Skip to content

Commit 842d414

Browse files
committed
refactor: generate selectors with theme's prefix
1 parent 1872951 commit 842d414

File tree

8 files changed

+141
-72
lines changed

8 files changed

+141
-72
lines changed

scss/_functions.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,8 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
296296

297297
@return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
298298
}
299+
300+
// Generate selectors for theme variants
301+
@function theme-prefix($selector) {
302+
@return #{"." + $theme-prefix + "\\:" + $selector + ", " + "." + $selector + ":not([class*='#{$theme-prefix}:'])"};
303+
}

scss/mixins/_alert.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// scss-docs-start alert-variant-mixin
2-
@mixin alert-variant($state, $variant) {
2+
@mixin alert-variant($state, $variant, $theme-prefix: false) {
33
$background: map-get($variant, "bg");
44
$border-color: map-get($variant, "border-color");
55
$color: contrast-ratio-correction(map-get($variant, "color"), map-get($variant, "bg"), abs($alert-color-scale), $state);
66
$link-color: map-get($variant, "link-color");
77

8-
.alert-#{$state} {
8+
$selector: if($theme-prefix, theme-prefix("alert-#{$state}"), ".alert-#{$state}");
9+
10+
#{$selector} {
911
--#{$variable-prefix}alert-color: #{$color};
1012
--#{$variable-prefix}alert-bg: #{$background};
1113
--#{$variable-prefix}alert-border-color: #{$border-color};

scss/mixins/_buttons.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// and disabled options for all buttons
55

66
// scss-docs-start btn-variant-mixin
7-
@mixin button-variant($state, $variant) {
7+
@mixin button-variant($state, $variant, $theme-prefix: false) {
88
$background: map-get($variant, "bg");
99
$border-color: map-get($variant, "border-color");
1010
$color: map-get($variant, "color");
@@ -19,7 +19,9 @@
1919
$disabled-color: map-get($variant, "disabled-color");
2020
$shadow: map-get($variant, "shadow");
2121

22-
.btn-#{$state} {
22+
$selector: if($theme-prefix, theme-prefix("btn-#{$state}"), ".btn-#{$state}");
23+
24+
#{$selector} {
2325
--#{$variable-prefix}btn-bg: #{$background};
2426
--#{$variable-prefix}btn-border-color: #{$border-color};
2527
--#{$variable-prefix}btn-color: #{$color};
@@ -38,7 +40,7 @@
3840
// scss-docs-end btn-variant-mixin
3941

4042
// scss-docs-start btn-outline-variant-mixin
41-
@mixin button-outline-variant($state, $variant) {
43+
@mixin button-outline-variant($state, $variant, $theme-prefix: false) {
4244
$color: map-get($variant, "color");
4345
$hover-background: map-get($variant, "hover-bg");
4446
$hover-border-color: map-get($variant, "hover-border-color");
@@ -49,7 +51,9 @@
4951
$disabled-color: map-get($variant, "disabled-color");
5052
$shadow: map-get($variant, "shadow");
5153

52-
.btn-outline-#{$state} {
54+
$selector: if($theme-prefix, theme-prefix("btn-outline-#{$state}"), ".btn-outline-#{$state}");
55+
56+
#{$selector} {
5357
--#{$variable-prefix}btn-border-color: #{$color};
5458
--#{$variable-prefix}btn-color: #{$color};
5559
--#{$variable-prefix}btn-hover-bg: #{$hover-background};
@@ -66,7 +70,7 @@
6670

6771
// Button Ghost
6872

69-
@mixin button-ghost-variant($state, $variant) {
73+
@mixin button-ghost-variant($state, $variant, $theme-prefix: false) {
7074
$color: map-get($variant, "color");
7175
$hover-background: map-get($variant, "hover-bg");
7276
$hover-border-color: map-get($variant, "hover-border-color");
@@ -77,7 +81,9 @@
7781
$disabled-color: map-get($variant, "disabled-color");
7882
$shadow: map-get($variant, "shadow");
7983

80-
.btn-ghost-#{$state} {
84+
$selector: if($theme-prefix, theme-prefix("btn-ghost-#{$state}"), ".btn-ghost-#{$state}");
85+
86+
#{$selector} {
8187
--#{$variable-prefix}btn-color: #{$color};
8288
--#{$variable-prefix}btn-hover-bg: #{$hover-background};
8389
--#{$variable-prefix}btn-hover-border-color: #{$hover-border-color};

scss/mixins/_list-group.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// List Groups
22
// scss-docs-start list-group-mixin
3-
@mixin list-group-item-variant($state, $variant) {
3+
@mixin list-group-item-variant($state, $variant, $theme-prefix: false) {
44
$background: map-get($variant, "bg");
55
$background-hover: map-get($variant, "bg-hover");
66
$color: contrast-ratio-correction(map-get($variant, "color"), map-get($variant, "bg"), abs($alert-color-scale), $state);
77

8-
.list-group-item-#{$state} {
8+
$selector: if($theme-prefix, theme-prefix("list-group-item-#{$state}"), ".list-group-item-#{$state}");
9+
10+
#{$selector} {
911
--#{$variable-prefix}list-group-color: #{$color};
1012
--#{$variable-prefix}list-group-bg: #{$background};
1113
--#{$variable-prefix}list-group-hover-bg: #{$background-hover};

scss/mixins/_utilities.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
$properties: append((), $properties);
1717
}
1818

19-
// Use class prefix if present
20-
$property-class-prefix: if(map-has-key($utility, prefix), map-get($utility, prefix), null);
21-
$property-class-prefix: if($property-class-prefix == null, "", $property-class-prefix);
22-
2319
// Use custom class if present
2420
$property-class: if(map-has-key($utility, class), map-get($utility, class), nth($properties, 1));
2521
$property-class: if($property-class == null, "", $property-class);
@@ -39,6 +35,9 @@
3935
// Generate RTL version
4036
$generate-rtl: if(map-has-key($utility, rtl), map-get($utility, rtl), false);
4137

38+
// Add theme prefix
39+
$theme-prefix: if(map-has-key($utility, theme-prefix), map-get($utility, theme-prefix), false);
40+
4241
@if map-get($utility, rfs) {
4342
// Inside the media query
4443
@if $is-rfs-media-query {
@@ -58,7 +57,9 @@
5857
@if $is-rtl == false {
5958
/* rtl:begin:remove */
6059
}
61-
.#{$property-class-prefix + $property-class + $infix + $property-class-modifier} {
60+
$selector: if($theme-prefix, theme-prefix("#{$property-class + $infix + $property-class-modifier}"), ".#{$property-class + $infix + $property-class-modifier}");
61+
62+
#{$selector} {
6263
@each $property in $properties {
6364
@if $generate-vars == true or $generate-only-vars == true {
6465
@if $generate-only-vars {

scss/themes/dark.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ $theme-prefix: "dark" !default;
2323

2424
@include theme($theme-map);
2525

26+
// Button variants
27+
28+
@each $state, $variant in $alert-variants-dt {
29+
@include alert-variant($state, $variant, true);
30+
}
31+
32+
// Button variants
33+
34+
@each $state, $variant in $button-variants-dt {
35+
@include button-variant($state, $variant, true);
36+
}
37+
38+
@each $state, $variant in $button-outline-ghost-variants-dt {
39+
@include button-outline-variant($state, $variant, true);
40+
}
41+
42+
@each $state, $variant in $button-outline-ghost-variants-dt {
43+
@include button-ghost-variant($state, $variant, true);
44+
}
45+
46+
// List group variants
47+
48+
@each $state, $variant in $list-group-variants-dt {
49+
@include list-group-item-variant($state, $variant, true);
50+
}
51+
2652
// Utilities
2753
@import "./../utilities/api";
2854
}

scss/themes/dark/_utilities.scss

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@ $utilities: ();
44
// stylelint-disable-next-line scss/dollar-variable-default
55
$utilities: map-merge(
66
(
7-
"background-color": (
8-
property: background-color,
9-
prefix: "dark\\:",
10-
class: bg,
7+
"color": (
8+
property: color,
9+
class: text,
1110
values: map-merge(
1211
$theme-colors,
1312
(
14-
"body": $body-bg,
1513
"white": $white,
16-
"transparent": transparent
14+
"body": $body-color-dt,
15+
"black-50": rgba($black, .5),
16+
"white-50": rgba($white, .5),
17+
"reset": inherit,
18+
"high-emphasis": $high-emphasis-dt,
19+
"medium-emphasis": $medium-emphasis-dt,
20+
"disabled": $disabled-dt
1721
)
1822
),
19-
vars: true
23+
only-vars: true,
24+
theme-prefix: true,
2025
),
21-
"background-color-exclude": (
26+
"background-color": (
2227
property: background-color,
2328
class: bg,
24-
postfix: ":not([class*='dark:'])",
2529
values: map-merge(
2630
$theme-colors,
2731
(
@@ -30,8 +34,9 @@ $utilities: map-merge(
3034
"transparent": transparent
3135
)
3236
),
33-
vars: true
34-
),
37+
only-vars: true,
38+
theme-prefix: true,
39+
)
3540
),
3641
$utilities
3742
);

0 commit comments

Comments
 (0)