diff --git a/scss/_utilities.scss b/scss/_utilities.scss index d25c870655..668988f596 100644 --- a/scss/_utilities.scss +++ b/scss/_utilities.scss @@ -897,7 +897,7 @@ $utilities: map.merge( // scss-docs-end utils-zindex // scss-docs-start utils-check-colors "check-color": ( - property: --#{$prefix}check-checked-bg --#{$prefix}check-checked-border-color --#{$prefix}radio-checked-bg --#{$prefix}radio-checked-border-color, + property: --#{$prefix}check-checked-bg --#{$prefix}check-checked-border-color --#{$prefix}radio-checked-bg --#{$prefix}radio-checked-border-color --#{$prefix}switch-checked-bg, class: checked, values: theme-color-values("bg") ) diff --git a/scss/forms/_switch.scss b/scss/forms/_switch.scss index 457d170a4f..ccb20bc6e4 100644 --- a/scss/forms/_switch.scss +++ b/scss/forms/_switch.scss @@ -21,6 +21,7 @@ --#{$prefix}switch-border-color: var(--#{$prefix}border-color); --#{$prefix}switch-indicator-bg: var(--#{$prefix}white); --#{$prefix}switch-checked-bg: var(--#{$prefix}primary-base); + --#{$prefix}switch-checked-border-color: var(--#{$prefix}switch-checked-bg); --#{$prefix}switch-checked-indicator-bg: var(--#{$prefix}white); --#{$prefix}switch-disabled-bg: var(--#{$prefix}secondary-bg); --#{$prefix}switch-disabled-indicator-bg: var(--#{$prefix}secondary-text); @@ -65,7 +66,8 @@ &:has(input:checked) { padding-inline-start: calc(var(--#{$prefix}switch-height) / 2 + var(--#{$prefix}switch-padding)); - background-color: var(--#{$prefix}primary-base); + background-color: var(--#{$prefix}switch-checked-bg); + border-color: var(--#{$prefix}switch-checked-border-color); } &:has(input:disabled) { diff --git a/site/src/content/docs/forms/switch.mdx b/site/src/content/docs/forms/switch.mdx index c98f424d8c..4112b91b6d 100644 --- a/site/src/content/docs/forms/switch.mdx +++ b/site/src/content/docs/forms/switch.mdx @@ -4,6 +4,8 @@ description: Custom toggle component built on top of native `` checkbox e toc: true --- +import { getData } from '@libs/data' + ## Basic switch Switches are built with checkboxes under the hood, so their HTML closely mirrors that of checkboxes, including optional layout components. @@ -36,6 +38,17 @@ Consider margin utilities for additional spacing, and flex utilities for alignme `} /> +## Theme colors + +Modify the appearance of checked checkboxes by adding the `.checked-{color}` class to the `.switch` element. This will set the checked background and border color to the theme color. + + ` +
+ +
+ +
`)} /> + ## Disabled Add the `disabled` attribute and the associated `