Skip to content

Commit a467d09

Browse files
PKulkoRaccoonGangmonteri
authored and
monteri
committed
feat: added CSS custom media query transformer (openedx#2068)
* feat: added CSS custom media query transformer * refactor: refactoring after review * refactor: refactoring after review
1 parent 5ef14fe commit a467d09

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

scss/core/core.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "css/variables";
2+
@import "css/custom-media-breakpoints";
23
@import "functions";
34
@import "variables";
45
@import "~bootstrap/scss/mixins";
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* IMPORTANT: This file is the result of assembling design tokens
3+
* Do not edit directly
4+
* Generated on Fri, 24 Feb 2023 11:38:50 GMT
5+
*/
6+
7+
@custom-media --pgn-size-breakpoint-xs (max-width: 0);
8+
@custom-media --pgn-size-breakpoint-sm (max-width: 576px);
9+
@custom-media --pgn-size-breakpoint-md (max-width: 768px);
10+
@custom-media --pgn-size-breakpoint-lg (max-width: 992px);
11+
@custom-media --pgn-size-breakpoint-xl (max-width: 1200px);
12+
@custom-media --pgn-size-breakpoint-xxl (max-width: 1400px);

tokens/build-tokens.js

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ const config = {
4242
outputReferences: true,
4343
},
4444
},
45+
{
46+
format: 'css/custom-media-breakpoints',
47+
destination: 'custom-media-breakpoints.css',
48+
options: {
49+
outputReferences: true,
50+
},
51+
},
4552
],
4653
transforms: StyleDictionary.transformGroup.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
4754
options: {

tokens/style-dictionary.js

+20
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,24 @@ StyleDictionary.registerFormat({
154154
},
155155
});
156156

157+
/**
158+
* Formatter to generate CSS custom media queries for responsive breakpoints.
159+
* Gets input about existing tokens of the 'size' category,
160+
* 'breakpoints' subcategory, and generates a CSS custom media queries.
161+
*/
162+
StyleDictionary.registerFormat({
163+
name: 'css/custom-media-breakpoints',
164+
formatter({ dictionary, file }) {
165+
const { size: { breakpoint } } = dictionary.properties;
166+
167+
let customMediaVariables = '';
168+
169+
Object.values(breakpoint).forEach(item => {
170+
customMediaVariables += `@custom-media --${item.name} (max-width: ${item.value}); \n`;
171+
});
172+
173+
return fileHeader({ file }) + customMediaVariables;
174+
},
175+
});
176+
157177
module.exports = StyleDictionary;

0 commit comments

Comments
 (0)