Skip to content

Commit

Permalink
feat: added CSS custom media query transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Feb 22, 2023
1 parent 2be3177 commit 8423208
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions scss/core/core.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "css/variables";
@import "css/custom-media";
@import "functions";
@import "variables";
@import "~bootstrap/scss/mixins";
Expand Down
12 changes: 12 additions & 0 deletions scss/core/css/custom-media.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* IMPORTANT: This file is the result of assembling design tokens
* Do not edit directly
* Generated on Tue, 21 Feb 2023 18:00:46 GMT
*/

@custom-media --pgn-size-breakpoint-xs (max-width: 0);
@custom-media --pgn-size-breakpoint-sm (max-width: 576px);
@custom-media --pgn-size-breakpoint-md (max-width: 768px);
@custom-media --pgn-size-breakpoint-lg (max-width: 992px);
@custom-media --pgn-size-breakpoint-xl (max-width: 1200px);
@custom-media --pgn-size-breakpoint-xxl (max-width: 1400px);
7 changes: 7 additions & 0 deletions tokens/build-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const config = {
outputReferences: true,
},
},
{
format: 'css/custom-media',
destination: 'custom-media.css',
options: {
outputReferences: true,
},
},
],
transforms: StyleDictionary.transformGroup.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
options: {
Expand Down
20 changes: 20 additions & 0 deletions tokens/style-dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,24 @@ StyleDictionary.registerFormat({
},
});

/**
* Formatter to generate CSS custom media queries.
* Gets input about existing tokens of the 'size' category,
* 'breakpoints' subcategory, and generates a CSS custom media queries.
*/
StyleDictionary.registerFormat({
name: 'css/custom-media',
formatter({ dictionary, file }) {
const { size: { breakpoint } } = dictionary.properties;

let customMediaVariables = '';

Object.keys(breakpoint).forEach(key => {
customMediaVariables += `@custom-media --${breakpoint[key].name} (max-width: ${breakpoint[key].value}); \n`;
});

return fileHeader({ file }) + customMediaVariables;
},
});

module.exports = StyleDictionary;

0 comments on commit 8423208

Please sign in to comment.