Trên trang này

Công tắc

Khi nào dùng công tắc, công tắc trông thế nào ở từng trạng thái, và các token nó dùng.

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ền border.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

TokenGiá trịMô tả
--bh-switch-size-track-height1.25rem20 px. Chiều cao rãnh của switch.
--bh-switch-size-track-width2.25rem36 px. Chiều rộng rãnh của switch.
--bh-switch-size-thumb1rem16 px. Đường kính núm của switch.
--bh-switch-focus-ring{color.border.focus}#005195Tối: #6bb3faKeyboard-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: #282827OFF track, normal. Neutral boolean-state fill, never business-success green.
--bh-switch-off-track-hover{color.background.neutral.hover}#e5e5e4Tối: #31302fOFF track, hover. Neutral boolean-state fill, never business-success green.
--bh-switch-off-track-pressed{color.background.neutral.pressed}#d9d9d8Tối: #393937OFF track, pressed. Neutral boolean-state fill, never business-success green.
--bh-switch-off-track-focus{switch.off.track}#f1f1f0Tối: #282827OFF 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: #282827OFF 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: #282827OFF track, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-off-thumb{color.icon}#42413fTối: #cdccc9OFF 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: #cdccc9OFF 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: #cdccc9OFF 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: #cdccc9OFF 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: #cdccc9OFF 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: #6b6a67OFF thumb, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-off-label{color.text}#2b2a28Tối: #eeeeedOFF 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: #eeeeedOFF 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: #eeeeedOFF 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: #eeeeedOFF 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: #eeeeedOFF 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: #6b6a67OFF label, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-off-border{color.border.bold}#7b7976Tối: #878682OFF border, normal. Meaningful boundary without changing native geometry.
--bh-switch-off-border-hover{color.border.bold}#7b7976Tối: #878682OFF border, hover. Meaningful boundary without changing native geometry.
--bh-switch-off-border-pressed{color.graphite.10}#5f5e5bTối: #a8a6a3OFF 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: #878682OFF 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: #878682OFF 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: #454443OFF border, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-off-loading-icon{color.icon.inverse}#fdfdfcTối: #181717Spinner 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: #eeeeedON track, normal. Neutral boolean-state fill, never business-success green.
--bh-switch-on-track-hover{color.background.neutral.bold.hover}#42413fTối: #cdccc9ON track, hover. Neutral boolean-state fill, never business-success green.
--bh-switch-on-track-pressed{color.background.neutral.bold.pressed}#5f5e5bTối: #a8a6a3ON track, pressed. Neutral boolean-state fill, never business-success green.
--bh-switch-on-track-focus{switch.on.track}#2b2a28Tối: #eeeeedON 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: #eeeeedON 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: #282827ON track, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-on-thumb{color.icon.inverse}#fdfdfcTối: #181717ON 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: #181717ON 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: #181717ON 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: #181717ON 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: #181717ON 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: #6b6a67ON thumb, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-on-label{color.text.inverse}#fdfdfcTối: #181717ON 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: #181717ON 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: #181717ON 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: #181717ON 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: #181717ON 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: #6b6a67ON label, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-on-border{color.background.neutral.bold}#2b2a28Tối: #eeeeedON border, normal. Meaningful boundary without changing native geometry.
--bh-switch-on-border-hover{color.background.neutral.bold.hover}#42413fTối: #cdccc9ON border, hover. Meaningful boundary without changing native geometry.
--bh-switch-on-border-pressed{color.background.neutral.bold.pressed}#5f5e5bTối: #a8a6a3ON border, pressed. Meaningful boundary without changing native geometry.
--bh-switch-on-border-focus{switch.on.border}#2b2a28Tối: #eeeeedON 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: #eeeeedON 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: #454443ON border, disabled. Opaque disabled role; checked position and visible labels remain. No opacity dimming.
--bh-switch-on-loading-icon{color.icon}#42413fTối: #cdccc9Spinner foreground inside the ON thumb, paired with switch.on.thumb.loading. Keep the native spinning indicator and blocked callback behavior.