Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BD-46] feat: added CSS custom media query transformer #2068

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat to see that this wasn't that large of a lift given what we already had! 🚀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's very simple thanks to the Style Dictionary setups 💯


let customMediaVariables = '';

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

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

module.exports = StyleDictionary;