(tokens) make sass maps overridable

We suffix all sass maps with `!default` flag. In this way, if a consumer
 needs to override cunningham tokens, it will be able to.
This commit is contained in:
jbpenrath
2023-05-03 15:30:45 +02:00
committed by Jean-Baptiste PENRATH
parent fb2fb3e107
commit 7eac0bfca1
3 changed files with 14 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
---
"@openfun/cunningham-tokens": minor
---
Suffix all sass maps with the `!default` map

View File

@@ -30,22 +30,22 @@ describe("SassGenerator", () => {
'secondary': #DA0000,
'ternary-900': #022858,
'ogre-odor-is-orange-indeed': #FD5240
);
) !default;
$fontFamilies: (
'base': Roboto
);
) !default;
$fontSizes: (
'm': 1rem
);
) !default;
$fontWeights: (
'medium': 400
);
) !default;
$spacings: (
's': 1rem
);
) !default;
$transitions: (
'ease': linear
);
) !default;
"
`);
});

View File

@@ -49,7 +49,7 @@ const generateTransitionsSassMap = (tokens: Tokens) => {
return `$transitions: ${JSONToSassMap(tokens.theme.transitions)};`;
};
function JSONToSassMap(json: Object) {
function JSONToSassMap(json: Object, isDefault = true) {
function deepQuoteObjectKeys(object: Object) {
return Object.entries(object).reduce(
(acc, [key, value]): Record<string, any> => ({
@@ -65,5 +65,6 @@ function JSONToSassMap(json: Object) {
return JSON.stringify(jsonWithQuotedKeys, null, 2)
.replace(/{/g, "(")
.replace(/}/g, ")")
.replace(/"/g, "");
.replace(/"/g, "")
.concat(isDefault ? " !default" : "");
}