Skip to content

Commit

Permalink
feat: added CSS custom media query transformer (#2068)
Browse files Browse the repository at this point in the history
* feat: added CSS custom media query transformer

* refactor: refactoring after review

* refactor: refactoring after review
  • Loading branch information
PKulkoRaccoonGang committed Aug 1, 2024
1 parent 1ef2dbd commit 9789c85
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-breakpoints";
@import "functions";
@import "variables";
@import "~bootstrap/scss/mixins";
Expand Down
12 changes: 12 additions & 0 deletions scss/core/css/custom-media-breakpoints.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 Fri, 24 Feb 2023 11:38:50 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-breakpoints',
destination: 'custom-media-breakpoints.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 for responsive breakpoints.
* Gets input about existing tokens of the 'size' category,
* 'breakpoints' subcategory, and generates a CSS custom media queries.
*/
StyleDictionary.registerFormat({
name: 'css/custom-media-breakpoints',
formatter({ dictionary, file }) {
const { size: { breakpoint } } = dictionary.properties;

let customMediaVariables = '';

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

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

module.exports = StyleDictionary;

0 comments on commit 9789c85

Please sign in to comment.