Skip to content

Commit 3ee117e

Browse files
authored
Add ::selection to color-mode-theme() mixin (#2472)
* Add `::selection` to color-mode-theme mixin * Document color-mode() mixin * Clarify warning * Create eleven-vans-repair.md
1 parent 07fa8a3 commit 3ee117e

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

.changeset/eleven-vans-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": patch
3+
---
4+
5+
Add `::selection` to `color-mode-theme()` mixin

src/support/mixins/color-modes.scss

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
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+
120
@mixin color-mode-theme($theme-name, $include-root: false) {
221
@if $include-root {
322
:root,
423
[data-color-mode="light"][data-light-theme="#{$theme-name}"],
524
[data-color-mode="dark"][data-dark-theme="#{$theme-name}"] {
6-
@content;
25+
&,
26+
&::selection {
27+
@content;
28+
}
729

830
/*! */ // This is a fix for a cssstats bug see https://github.com/cssstats/cssstats/issues/331
931
}
@@ -12,23 +34,61 @@
1234
@else {
1335
[data-color-mode="light"][data-light-theme="#{$theme-name}"],
1436
[data-color-mode="dark"][data-dark-theme="#{$theme-name}"] {
15-
@content;
37+
&,
38+
&::selection {
39+
@content;
40+
}
1641
}
1742
}
1843

1944
@media (prefers-color-scheme: light) {
2045
[data-color-mode="auto"][data-light-theme="#{$theme-name}"] {
21-
@content;
46+
&,
47+
&::selection {
48+
@content;
49+
}
2250
}
2351
}
2452

2553
@media (prefers-color-scheme: dark) {
2654
[data-color-mode="auto"][data-dark-theme="#{$theme-name}"] {
27-
@content;
55+
&,
56+
&::selection {
57+
@content;
58+
}
2859
}
2960
}
3061
}
3162

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+
3292
@mixin color-mode($mode) {
3393
@if $mode == light {
3494
:root,

0 commit comments

Comments
 (0)