From 590b1fe75aad1f56c5ca1b88053cc55fd503da50 Mon Sep 17 00:00:00 2001 From: Andrew Holloway Date: Thu, 16 May 2024 17:58:53 -0500 Subject: [PATCH] fix: update token and theming - support non-subset theming overrides - support spacing (with proper open typing) --- bin/eds-apply-theme.js | 2 -- tailwind.config.ts | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bin/eds-apply-theme.js b/bin/eds-apply-theme.js index ad0b6cfc9..b88a35be0 100755 --- a/bin/eds-apply-theme.js +++ b/bin/eds-apply-theme.js @@ -85,8 +85,6 @@ }); try { - // Keys in the theme file must be a strict subset of those in the base file - isStrictSubset(baseTheme, localTheme); EDSStyleDictionary.buildAllPlatforms(); } catch (error) { // TODO: if theme has things not in base, error showing where the conflict diff --git a/tailwind.config.ts b/tailwind.config.ts index 11bf2fe66..d56aabbd0 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -8,6 +8,22 @@ const { ...colorTokens } = edsTokens.theme.color; +// Add a type to the token sizes to avoid literals for keys +const sizes: { [x: string]: string } = edsTokens.size; + +const sizeTokens = { + // We pull the spacing tokens and format them such that names are like 'size-${name} = ${value}px' + ...Object.keys(sizes) + .map((sizeKey) => { + return { [`size-${sizeKey}`]: `${sizes[sizeKey]}px` }; + }) + .reduce((accumulate, current) => { + const entry = Object.entries(current)[0]; + accumulate[entry[0]] = entry[1]; + return accumulate; + }, {}), +}; + export default { /** * The main value in TW utility classes is for Storybook stories, etc.. @@ -34,16 +50,7 @@ export default { ...textColorTokens, }, spacing: { - // We pull the spacing tokens and format them such that names are like 'size-${name} = ${value}px' - ...Object.keys(edsTokens.size) - .map((sizeKey) => { - return { [`size-${sizeKey}`]: `${edsTokens.size[sizeKey]}px` }; - }) - .reduce((accumulate, current) => { - const entry = Object.entries(current)[0]; - accumulate[entry[0]] = entry[1]; - return accumulate; - }, {}), + ...sizeTokens, }, }, fontWeight: {