# Segmented Control URL: /lynx/components/segmented-control Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/segmented-control.mdx 여러 옵션 중 하나를 선택하여 관련 콘텐츠를 즉시 필터링하거나 전환할 때 사용하는 컴포넌트입니다. Lynx Engine 최소 버전: 3.6 사용 가능 버전: @seed-design/lynx-react@0.6.0, @seed-design/lynx-css@0.10.0 ## Preview ```tsx import "./styles"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { return ( Hot New ); } ``` ## Installation - npm: npx @seed-design/cli add ui:segmented-control - pnpm: pnpm dlx @seed-design/cli add ui:segmented-control - yarn: yarn dlx @seed-design/cli add ui:segmented-control - bun: bun x @seed-design/cli add ui:segmented-control ## Props ### `SegmentedControl` `value`와 `defaultValue` 중 적어도 하나를 제공해야 선택된 항목과 Indicator를 표시할 수 있습니다. ### `SegmentedControlItem` ## Usage ```tsx import { SegmentedControl, SegmentedControlItem, } from "@/components/ui/segmented-control"; export function App() { return ( 인기순 최신순 ); } ``` ## Examples ### Disabled `SegmentedControl`의 `disabled`는 전체 항목을 비활성화합니다. 각 `SegmentedControlItem`도 따로 비활성화할 수 있습니다. ```tsx import "./styles"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { return ( Hot New Marinara Pesto Carbonara ); } ``` ### Notification ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { ActionButton } from "@seed-design/lynx-react"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { const [sortBy, setSortBy] = useState("monthly"); const [hasSeenAnnual, setHasSeenAnnual] = useState(false); function handleValueChange(value: string) { "background only"; setSortBy(value); if (value === "annual") setHasSeenAnnual(true); } function handleResetNotification() { "background only"; setHasSeenAnnual(false); } return ( Monthly Annual Enterprise Custom Reset Notification ); } ``` ### Long Label ```tsx import "./styles"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { return ( 가격 높은 순 할인율 높은 순 인기 많은 순 ); } ``` ### Fixed Width `SegmentedControl`의 `style`이나 `className`으로 너비를 지정할 수 있습니다. ```tsx import "./styles"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { return ( New Hot One Way Trip Round Trip Multi-City Journey ); } ``` ### Listening to Value Changes `onValueChange`로 선택 값 변경을 감지할 수 있습니다. Controlled 모드에서는 `value`와 함께 사용합니다. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"; export default function Example() { const [count, setCount] = useState(0); const [lastValue, setLastValue] = useState(null); function handleValueChange(nextValue: string) { "background only"; setCount((previous) => previous + 1); setLastValue(nextValue); } return ( Hot New onValueChange called: {count} times, last value: {lastValue ?? "-"} ); } ``` ## 웹 버전과의 차이 - 선택 이벤트는 input change 대신 `bindtap`과 `onValueChange`로 받습니다. - 접근성은 ARIA 대신 Lynx의 `accessibility-*` 속성을 사용합니다. ## Lynx 미지원 기능 - HTML form 제출을 위한 `ItemHiddenInput`, `name`, `form`, `inputProps` - 키보드 focus와 focus-visible 상호작용 - `SegmentedControlItem`의 `invalid` 상태. 오류 문구는 컴포넌트 가까이에 표시하고 `accessibility-label`에도 포함하세요.