Proposal
Categorize the tokens across relevant theme files.
Why?
Currently, all the tokens stay in the same hierarchy at the root level of the Token object. (both named and unnamed). The issue that arises with this approach is that all the theme colour objects stay at the same level as the fontSizes = {}
object. Which causes an issue when we need to override certain components inside our existing theme/design system.
For example, in cases such: tailwind-next, the existing tailwind theme colours of a project are overridden as:
theme: {
extend: {
colors: mirrorful.Tokens,
},
},
This approach works fine but the fontSizes = {}
object will also be included in the colors
object of tailwind, which won't break anything but should not be there. As the project size increases more and more components will be added and I think the categorization process should be done from the very start instead of people having to run migrations at a later stage.
Note: For now, I just added a basic .filter()
function to mirrorful.Tokens
which excludes the fontSizes
object, but I think it's a very hacky approach and would keep getting worse if/when more components are added to the theme files.
Current Structure
exports.Tokens = {
'acme-inc-purple': {
50: '#fefeff',
100: '#ebe4fb',
200: '#d8c9f7',
300: '#c5aff2',
400: '#b294ee',
500: '#9f7aea',
600: '#8c60e6',
700: '#7945e2',
800: '#662bdd',
900: '#5820ca',
base: '#9F7AEA',
},
'acme-inc-error-red': {
50: '#fffefe',
100: '#fbe4e9',
200: '#f7c9d3',
300: '#f2afbd',
400: '#ee94a8',
500: '#ea7a92',
600: '#e6607c',
700: '#e24567',
800: '#dd2b51',
900: '#ca2044',
base: '#ea7a92',
},
...
fontSizes: {
sm: '1rem',
md: '1.2rem',
lg: '1.4rem',
},
}
Proposed Structure
exports.Tokens = {
themeColors: {
'acme-inc-purple': {
50: '#fefeff',
100: '#ebe4fb',
200: '#d8c9f7',
300: '#c5aff2',
400: '#b294ee',
500: '#9f7aea',
600: '#8c60e6',
700: '#7945e2',
800: '#662bdd',
900: '#5820ca',
base: '#9F7AEA',
},
'acme-inc-error-red': {
50: '#fffefe',
100: '#fbe4e9',
200: '#f7c9d3',
300: '#f2afbd',
400: '#ee94a8',
500: '#ea7a92',
600: '#e6607c',
700: '#e24567',
800: '#dd2b51',
900: '#ca2044',
base: '#ea7a92',
},
},
fontSizes: {
sm: '1rem',
md: '1.2rem',
lg: '1.4rem',
},
xyzCategory: {
key1: 'value1',
key2: 'value2',
},
pqrCategory: {
key3: 'value3',
key4: 'value4',
},
}