Web Components 버튼 오버view
The Web Components Button Component lets you enable clickable elements that trigger actions in your Web Components 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 Web Components Button OnClick event, toggle the Web Components button, disable the Web Components button, and more.
Web Components Button Example
Usage
먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.
npm install igniteui-webcomponents
그런 다음 다음과 같이 필요한 CSS인 IgcButtonComponent
가져오고 해당 모듈을 등록해야 합니다.
import { defineComponents, IgcButtonComponent } from "igniteui-webcomponents";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
defineComponents(IgcButtonComponent);
Ignite UI for Web Components에 대한 전체 소개를 보려면 시작하기 항목을 읽어보세요.
사용을 IgcButtonComponent
시작하는 가장 간단한 방법은 다음과 같습니다.
<igc-button>Click me</igc-button>
Prefix / Suffix
와 함께 prefix
그리고 suffix
슬롯 IgcButtonComponent
구성 요소를 사용하면 버튼의 기본 콘텐츠 앞뒤에 다양한 콘텐츠를 추가할 수 있습니다.
<igc-button type="button" variant="contained">
<span slot="prefix">+</span>Click me<span slot="suffix">-</span>
</igc-button>
Type
href
속성이 설정되면 버튼 구성 요소의 내부 구조가 <button>
에서 <a>
유형 요소로 변경됩니다. 이 경우 버튼은 일반 링크로 간주될 수 있습니다. href
속성을 설정하면 rel
, target
및 download
속성도 설정할 수 있습니다. 버튼 구성 요소가 내부적으로 실제 <button>
요소를 사용하는 경우 속성을 다음 값 중 하나로 설정하여 Type
지정할 수 있습니다.
Submit
- 양식 데이터를 제출하려는 경우reset
- 양식 데이터를 초기 값으로 재설정하려는 경우button
- 웹페이지 어디든 맞춤 기능이 있는 버튼을 추가하고 싶을 때
Button Variants
Contained Button
속성을 사용하여 variant
구성 요소 템플릿에 간단한 포함 단추를 추가합니다. variant를 설정하지 않으면 기본적으로 포함으로 설정됩니다.
<igc-button variant="contained">Contained</igc-button>
Outlined Button
버튼을 생성 outlined
하기 위해 해야 할 일은 속성의 값을 변경하는 것입니다. variant
<igc-button variant="outlined">Outlined</igc-button>
Flat Button
유사하게 flat
변형으로 전환할 수 있습니다.
<igc-button variant="flat">Flat</igc-button>
Floating Action Button
속성을 다음과 같이 설정 variant
하여 부동 작업 버튼을 만들 수 있습니다. fab
<igc-button variant="fab">Fab</igc-button>
Button Sizing
사용자는 IgcButtonComponent
를 사용하여--ig-size
CSS 변수. 다음 예에서는 모든 크기 값을 표시하는 몇 가지 라디오 버튼을 추가합니다. 이렇게 하면 하나가 선택될 때마다 버튼의 크기가 변경됩니다.
import { defineComponents, IgcButtonComponent, IgcRadioComponent, IgcRadioGroupComponent } from 'igniteui-webcomponents';
defineComponents(IgcButtonComponent, IgcRadioComponent, IgcRadioGroupComponent);
<igc-radio-group id="radio-group" alignment="horizontal">
<igc-radio name="size" value="small" label-position="after">Small</igc-radio>
<igc-radio name="size" value="medium" label-position="after" checked>Medium</igc-radio>
<igc-radio name="size" value="large" label-position="after">Large</igc-radio>
</igc-radio-group>
this.radioGroup = document.getElementById('radio-group') as IgcRadioGroupComponent;
this.outlinedButton = document.getElementById('outlined-btn') as IgcButtonComponent;
this.flatButton = document.getElementById('flat-btn') as IgcButtonComponent;
this.containedButton = document.getElementById('contained-btn') as IgcButtonComponent;
this.fabButton = document.getElementById('fab-btn') as IgcButtonComponent;
this.radioGroup.addEventListener('click', (radio: any) => {
this.outlinedButton.style.setProperty('--ig-size', `var(--ig-size-${radio.target.value})`);
this.flatButton.style.setProperty('--ig-size', `var(--ig-size-${radio.target.value})`);
this.containedButton.style.setProperty('--ig-size', `var(--ig-size-${radio.target.value})`);
this.fabButton.style.setProperty('--ig-size', `var(--ig-size-${radio.target.value})`);
});
위 코드를 구현한 결과는 다음과 같아야 합니다.
Download
속성을 설정하면 download
사용자에게 연결된 URL로 이동하는 대신 저장하라는 메시지가 표시됩니다.
<igc-button
href=""
variant="contained"
download="url_to_content"
target="_blank">
Download
</igc-button>
Styling
스타일 IgcButtonComponent
링에 사용할 수 있는 세 가지 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;
}