feat: allow for deeply nested color objects (#2148)
This commit is contained in:
parent
15d6fc4715
commit
58a600816c
2 changed files with 33 additions and 1 deletions
|
|
@ -43,3 +43,35 @@ test('it flattens nested color objects', () => {
|
|||
'blue-3': 'rgb(0,0,100)',
|
||||
})
|
||||
})
|
||||
|
||||
test('it flattens deeply nested color objects', () => {
|
||||
expect(
|
||||
flattenColorPalette({
|
||||
primary: 'purple',
|
||||
secondary: {
|
||||
DEFAULT: 'blue',
|
||||
hover: 'cyan',
|
||||
focus: 'red',
|
||||
},
|
||||
button: {
|
||||
primary: {
|
||||
DEFAULT: 'magenta',
|
||||
hover: 'green',
|
||||
focus: {
|
||||
DEFAULT: 'yellow',
|
||||
variant: 'orange',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
).toEqual({
|
||||
primary: 'purple',
|
||||
secondary: 'blue',
|
||||
'secondary-hover': 'cyan',
|
||||
'secondary-focus': 'red',
|
||||
'button-primary': 'magenta',
|
||||
'button-primary-hover': 'green',
|
||||
'button-primary-focus': 'yellow',
|
||||
'button-primary-focus-variant': 'orange',
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export default function flattenColorPalette(colors) {
|
|||
return [[name, color]]
|
||||
}
|
||||
|
||||
return _.map(color, (value, key) => {
|
||||
return _.map(flattenColorPalette(color), (value, key) => {
|
||||
const suffix = key === 'DEFAULT' ? '' : `-${key}`
|
||||
return [`${name}${suffix}`, value]
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue