Skip to content

Commit 53d1cdb

Browse files
committed
Follow up: custom switches get themes
1 parent d8493bf commit 53d1cdb

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

scss/_utilities.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ $utilities: map.merge(
897897
// scss-docs-end utils-zindex
898898
// scss-docs-start utils-check-colors
899899
"check-color": (
900-
property: --#{$prefix}check-checked-bg --#{$prefix}check-checked-border-color --#{$prefix}radio-checked-bg --#{$prefix}radio-checked-border-color,
900+
property: --#{$prefix}check-checked-bg --#{$prefix}check-checked-border-color --#{$prefix}radio-checked-bg --#{$prefix}radio-checked-border-color --#{$prefix}switch-checked-bg,
901901
class: checked,
902902
values: theme-color-values("bg")
903903
)

scss/forms/_switch.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
--#{$prefix}switch-border-color: var(--#{$prefix}border-color);
2222
--#{$prefix}switch-indicator-bg: var(--#{$prefix}white);
2323
--#{$prefix}switch-checked-bg: var(--#{$prefix}primary-base);
24+
--#{$prefix}switch-checked-border-color: var(--#{$prefix}switch-checked-bg);
2425
--#{$prefix}switch-checked-indicator-bg: var(--#{$prefix}white);
2526
--#{$prefix}switch-disabled-bg: var(--#{$prefix}secondary-bg);
2627
--#{$prefix}switch-disabled-indicator-bg: var(--#{$prefix}secondary-text);
@@ -65,7 +66,8 @@
6566

6667
&:has(input:checked) {
6768
padding-inline-start: calc(var(--#{$prefix}switch-height) / 2 + var(--#{$prefix}switch-padding));
68-
background-color: var(--#{$prefix}primary-base);
69+
background-color: var(--#{$prefix}switch-checked-bg);
70+
border-color: var(--#{$prefix}switch-checked-border-color);
6971
}
7072

7173
&:has(input:disabled) {

site/src/content/docs/forms/switch.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Custom toggle component built on top of native `<input>` checkbox e
44
toc: true
55
---
66

7+
import { getData } from '@libs/data'
8+
79
## Basic switch
810

911
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
3638
<label for="switchMdLabel">Default switch</label>
3739
</b-checkgroup>`} />
3840

41+
## Theme colors
42+
43+
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.
44+
45+
<Example class="d-flex flex-column gap-2" code={getData('theme-colors').map((themeColor) => ` <b-checkgroup>
46+
<div class="switch switch-sm mt-1 checked-${themeColor.name}">
47+
<input type="checkbox" value="" id="switch${themeColor.name}" switch checked>
48+
</div>
49+
<label for="switch${themeColor.name}">Example ${themeColor.name} switch</label>
50+
</b-checkgroup>`)} />
51+
3952
## Disabled
4053

4154
Add the `disabled` attribute and the associated `<label>`s are automatically styled to match with a lighter color to help indicate the input’s state.

0 commit comments

Comments
 (0)