SegmentedControl
SegmentedControl은 밀접하게 관련된 선형 옵션 집합에서 하나를 골라 즉시 적용하는 데 쓰는 컴포넌트예요. 세그먼트 버튼·아이콘 버튼·액션·구분선을 조합해 다양하게 구성할 수 있습니다.
출처: 문서
본문
SegmentedControl은 밀접하게 관련된 선형 옵션 집합에서 하나를 선택하고 그 선택을 즉시 적용하는 데 사용합니다. React와 Rails 모두 지원되며 Figma 스펙도 제공됩니다.
React 예제
기본
<SegmentedControl aria-label="File view">
<SegmentedControl.Button defaultSelected>Preview</SegmentedControl.Button>
<SegmentedControl.Button>Raw</SegmentedControl.Button>
<SegmentedControl.Button>Blame</SegmentedControl.Button>
</SegmentedControl>
제어(Controlled)
import React from 'react'
import {SegmentedControl} from '@primer/react'
export default function Default() {
const [selectedIndex, setSelectedIndex] = React.useState(0)
const handleChange = (i: number) => {
setSelectedIndex(i)
}
return (
<SegmentedControl aria-label="File view" onChange={handleChange}>
<SegmentedControl.Button selected={selectedIndex === 0}>Preview</SegmentedControl.Button>
<SegmentedControl.Button selected={selectedIndex === 1}>Raw</SegmentedControl.Button>
<SegmentedControl.Button selected={selectedIndex === 2}>Blame</SegmentedControl.Button>
</SegmentedControl>
)
}
앞 아이콘과 함께
세그먼트의 아이콘에 대한 가이드라인을 참고하세요.
<SegmentedControl aria-label="File view">
<SegmentedControl.Button defaultSelected aria-label="Preview" leadingIcon={EyeIcon}>
Preview
</SegmentedControl.Button>
<SegmentedControl.Button aria-label="Raw" leadingIcon={FileCodeIcon}>
Raw
</SegmentedControl.Button>
<SegmentedControl.Button aria-label="Blame" leadingIcon={PeopleIcon}>
Blame
</SegmentedControl.Button>
</SegmentedControl>
아이콘만
아이콘 전용 세그먼트 가이드라인을 참고하세요.
<SegmentedControl aria-label="File view">
<SegmentedControl.IconButton defaultSelected aria-label="Preview" icon={EyeIcon} />
<SegmentedControl.IconButton aria-label="Raw" icon={FileCodeIcon} />
<SegmentedControl.IconButton aria-label="Blame" icon={PeopleIcon} />
</SegmentedControl>
더 많은 예제
앞의 예제들은 SegmentedControl 컴포넌트의 전체 기능(반응형 동작 등) 중 일부를 정제한 것입니다. 더 많은 예제는 SegmentedControl Storybook 스토리를 참고하세요.
Props
SegmentedControl
| 이름 | 기본값 | 타입 | 설명 |
|---|---|---|---|
aria-label |
string |
||
aria-labelledby |
string |
||
aria-describedby |
string |
||
fullWidth |
boolean | { narrow?: boolean regular?: boolean wide?: boolean } |
컨트롤이 부모의 너비를 채우는지 여부. | |
onChange |
(selectedIndex?: number) => void |
세그먼트가 선택될 때 호출되는 핸들러. | |
variant |
'default' |
'default' | 'subtle' | { narrow?: 'hideLabels' | 'dropdown' | 'default' | 'subtle' regular?: 'hideLabels' | 'dropdown' | 'default' | 'subtle' wide?: 'hideLabels' | 'dropdown' | 'default' | 'subtle' } |
좁은 공간에서 컨트롤의 시각적 처리 또는 반응형 동작을 구성합니다. |
size |
'small' | 'medium' |
버튼의 크기. | |
ref |
React.RefObject<HTMLDivElement> |
SegmentedControl.Button
| 이름 | 기본값 | 타입 | 설명 |
|---|---|---|---|
leadingVisual |
Component |
항목 라벨 앞에 오는 앞 비주얼. | |
leadingIcon |
Deprecated | Component |
Deprecated: 대신 leadingVisual을 사용하세요. 항목 라벨 앞에 오는 앞 아이콘. |
selected |
boolean |
세그먼트가 선택되었는지 여부. 제어 SegmentedControl에 사용되며, SegmentedControl의 onChange 핸들러로 업데이트해야 합니다. | |
defaultSelected |
boolean |
세그먼트가 선택되었는지 여부. 비제어 SegmentedControl에서 초기 렌더링에 선택될 SegmentedControlButton 하나를 고르는 데 사용합니다. | |
count |
number | string |
카운터 라벨에 표시할 숫자. | |
ref |
React.RefObject<HTMLButtonElement> |
SegmentedControl.IconButton
| 이름 | 기본값 | 타입 | 설명 |
|---|---|---|---|
aria-label |
Required | string |
|
icon |
Required | Component |
세그먼트 컨트롤 항목을 나타내는 아이콘. |
selected |
boolean |
세그먼트가 선택되었는지 여부. 제어 SegmentedControl에 사용되며, SegmentedControl의 onChange 핸들러로 업데이트해야 합니다. | |
size |
'small' | 'medium' |
버튼의 크기. | |
defaultSelected |
boolean |
세그먼트가 선택되었는지 여부. 비제어 SegmentedControl에서 초기 렌더링에 선택될 SegmentedControlButton 하나를 고르는 데 사용합니다. | |
ref |
React.RefObject<HTMLButtonElement> |
||
tooltipDirection |
'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' |
||
description |
string |
description이 제공되면 Tooltip으로 버튼을 설명합니다. 그러면 aria-label은 버튼을 라벨하는 데 사용됩니다. |
SegmentedControl.Divider
| 이름 | 기본값 | 타입 | 설명 |
|---|---|---|---|
className |
string |
||
style |
React.CSSProperties |
SegmentedControl.Action
| 이름 | 기본값 | 타입 | 설명 |
|---|---|---|---|
label |
Required | string |
액션 아이콘 버튼의 접근 가능한 라벨. |
icon |
Required | Component |
액션 버튼이 렌더링하는 아이콘. |
onClick |
() => void |
액션 버튼이 클릭될 때 호출되는 핸들러. | |
disabled |
boolean |
액션이 비활성화되었는지 여부. | |
loading |
boolean |
액션이 로딩 상태인지 여부. |
관련 링크
- RadioGroup
- UnderlineNav
- UnderlinePanels
- Navigation
- Saving
더 알아보기 (Learn more)
- SegmentedControl 접근성 문서에서 키보드 동작을 확인하세요.
- SegmentedControl 가이드라인에서 사용 시점과 대안을 살펴보세요.
- RadioGroup과의 차이를 비교해 보세요.