# Switch URL: /lynx/components/switch Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/switch.mdx 특정 설정 및 상태를 즉시 켜거나 끌 수 있도록 하는 컴포넌트입니다. Lynx Engine 최소 버전: 3.6 사용 가능 버전: @seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0 ## Preview ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { Switch } from "@/components/ui/switch"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:switch - pnpm: pnpm dlx @seed-design/cli@latest add ui:switch - yarn: yarn dlx @seed-design/cli@latest add ui:switch - bun: bun x @seed-design/cli@latest add ui:switch ## Props ### `Switch` ### `Switchmark` ## Examples ### Sizes ```tsx import "./styles"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Switch, type SwitchProps } from "@/components/ui/switch"; function SwitchItem({ size, label }: { size: SwitchProps["size"]; label: string }) { return ; } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Tones #### Brand ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { Switch } from "@/components/ui/switch"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` #### Neutral ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { Switch } from "@/components/ui/switch"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Long Label ```tsx import "./styles"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Switch, type SwitchProps } from "@/components/ui/switch"; const label = "Consequat ut veniam aliqua deserunt occaecat enim occaecat veniam et et cillum nulla officia incididunt incididunt. Sint laboris labore occaecat fugiat culpa voluptate ullamco in elit dolore exercitation nulla."; function SwitchItem({ size }: { size: SwitchProps["size"] }) { return ; } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Disabled ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Switch, type SwitchProps } from "@/components/ui/switch"; function SwitchItem({ disabled, label, tone = "brand", defaultChecked = false, }: { disabled: boolean; label: string; tone?: SwitchProps["tone"]; defaultChecked?: boolean; }) { return ; } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [disabled, setDisabled] = useState(true); return ( ); } ``` ### Listening to Value Changes `onCheckedChange`를 사용하여 스위치의 선택 상태 변경을 감지할 수 있습니다. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Switch } from "@/components/ui/switch"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [count, setCount] = useState(0); const [lastValue, setLastValue] = useState(null); return ( { setCount((previous) => previous + 1); setLastValue(checked); }} /> onCheckedChange called: {count} times, last value:{" "} {lastValue === null ? "-" : JSON.stringify(lastValue)} ); } ``` ### Use Cases #### Using `Switchmark` `Switchmark`는 레이블을 제외한 스위치 컴포넌트로, 커스텀 레이아웃을 위해 사용할 수 있습니다. ```tsx import "./styles"; import { HStack, Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Switchmark } from "@/components/ui/switch"; interface CustomSwitchProps { label: string; textStyle: "t7Regular" | "t7Medium" | "t7Bold"; defaultChecked?: boolean; } function CustomSwitch({ label, textStyle, defaultChecked = false }: CustomSwitchProps) { return ( {label} ); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ## 웹 버전과의 차이 Lynx `Switch`는 React `Switch`와 다음과 같은 차이가 있습니다. - **이벤트 핸들링**: `onChange` 대신 `onCheckedChange`만 노출합니다. tap 핸들러는 Switch 내부에서 소유합니다. - **렌더링 요소**: HTML ` ## Scale Feedback Lynx `Switch`는 현재 눌렀을 때 `Switchmark`가 줄어드는 피드백을 제공하지 않습니다. CSS 지원 문제가 아니라 현재 Rootage 명세와 Lynx Recipe에 pressed scale 상태가 없기 때문입니다. 이 피드백이 필요하면 앱에서 `Switchmark`를 감싸는 요소의 눌림 상태와 scale transform을 직접 연결하세요. ## Lynx 미지원 기능 현재 Lynx 플랫폼 제약으로 다음 기능이 지원되지 않습니다. ### 런타임 모델 차이로 제외 | 기능 | 웹 대응 | 설명 | | ----------------------------------------- | ------------------------- | ---------------------------- | | `SwitchHiddenInput` | `` | Lynx에 HTML form 제출 모델 없음 | | `name` / `value` / `required` / `invalid` | form field props | Lynx에 native form 제출 모델 없음 | | `focus` / `focusVisible` | 키보드 포커스 | Lynx에 키보드 포커스 개념 없음 | | `onChange` (raw DOM event) | `React.ChangeEvent` | 의미 없음. `onCheckedChange`로 대체 |