Skip to content

Commit 9f39277

Browse files
committed
Rename reduced-motion to motion-reduced, add motion-safe
1 parent 5dcb9f9 commit 9f39277

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ test('it can generate focus-visible variants', () => {
177177
})
178178
})
179179

180-
test('it can generate reduce-motion variants', () => {
180+
test('it can generate motion-reduced variants', () => {
181181
const input = `
182-
@variants reduce-motion {
182+
@variants motion-reduced {
183183
.banana { color: yellow; }
184184
.chocolate { color: brown; }
185185
}
@@ -189,8 +189,31 @@ test('it can generate reduce-motion variants', () => {
189189
.banana { color: yellow; }
190190
.chocolate { color: brown; }
191191
@media (prefers-reduced-motion: reduce) {
192-
.reduce-motion\\:banana { color: yellow; }
193-
.reduce-motion\\:chocolate { color: brown; }
192+
.motion-reduced\\:banana { color: yellow; }
193+
.motion-reduced\\:chocolate { color: brown; }
194+
}
195+
`
196+
197+
return run(input).then(result => {
198+
expect(result.css).toMatchCss(output)
199+
expect(result.warnings().length).toBe(0)
200+
})
201+
})
202+
203+
test('it can generate motion-safe variants', () => {
204+
const input = `
205+
@variants motion-safe {
206+
.banana { color: yellow; }
207+
.chocolate { color: brown; }
208+
}
209+
`
210+
211+
const output = `
212+
.banana { color: yellow; }
213+
.chocolate { color: brown; }
214+
@media (prefers-reduced-motion: no-preference) {
215+
.motion-safe\\:banana { color: yellow; }
216+
.motion-safe\\:chocolate { color: brown; }
194217
}
195218
`
196219

src/lib/substituteVariantsAtRules.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@ function ensureIncludesDefault(variants) {
2323

2424
const defaultVariantGenerators = config => ({
2525
default: generateVariantFunction(() => {}),
26-
'reduce-motion': generateVariantFunction(({ container, separator, modifySelectors }) => {
26+
'motion-safe': generateVariantFunction(({ container, separator, modifySelectors }) => {
2727
const modified = modifySelectors(({ selector }) => {
2828
return selectorParser(selectors => {
2929
selectors.walkClasses(sel => {
30-
sel.value = `reduce-motion${separator}${sel.value}`
30+
sel.value = `motion-safe${separator}${sel.value}`
31+
})
32+
}).processSync(selector)
33+
})
34+
const mediaQuery = postcss.atRule({
35+
name: 'media',
36+
params: '(prefers-reduced-motion: no-preference)',
37+
})
38+
mediaQuery.append(modified)
39+
container.append(mediaQuery)
40+
}),
41+
'motion-reduced': generateVariantFunction(({ container, separator, modifySelectors }) => {
42+
const modified = modifySelectors(({ selector }) => {
43+
return selectorParser(selectors => {
44+
selectors.walkClasses(sel => {
45+
sel.value = `motion-reduced${separator}${sel.value}`
3146
})
3247
}).processSync(selector)
3348
})

0 commit comments

Comments
 (0)