スイッチ
スイッチは、設定のオン・オフや2つの選択肢を切り替えるためのコントロールです。
import { Switch } from "@/components/ui/switch";使用例
オン・オフの切り替えと2つの選択肢の切り替えのどちらにも、Ark UIのSwitch.Rootと各slotを組み合わせます。2つの選択肢を切り替える場合はvariant="mode"を指定します。
Slot Recipeのvariant軸はvariantで、値はonOffまたはmodeです。既定値はonOffです。
オン・オフを切り替えるとき
読み込み中
import { Switch } from "@/components/ui/switch";
export default function App() {
return (
<Switch.Root>
<Switch.Control>
<Switch.Thumb>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path
d="m10.4 16.3-4.1-4.1 1.2-1.3 2.9 2.9 6-6.1 1.3 1.2z"
fill="currentcolor"
/>
</svg>
</Switch.Thumb>
</Switch.Control>
<Switch.HiddenInput role="switch" />
<Switch.Label>やさしい日本語に変換する</Switch.Label>
</Switch.Root>
);
}
2つの選択肢のどちらかに切り替えるとき
読み込み中
import { css } from "styled-system/css";
import { Switch } from "@/components/ui/switch";
export default function App() {
return (
<Switch.Root variant="mode">
<span aria-hidden="true">リスト表示</span>
<Switch.Control>
<Switch.Thumb />
</Switch.Control>
<span aria-hidden="true">カレンダー表示</span>
<Switch.HiddenInput role="switch" />
<Switch.Label className={css({ srOnly: true })}>
リスト表示 / カレンダー表示
</Switch.Label>
</Switch.Root>
);
}