ToggleButton
켜고 끌 수 있는 토글 버튼 컴포넌트예요. 선택 상태를 시각적으로 나타내는 데 써요.
출처: 문서
본문
ToggleButton 컴포넌트는 켜거나 끌 수 있는 버튼을 만드는 데 사용해요.
사용법 (Usage)
import { ToggleButton } from '@primereact/ui/togglebutton';
<ToggleButton.Root>
<ToggleButton.Indicator>Toggle</ToggleButton.Indicator>
</ToggleButton.Root>
예제 (Examples)
기본 (Basic)
활성/비활성 상태를 전환하는 버튼이에요.
렌더 props (Render Props)
이것을 render prop 패턴이라고 불러요. 내부 상태에 따라 컴포넌트가 무엇을 표시할지 함수로 커스터마이즈할 수 있게 해 줘요.
제어 (Controlled)
pressed와 onPressedChange 속성으로 ToggleButton의 상태를 제어해요.
크기 (Size)
size 속성을 사용하면 기본 크기 외에 small과 large 크기가 제공돼요.
Fluid
fluid가 활성화되면 ToggleButton이 부모 컨테이너의 전체 폭을 차지해요.
유효하지 않음 (Invalid)
invalid prop으로 유효하지 않은 상태를 표시해서 검증 실패를 나타낼 수 있어요. 폼 검증 라이브러리와 통합할 때 유용한 스타일이에요.
비활성 (Disabled)
disabled가 있으면 요소를 수정하거나 포커스할 수 없어요.
관련 자료 (Related)
하위 컴포넌트 (Sub-Components)
ToggleButtonRoot, ToggleButtonIndicator, ToggleButtonGroup 컴포넌트 문서는 Primitive API에서 확인할 수 있어요.
훅 (Hooks)
useToggleButton와 useToggleButtonGroup 훅 문서는 Headless API에서 확인할 수 있어요.
접근성 (Accessibility)
WAI-ARIA 준수 상세와 키보드 지원은 ToggleButton Primitive에서 확인할 수 있어요.
테마 (Theming)
CSS 클래스 (CSS Classes)
styled 모드에서 사용하는 클래스 이름 목록이에요.
| ClassName | Description |
|---|---|
| p-togglebutton | Class name of the root element |
| p-togglebutton-content | Class name of the content element |
| ClassName | Description |
|---|---|
| p-togglebutton-group | Class name of the root element |
디자인 토큰 (Design Tokens)
디자인 토큰 목록이에요.
| Token | CSS Variable | Description |
|---|---|---|
| togglebutton.padding | --p-togglebutton-padding | Padding of root |
| togglebutton.border.radius | --p-togglebutton-border-radius | Border radius of root |
| togglebutton.gap | --p-togglebutton-gap | Gap of root |
| togglebutton.font.size | --p-togglebutton-font-size | Font size of root |
| togglebutton.font.weight | --p-togglebutton-font-weight | Font weight of root |
| togglebutton.disabled.background | --p-togglebutton-disabled-background | Disabled background of root |
| togglebutton.disabled.border.color | --p-togglebutton-disabled-border-color | Disabled border color of root |
| togglebutton.disabled.color | --p-togglebutton-disabled-color | Disabled color of root |
| togglebutton.invalid.border.color | --p-togglebutton-invalid-border-color | Invalid border color of root |
| togglebutton.focus.ring.width | --p-togglebutton-focus-ring-width | Focus ring width of root |
| togglebutton.focus.ring.style | --p-togglebutton-focus-ring-style | Focus ring style of root |
| togglebutton.focus.ring.color | --p-togglebutton-focus-ring-color | Focus ring color of root |
| togglebutton.focus.ring.offset | --p-togglebutton-focus-ring-offset | Focus ring offset of root |
| togglebutton.focus.ring.shadow | --p-togglebutton-focus-ring-shadow | Focus ring shadow of root |
| togglebutton.transition.duration | --p-togglebutton-transition-duration | Transition duration of root |
| togglebutton.sm.font.size | --p-togglebutton-sm-font-size | Sm font size of root |
| togglebutton.sm.padding | --p-togglebutton-sm-padding | Sm padding of root |
| togglebutton.lg.font.size | --p-togglebutton-lg-font-size | Lg font size of root |
| togglebutton.lg.padding | --p-togglebutton-lg-padding | Lg padding of root |
| togglebutton.background | --p-togglebutton-background | Background of root |
| togglebutton.checked.background | --p-togglebutton-checked-background | Checked background of root |
| togglebutton.hover.background | --p-togglebutton-hover-background | Hover background of root |
| togglebutton.border.color | --p-togglebutton-border-color | Border color of root |
| togglebutton.color | --p-togglebutton-color | Color of root |
| togglebutton.hover.color | --p-togglebutton-hover-color | Hover color of root |
| togglebutton.checked.color | --p-togglebutton-checked-color | Checked color of root |
| togglebutton.checked.border.color | --p-togglebutton-checked-border-color | Checked border color of root |
| togglebutton.icon.disabled.color | --p-togglebutton-icon-disabled-color | Disabled color of icon |
| togglebutton.icon.color | --p-togglebutton-icon-color | Color of icon |
| togglebutton.icon.hover.color | --p-togglebutton-icon-hover-color | Hover color of icon |
| togglebutton.icon.checked.color | --p-togglebutton-icon-checked-color | Checked color of icon |
| togglebutton.content.padding | --p-togglebutton-content-padding | Padding of content |
| togglebutton.content.border.radius | --p-togglebutton-content-border-radius | Border radius of content |
| togglebutton.content.checked.shadow | --p-togglebutton-content-checked-shadow | Checked shadow of content |
| togglebutton.content.sm.padding | --p-togglebutton-content-sm-padding | Sm padding of content |
| togglebutton.content.lg.padding | --p-togglebutton-content-lg-padding | Lg padding of content |
| togglebutton.content.checked.background | --p-togglebutton-content-checked-background | Checked background of content |