Khi nào dùng
- Để bật hoặc tắt một thiết lập có hiệu lực ngay, như tạm dừng một tác vụ đồng bộ.
Khi nào không dùng
- Cho lựa chọn chỉ được lưu sau khi bấm nút Lưu của biểu mẫu. Dùng checkbox.
- Cho nhiều hơn hai lựa chọn. Dùng radio hoặc segmented control.
Màu
Bật là màu trung tính, không phải màu thành công. Tắt là đang dùng được, không phải vô hiệu.
- Bật dùng màu của nút chính: rãnh
background.neutral.bold, núm và nhãn màu đảo (inverse). Không dùng xanh lá thành công hay vàng thương hiệu, vì công tắc cho biết một thiết lập, không phải kết quả của một thao tác. - Tắt có rãnh
background.neutral, núm màu icon và viềnborder.bold, để người dùng thấy đây là control dùng được. Không dùng màu vô hiệu cho nó. - Mỗi trạng thái có màu núm riêng, đi cặp với rãnh của nó, và màu nhãn cho chữ Bật, Tắt khi sản phẩm hiện chữ trong một rãnh rộng hơn. Không đặt một núm trắng cho cả hai rãnh: trên rãnh tắt màu sáng, núm trắng biến mất.
Trạng thái
Mọi tên màu bên dưới đều bắt đầu bằng color..
| Trạng thái | Tắt | Bật | Dấu hiệu khác |
|---|---|---|---|
| Thường | Rãnh background.neutral; núm icon; nhãn text; viền border.bold |
Rãnh và viền background.neutral.bold; núm icon.inverse; nhãn text.inverse |
Vị trí núm và aria-checked |
| Hover | Rãnh .hover; núm, nhãn, viền giữ nguyên |
Rãnh và viền .hover; núm, nhãn giữ nguyên |
Trạng thái bật/tắt không đổi |
| Nhấn | Rãnh .pressed; núm, nhãn giữ nguyên; viền graphite 10 |
Rãnh và viền .pressed; núm, nhãn giữ nguyên |
Viền khi tắt vẫn đạt 3:1 so với rãnh lúc nhấn |
| Focus | Cùng màu với trạng thái thường | Cùng màu với trạng thái thường | Vòng focus switch.focus-ring, dày 2 px, cách 2 px |
| Đang xử lý | Cùng màu với Tắt thường | Cùng màu với Bật thường | Spinner màu switch.{off,on}.loading-icon; không đổi được công tắc cho tới khi lưu xong |
| Vô hiệu | Màu vô hiệu cho rãnh, núm, nhãn và viền | Cùng màu vô hiệu; núm vẫn ở vị trí Bật | Không dùng độ trong suốt |
Bật hoạt động giống nút chính: rãnh nằm ở graphite 12, bậc cuối của thang, nên khi hover lùi một bậc (graphite 11), khi nhấn lùi hai bậc (graphite 10). Token đã làm sẵn việc này, ở cả giao diện sáng và tối.
Kích thước
Rãnh 36 × 20 px (switch.size.track.width, switch.size.track.height), núm 16 px (switch.size.thumb), cả hai dùng radius.full. Vùng nhận click tối thiểu 24 × 24 px, và 44 × 44 px trên màn hình cảm ứng.
Token
| Token | Giá trị | Mô tả |
|---|---|---|
--bh-switch-size-track-height | 1.25rem | 20 px. Chiều cao rãnh của switch. |
--bh-switch-size-track-width | 2.25rem | 36 px. Chiều rộng rãnh của switch. |
--bh-switch-size-thumb | 1rem | 16 px. Đường kính núm của switch. |
--bh-switch-focus-ring | {color.border.focus}#005195Tối: #6bb3fa | Keyboard-visible ring for either checked state; keep the existing focused border width and focus offset. Does not replace the ON/OFF track, thumb or label. |
--bh-switch-off-track | {color.background.neutral}#f1f1f0Tối: #282827 | OFF track, normal. Neutral boolean-state fill, never business-success green. |
--bh-switch-off-track-hover | {color.background.neutral.hover}#e5e5e4Tối: #31302f | OFF track, hover. Neutral boolean-state fill, never business-success green. |
--bh-switch-off-track-pressed | {color.background.neutral.pressed}#d9d9d8Tối: #393937 | OFF track, pressed. Neutral boolean-state fill, never business-success green. |
--bh-switch-off-track-focus | {switch.off.track}#f1f1f0Tối: #282827 | OFF track, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-off-track-loading | {switch.off.track}#f1f1f0Tối: #282827 | OFF track, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-off-track-disabled | {color.background.disabled}#f1f1f0Tối: #282827 | OFF track, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-off-thumb | {color.icon}#42413fTối: #cdccc9 | OFF thumb, normal. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-thumb-hover | {color.icon}#42413fTối: #cdccc9 | OFF thumb, hover. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-thumb-pressed | {color.icon}#42413fTối: #cdccc9 | OFF thumb, pressed. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-thumb-focus | {switch.off.thumb}#42413fTối: #cdccc9 | OFF thumb, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-off-thumb-loading | {switch.off.thumb}#42413fTối: #cdccc9 | OFF thumb, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-off-thumb-disabled | {color.icon.disabled}#949390Tối: #6b6a67 | OFF thumb, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-off-label | {color.text}#2b2a28Tối: #eeeeed | OFF label, normal. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-label-hover | {color.text}#2b2a28Tối: #eeeeed | OFF label, hover. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-label-pressed | {color.text}#2b2a28Tối: #eeeeed | OFF label, pressed. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-off-label-focus | {switch.off.label}#2b2a28Tối: #eeeeed | OFF label, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-off-label-loading | {switch.off.label}#2b2a28Tối: #eeeeed | OFF label, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-off-label-disabled | {color.text.disabled}#949390Tối: #6b6a67 | OFF label, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-off-border | {color.border.bold}#7b7976Tối: #878682 | OFF border, normal. Meaningful boundary without changing native geometry. |
--bh-switch-off-border-hover | {color.border.bold}#7b7976Tối: #878682 | OFF border, hover. Meaningful boundary without changing native geometry. |
--bh-switch-off-border-pressed | {color.graphite.10}#5f5e5bTối: #a8a6a3 | OFF border, pressed. Graphite 10 keeps at least 3:1 against the pressed neutral track in both themes without changing native geometry. |
--bh-switch-off-border-focus | {switch.off.border}#7b7976Tối: #878682 | OFF border, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-off-border-loading | {switch.off.border}#7b7976Tối: #878682 | OFF border, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-off-border-disabled | {color.border.disabled}#bdbcbbTối: #454443 | OFF border, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-off-loading-icon | {color.icon.inverse}#fdfdfcTối: #181717 | Spinner foreground inside the OFF thumb, paired with switch.off.thumb.loading. Keep the native spinning indicator and blocked callback behavior. |
--bh-switch-on-track | {color.background.neutral.bold}#2b2a28Tối: #eeeeed | ON track, normal. Neutral boolean-state fill, never business-success green. |
--bh-switch-on-track-hover | {color.background.neutral.bold.hover}#42413fTối: #cdccc9 | ON track, hover. Neutral boolean-state fill, never business-success green. |
--bh-switch-on-track-pressed | {color.background.neutral.bold.pressed}#5f5e5bTối: #a8a6a3 | ON track, pressed. Neutral boolean-state fill, never business-success green. |
--bh-switch-on-track-focus | {switch.on.track}#2b2a28Tối: #eeeeed | ON track, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-on-track-loading | {switch.on.track}#2b2a28Tối: #eeeeed | ON track, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-on-track-disabled | {color.background.disabled}#f1f1f0Tối: #282827 | ON track, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-on-thumb | {color.icon.inverse}#fdfdfcTối: #181717 | ON thumb, normal. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-thumb-hover | {color.icon.inverse}#fdfdfcTối: #181717 | ON thumb, hover. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-thumb-pressed | {color.icon.inverse}#fdfdfcTối: #181717 | ON thumb, pressed. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-thumb-focus | {switch.on.thumb}#fdfdfcTối: #181717 | ON thumb, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-on-thumb-loading | {switch.on.thumb}#fdfdfcTối: #181717 | ON thumb, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-on-thumb-disabled | {color.icon.disabled}#949390Tối: #6b6a67 | ON thumb, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-on-label | {color.text.inverse}#fdfdfcTối: #181717 | ON label, normal. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-label-hover | {color.text.inverse}#fdfdfcTối: #181717 | ON label, hover. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-label-pressed | {color.text.inverse}#fdfdfcTối: #181717 | ON label, pressed. Paired foreground against this checked-state track; never reuse the opposite checked-state foreground. |
--bh-switch-on-label-focus | {switch.on.label}#fdfdfcTối: #181717 | ON label, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-on-label-loading | {switch.on.label}#fdfdfcTối: #181717 | ON label, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-on-label-disabled | {color.text.disabled}#949390Tối: #6b6a67 | ON label, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-on-border | {color.background.neutral.bold}#2b2a28Tối: #eeeeed | ON border, normal. Meaningful boundary without changing native geometry. |
--bh-switch-on-border-hover | {color.background.neutral.bold.hover}#42413fTối: #cdccc9 | ON border, hover. Meaningful boundary without changing native geometry. |
--bh-switch-on-border-pressed | {color.background.neutral.bold.pressed}#5f5e5bTối: #a8a6a3 | ON border, pressed. Meaningful boundary without changing native geometry. |
--bh-switch-on-border-focus | {switch.on.border}#2b2a28Tối: #eeeeed | ON border, focus. Normal pair under the independent keyboard focus ring; pointer hover/pressed feedback may coexist with the ring. |
--bh-switch-on-border-loading | {switch.on.border}#2b2a28Tối: #eeeeed | ON border, loading. Preserve the normal checked-state pair while the native spinner signals pending work; native interaction stays blocked. |
--bh-switch-on-border-disabled | {color.border.disabled}#bdbcbbTối: #454443 | ON border, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming. |
--bh-switch-on-loading-icon | {color.icon}#42413fTối: #cdccc9 | Spinner foreground inside the ON thumb, paired with switch.on.thumb.loading. Keep the native spinning indicator and blocked callback behavior. |