Skip to content

Commit c54ca85

Browse files
committed
Merge branch 'origin-main' into reduced-motion
1 parent 7369ab4 commit c54ca85

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

build/to-stylesheet.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import fs from 'fs'
22

3+
/**
4+
* Wraps a set of definitions inside of a media query
5+
* @param {*} queryValue The media value to query for
6+
* @param {*} definitions The definitions that need to be wrapped
7+
* @returns Media query string
8+
*/
9+
const wrapInQuery = (queryValue, definitions) => {
10+
return definitions ? `
11+
@media (${queryValue}) {
12+
${definitions.reduce((acc, [_, val], i) => (
13+
`${acc} ${i ? `\n` : ''} ${val}`
14+
), '')}
15+
}` : '';
16+
}
17+
318
export const buildPropsStylesheet = ({filename,props}, {selector,prefix}) => {
419
const file = fs.createWriteStream("../src/" + filename)
520

@@ -69,28 +84,8 @@ ${dark_propsMeta}
6984
return acc;
7085
}, [[], []])
7186

72-
73-
dark_props.forEach(([_, val]) => {
74-
appendedMeta += `
75-
@media (--OSdark) {
76-
${val};
77-
}
78-
`
79-
})
80-
81-
if (reduced_props.length) {
82-
appendedMeta += `
83-
@media (--motionNotOK) {`
84-
85-
reduced_props.forEach(([_, val]) => {
86-
appendedMeta += `
87-
${val}
88-
`
89-
})
90-
91-
appendedMeta += `
92-
}`
93-
}
87+
appendedMeta += wrapInQuery('--OSdark', dark_props)
88+
appendedMeta += wrapInQuery('--motionNotOK', reduced_props)
9489
}
9590

9691
file.write('}\n')

0 commit comments

Comments
 (0)