|
| 1 | +// This mixin is used to output the tokens/variables from Primitives |
| 2 | +// |
| 3 | +// Example: |
| 4 | +// |
| 5 | +// @include color-mode-theme(dark) { |
| 6 | +// --color: black; |
| 7 | +// } |
| 8 | +// |
| 9 | +// Warning!!! |
| 10 | +// Don't use this mixin with a class. E.g. |
| 11 | +// @include color-mode-theme(dark) { |
| 12 | +// .my-class { |
| 13 | +// color: red; |
| 14 | +// } |
| 15 | +// } |
| 16 | +// |
| 17 | +// The outputted `::selection .my-class` will make the selector invalid and the entire ruleset is disregarded. |
| 18 | +// At some point we hopefully can remove the need for `&, &::selection {}` again (once the spec/implementation changes). |
| 19 | + |
1 | 20 | @mixin color-mode-theme($theme-name, $include-root: false) { |
2 | 21 | @if $include-root { |
3 | 22 | :root, |
4 | 23 | [data-color-mode="light"][data-light-theme="#{$theme-name}"], |
5 | 24 | [data-color-mode="dark"][data-dark-theme="#{$theme-name}"] { |
6 | | - @content; |
| 25 | + &, |
| 26 | + &::selection { |
| 27 | + @content; |
| 28 | + } |
7 | 29 |
|
8 | 30 | /*! */ // This is a fix for a cssstats bug see https://github.com/cssstats/cssstats/issues/331 |
9 | 31 | } |
|
12 | 34 | @else { |
13 | 35 | [data-color-mode="light"][data-light-theme="#{$theme-name}"], |
14 | 36 | [data-color-mode="dark"][data-dark-theme="#{$theme-name}"] { |
15 | | - @content; |
| 37 | + &, |
| 38 | + &::selection { |
| 39 | + @content; |
| 40 | + } |
16 | 41 | } |
17 | 42 | } |
18 | 43 |
|
19 | 44 | @media (prefers-color-scheme: light) { |
20 | 45 | [data-color-mode="auto"][data-light-theme="#{$theme-name}"] { |
21 | | - @content; |
| 46 | + &, |
| 47 | + &::selection { |
| 48 | + @content; |
| 49 | + } |
22 | 50 | } |
23 | 51 | } |
24 | 52 |
|
25 | 53 | @media (prefers-color-scheme: dark) { |
26 | 54 | [data-color-mode="auto"][data-dark-theme="#{$theme-name}"] { |
27 | | - @content; |
| 55 | + &, |
| 56 | + &::selection { |
| 57 | + @content; |
| 58 | + } |
28 | 59 | } |
29 | 60 | } |
30 | 61 | } |
31 | 62 |
|
| 63 | +// This mixin wraps styles with light or dark mode selectors |
| 64 | +// If possible, use a color variable instead. |
| 65 | +// |
| 66 | +// Example: |
| 67 | +// |
| 68 | +// @include color-mode('dark') { |
| 69 | +// .my-class { |
| 70 | +// color: red; |
| 71 | +// } |
| 72 | +// } |
| 73 | +// |
| 74 | +// Returns: |
| 75 | +// |
| 76 | +// [data-color-mode=light][data-light-theme*=dark] .my-class, |
| 77 | +// [data-color-mode=dark][data-dark-theme*=dark] .my-class { |
| 78 | +// color: red; |
| 79 | +// } |
| 80 | +// |
| 81 | +// @media (prefers-color-scheme: light) { |
| 82 | +// [data-color-mode=auto][data-light-theme*=dark] .my-class { |
| 83 | +// color: red; |
| 84 | +// } |
| 85 | +// } |
| 86 | +// @media (prefers-color-scheme: dark) { |
| 87 | +// [data-color-mode=auto][data-dark-theme*=dark] .my-class { |
| 88 | +// color: red; |
| 89 | +// } |
| 90 | +// } |
| 91 | + |
32 | 92 | @mixin color-mode($mode) { |
33 | 93 | @if $mode == light { |
34 | 94 | :root, |
|
0 commit comments