Blazor 버튼 개요

    The Blazor Button Component lets you enable clickable elements that trigger actions in your Blazor app. You get full control over how you set button variants, configure styles for the wrapped element, and define sizes. The Button Component also gives flexibility through the Blazor Button OnClick event, toggle the Blazor button, disable the Blazor button, and more.

    Blazor Button Example

    Usage

    IgbButton 사용하기 전에 다음과 같이 등록해야 합니다.

    // in Program.cs file
    
    builder.Services.AddIgniteUIBlazor(typeof(IgbButtonModule));
    

    IgbButton 구성 요소에 스타일을 적용하려면 추가 CSS 파일을 연결해야 합니다. 다음은 Blazor Web Assembly 프로젝트의 wwwroot/index.html 파일이나 Blazor Server 프로젝트의 Pages/_Host.cshtml 파일에 배치해야 합니다.

    <link href="_content/IgniteUI.Blazor/themes/light/bootstrap.css" rel="stylesheet" />
    
    <IgbButton />
    

    Prefix / Suffix

    와 함께 prefix 그리고 suffix 슬롯 IgbButton 구성 요소를 사용하면 버튼의 기본 콘텐츠 앞뒤에 다양한 콘텐츠를 추가할 수 있습니다.

    <IgbButton Variant="@ButtonVariant.Contained">
        <span slot="prefix">+</span>Click me<span slot="suffix">-</span>
    </IgbButton>
    

    Type

    Href 속성이 설정되면 버튼 구성 요소의 내부 구조가 <button>에서 <a> 유형 요소로 변경됩니다. 이 경우 버튼은 일반 링크로 간주될 수 있습니다. Href 속성을 설정하면 Rel, TargetDownload 속성도 설정할 수 있습니다. 버튼 구성 요소가 내부적으로 실제 <button> 요소를 사용하는 경우 속성을 다음 값 중 하나로 설정하여 DisplayType 지정할 수 있습니다.

    • Submit- 양식 데이터를 제출하려는 경우
    • reset- 양식 데이터를 초기 값으로 재설정하려는 경우
    • button- 웹페이지 어디든 맞춤 기능이 있는 버튼을 추가하고 싶을 때

    Button Variants

    Contained Button

    속성을 사용하여 Variant 구성 요소 템플릿에 간단한 포함 단추를 추가합니다. variant를 설정하지 않으면 기본적으로 포함으로 설정됩니다.

    <IgbButton Variant="@ButtonVariant.Contained" />
    

    Outlined Button

    버튼을 생성 outlined 하기 위해 해야 할 일은 속성의 값을 변경하는 것입니다. Variant

    <IgbButton Variant="@ButtonVariant.Outlined" />
    

    Flat Button

    유사하게 flat 변형으로 전환할 수 있습니다.

    <IgbButton Variant="@ButtonVariant.Flat" />
    

    Floating Action Button

    속성을 다음과 같이 설정 Variant 하여 부동 작업 버튼을 만들 수 있습니다. fab

    <IgbButton Variant="@ButtonVariant.Fab" />
    

    Button Sizing

    사용자는 IgbButton를 사용하여--ig-size CSS 변수. 다음 예에서는 모든 크기 값을 표시하는 몇 가지 라디오 버튼을 추가합니다. 이렇게 하면 하나가 선택될 때마다 버튼의 크기가 변경됩니다.

    <IgbRadioGroup id="radioGroup" Alignment="ContentOrientation.Horizontal" >
        <IgbRadio Value="small" LabelPosition="RadioLabelPosition.After" @onclick="OnSmallClick">Small</IgbRadio>
        <IgbRadio Value="medium" LabelPosition="RadioLabelPosition.After" @onclick="OnMediumClick">Medium</IgbRadio>
        <IgbRadio Value="large" LabelPosition="RadioLabelPosition.After" Checked="true" @onclick="OnLargeClick">Large</IgbRadio>
    </IgbRadioGroup>
    
    @code {
        private SizableComponentSize SizableComponentSize = SizableComponentSize.Large;
    
        protected override void OnInitialized()
        {
        }
    
        public void OnSmallClick(EventArgs e)
        {
            SizableComponentSize = SizableComponentSize.Small;
        }
    
        public void OnMediumClick(EventArgs e)
        {
            SizableComponentSize = SizableComponentSize.Medium;
        }
    
        public void OnLargeClick(EventArgs e)
        {
            SizableComponentSize = SizableComponentSize.Large;
        }
    }
    

    위 코드를 구현한 결과는 다음과 같아야 합니다.

    Download

    속성을 설정하면 Download 사용자에게 연결된 URL로 이동하는 대신 저장하라는 메시지가 표시됩니다.

    <IgbButton Variant="@ButtonVariant.Contained" Download="Url" Href="https://ko.infragistics.com/" Target="@ButtonBaseTarget._blank">
        Download
    </IgbButton>
    

    Styling

    스타일 IgbButton 링에 사용할 수 있는 세 가지 CSS 부분을 노출합니다.

    이름 설명
    base igc-button 구성 요소의 기본 button 요소입니다.
    prefix igc-button 구성 요소의 접두사 컨테이너입니다.
    suffix igc-button 구성 요소의 접미사 컨테이너입니다.

    CSS 부분을 사용하면 base 래핑된 요소(<button> or <a>)의 스타일을 지정할 수 있습니다.

    igc-button::part(base) {
      background-color: var(--ig-primary-500);
      color: var(--ig-primary-500-contrast);
      padding: 18px;
    }
    

    API References

    Additional Resources