Switch
Switchは、設定のオン/オフを即座に切り替えるためのトグルコントロールです。 変更が直ちに反映される場合に使用します。
5
Colors
3
Sizes
5
Positions
Radix
Base
Playground
Preview
D32×18pxThumb 16px
Size
Color
Position
Icon
State
Options
<Switch
label="Dark mode"
/>Sizes
smトラック24×14
サム12px
移動距離10px
フォント12px
Gap8px
defaultトラック32×18
サム16px
移動距離14px
フォント14px
Gap10px
lgトラック40×22
サム20px
移動距離18px
フォント16px
Gap12px
| Size | トラック | サム | 移動距離 | フォント | Gap | プレビュー |
|---|---|---|---|---|---|---|
sm | 24×14px | 12px | 10px | 12px | 8px | |
default | 32×18px | 16px | 14px | 14px | 10px | |
lg | 40×22px | 20px | 18px | 16px | 12px |
Features
With Label
labelプロップスを使って、スイッチにラベルを付与できます。
Label Position
labelPositionプロップでラベルの配置を変更できます。デフォルトはend(右側)です。
end (default)
start
top
bottom
sides
With Icon
checkedIcon / uncheckedIconプロップでサム内にアイコンを表示できます。smサイズでは自動的に非表示になります。
Check / X
Moon / Sun (lg)
States
Off
On
Disabled Off
Disabled On
API
Props
checkedundefinedboolean制御モードでのオン/オフStates
defaultCheckedundefinedboolean非制御モードでの初期States
onCheckedChangeundefined(checked: boolean) => voidStates変更時のコールバック
size"default""sm" | "default" | "lg"スイッチのサイズ
labelundefinedstringスイッチのラベルテキスト
labelPosition"end""start" | "end" | "top" | "bottom"ラベルの配置位置
startLabelundefinedstringスイッチ左側のラベル(sides配置)
endLabelundefinedstringスイッチ右側のラベル(sides配置)
color"default""default" | "primary" | "success" | "warning" | "error"チェック時のトラック色とアイコン色
checkedIconundefinedReactNodeチェック時にサム内に表示するアイコン
uncheckedIconundefinedReactNode未チェック時にサム内に表示するアイコン
disabledundefinedboolean無効States
requiredundefinedboolean必須フィールド
nameundefinedstringフォームのname属性
valueundefinedstringフォームのvalue属性。Radixデフォルト: "on"
| Name | Type | Default | Description |
|---|---|---|---|
checked | boolean | undefined | 制御モードでのオン/オフStates |
defaultChecked | boolean | undefined | 非制御モードでの初期States |
onCheckedChange | (checked: boolean) => void | undefined | States変更時のコールバック |
size | "sm" | "default" | "lg" | "default" | スイッチのサイズ |
label | string | undefined | スイッチのラベルテキスト |
labelPosition | "start" | "end" | "top" | "bottom" | "end" | ラベルの配置位置 |
startLabel | string | undefined | スイッチ左側のラベル(sides配置) |
endLabel | string | undefined | スイッチ右側のラベル(sides配置) |
color | "default" | "primary" | "success" | "warning" | "error" | "default" | チェック時のトラック色とアイコン色 |
checkedIcon | ReactNode | undefined | チェック時にサム内に表示するアイコン |
uncheckedIcon | ReactNode | undefined | 未チェック時にサム内に表示するアイコン |
disabled | boolean | undefined | 無効States |
required | boolean | undefined | 必須フィールド |
name | string | undefined | フォームのname属性 |
value | string | undefined | フォームのvalue属性。Radixデフォルト: "on" |