폼과 선택@neumorphism-ui/switch

Switch

native checkbox input에 role=switch를 적용해 폼과 브라우저 동작을 유지합니다. checked, defaultChecked, onCheckedChange를 모두 사용할 수 있습니다.

@neumorphism-ui/switch
Registry JSON

미리보기

설치

설치: switchnpx shadcn@latest add @neumorphism-ui/switch

CLI가 npm 의존성, base 토큰, utils와 컴포넌트 소스를 순서대로 확인하고 설치합니다.

Registry를 처음 사용한다면 namespace 설정 을 먼저 완료하세요.

사용법

사용법: 설치npx shadcn@latest add @neumorphism-ui/switch @neumorphism-ui/label

Import

Switch import 코드
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"

Example

Switch 사용 코드
<div className="flex items-center justify-between gap-4">
  <Label htmlFor="system-theme">시스템 테마 따르기</Label>
  <Switch id="system-theme" name="systemTheme" defaultChecked />
</div>

API 레퍼런스

컴포넌트속성타입기본값설명
Switchchecked / defaultCheckedboolean—controlled 또는 초기 uncontrolled 켜짐 상태입니다.
SwitchonCheckedChange(checked: boolean) => void—켜짐 상태가 바뀔 때 호출됩니다.
SwitchonChangeReact.ChangeEventHandler<HTMLInputElement>—native checkbox change event를 받습니다.
Switchdisabledbooleanfalse입력과 포인터 동작을 비활성화합니다.
Switchname / value / requirednative input props—폼 제출에 사용하는 native checkbox 속성입니다.

접근성

  • 01

    실제 checkbox에 role=switch를 적용하므로 Space 키와 checked 상태를 보조기술에 전달합니다.

  • 02

    Label의 htmlFor와 Switch의 id를 연결하거나 aria-label을 제공합니다.

  • 03

    즉시 적용되지 않고 별도 저장이 필요한 boolean 선택에는 Checkbox가 더 자연스러울 수 있습니다.