Skip to content

Commit 37f3783

Browse files
committed
Add light-dark with !important tests and documentation
1 parent 0da1c42 commit 37f3783

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ Will be transformed to:
186186
}
187187
```
188188

189+
### light-dark with html and :root selectors
190+
189191
Note that `light-dark` function does not work on `:root`/`html` element. Use `light-root` and `dark-root` mixins instead:
190192

191193
```scss
@@ -206,6 +208,43 @@ Note that `light-dark` function does not work on `:root`/`html` element. Use `li
206208
}
207209
```
208210

211+
### light-dark and !important
212+
213+
`!important` at rule level:
214+
215+
```scss
216+
.button {
217+
color: light-dark(red, blue) !important;
218+
}
219+
220+
// Is transformed to
221+
.button {
222+
background: red !important;
223+
}
224+
225+
[data-mantine-color-scheme='dark'] .button {
226+
background: blue !important;
227+
}
228+
```
229+
230+
`!important` at value level:
231+
232+
```scss
233+
// !important at value level
234+
.button {
235+
color: light-dark(red !important, blue);
236+
}
237+
238+
// Is transformed to
239+
.button {
240+
background: red !important;
241+
}
242+
243+
[data-mantine-color-scheme='dark'] .button {
244+
background: blue;
245+
}
246+
```
247+
209248
## alpha function
210249

211250
`alpha` function can be used to add alpha channel to color. Note that it uses [color-mix](https://caniuse.com/mdn-css_types_color_color-mix) which is not supported in some older browsers.

src/tests/__snapshots__/light-dark.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ exports[`light-dark works when there are commas in the value 1`] = `
4848
"
4949
`;
5050

51+
exports[`light-dark works with !important 1`] = `
52+
"
53+
.button {
54+
background: red !important;
55+
}
56+
[data-mantine-color-scheme='dark'] .button {
57+
background: blue !important;
58+
}
59+
"
60+
`;
61+
62+
exports[`light-dark works with !important split 1`] = `
63+
"
64+
.button {
65+
background: red !important;
66+
}
67+
[data-mantine-color-scheme='dark'] .button {
68+
background: blue;
69+
}
70+
"
71+
`;
72+
5173
exports[`light-dark works with base input 1`] = `
5274
"
5375
.button {

src/tests/light-dark.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ const baseInput = `
66
}
77
`;
88

9+
const importantInput = `
10+
.button {
11+
background: light-dark(red, blue) !important;
12+
}
13+
`;
14+
15+
const importantSplitInput = `
16+
.button {
17+
background: light-dark(red !important, blue);
18+
}
19+
`;
20+
921
const mediaInput = `
1022
@media screen and (min-width: 400px) {
1123
.button {
@@ -61,4 +73,14 @@ describe('light-dark', () => {
6173
const res = await testTransform(commasInput);
6274
expect(res.css).toMatchSnapshot();
6375
});
76+
77+
it('works with !important', async () => {
78+
const res = await testTransform(importantInput);
79+
expect(res.css).toMatchSnapshot();
80+
});
81+
82+
it('works with !important split', async () => {
83+
const res = await testTransform(importantSplitInput);
84+
expect(res.css).toMatchSnapshot();
85+
});
6486
});

0 commit comments

Comments
 (0)