Skip to content

Commit 73f493c

Browse files
authored
refactor(switch): cleanup code (#197)
1 parent 6c8e41a commit 73f493c

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

src/assets/scss/components/_switch.scss

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
@use "sass:map";
22

33
/* @docs */
4-
$switch-spacer: 0.5em !default;
5-
$switch-width: 2.75em !default;
6-
$switch-height: 1.5em !default;
4+
$switch-spacer: 0.5rem !default;
75
/* @docs */
86

97
/* @bootstrap docs */
@@ -22,27 +20,17 @@ $switch-height: 1.5em !default;
2220
// $form-switch-checked-bg-position: right center;
2321
/* @bootstrap docs */
2422

25-
@function switchSVG($color, $svg, $replacement) {
23+
@function switchSVG($svg, $color) {
2624
@return escape-svg(str-replace($svg, "#{$form-switch-color}", $color));
2725
}
2826

2927
.form-switch {
3028
--#{$prefix}switch-spacer: #{$switch-spacer};
31-
--#{$prefix}switch-height: #{$switch-height};
32-
--#{$prefix}switch-width: #{$switch-width};
3329

3430
position: relative;
35-
padding-left: 0;
3631

37-
.form-check-input {
38-
height: var(--#{$prefix}switch-height);
39-
width: var(--#{$prefix}switch-width);
40-
margin: 0;
41-
cursor: pointer;
42-
43-
&:not(:last-child) {
44-
margin-right: var(--#{$prefix}switch-spacer);
45-
}
32+
&:not(:last-child) {
33+
margin-right: var(--#{$prefix}switch-spacer);
4634
}
4735

4836
// color variant
@@ -52,63 +40,52 @@ $switch-height: 1.5em !default;
5240
border-color: var(--#{$prefix}#{$name});
5341

5442
--#{$prefix}form-switch-bg: #{switchSVG(
55-
$color,
5643
$form-switch-bg-image,
57-
$form-switch-color
44+
$color
5845
)};
5946

6047
&:checked {
6148
background-color: var(--#{$prefix}#{$name});
6249
--#{$prefix}form-switch-bg: #{switchSVG(
63-
$white,
6450
$form-switch-checked-bg-image,
65-
$form-switch-checked-color
51+
$white
6652
)};
6753
}
6854
}
69-
}
7055

71-
// possive colors variant
72-
@each $name, $color in $theme-colors {
73-
&.variant-#{$name}-passive input[type="checkbox"] {
74-
background-color: var(--#{$prefix}#{$name});
75-
border-color: var(--#{$prefix}#{$name});
76-
77-
--#{$prefix}form-switch-bg: #{switchSVG(
78-
$white,
79-
$form-switch-bg-image,
80-
$form-switch-color
81-
)};
56+
// possive colors variant
57+
&.variant-#{$name}-passive {
58+
input[type="checkbox"]:checked {
59+
background-color: var(--#{$prefix}#{$name});
60+
border-color: var(--#{$prefix}#{$name});
61+
}
8262
}
83-
}
8463

85-
// subtle color variant
86-
@each $name, $color in $theme-colors {
64+
// subtle color variant
8765
&.variant-#{$name}-subtle input[type="checkbox"] {
8866
$color: map.get($theme-colors-bg-subtle, #{$name});
8967

9068
background-color: transparent;
9169
border-color: var(--#{$prefix}#{$name}-border-subtle);
9270

9371
--#{$prefix}form-switch-bg: #{switchSVG(
94-
$color,
9572
$form-switch-bg-image,
96-
$form-switch-color
73+
$color
9774
)};
9875

9976
&:checked {
10077
background-color: var(--#{$prefix}#{$name}-bg-subtle);
10178
--#{$prefix}form-switch-bg: #{switchSVG(
102-
$white,
10379
$form-switch-checked-bg-image,
104-
$form-switch-checked-color
80+
$white
10581
)};
10682
}
10783
}
10884
}
10985

11086
&.reversed {
11187
display: flex;
88+
padding-left: unset;
11289

11390
.form-check-input {
11491
order: 2;

0 commit comments

Comments
 (0)