-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance support for the nested theme token structure (#958)
* feat: enhance support for the nested theme token structure * test: add tests for the `getter` transform * feat(styled-system): enhance folder structure for better readability * Create tonic-ui-956.md * chore: update yarn.lock file * feat: import `isNullish` and `merge` from `@tonic-ui/utils` * chore: update yarn.lock file * chore: update tonic-ui-956.md
- Loading branch information
Showing
25 changed files
with
389 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tonic-ui/styled-system": minor | ||
--- | ||
|
||
feat: enhance support for the nested theme token structure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/styled-system/src/transforms/__tests__/getter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import getter from '../getter'; | ||
|
||
describe('getter', () => { | ||
const theme = { | ||
colors: { | ||
// flat theme tokens | ||
'white:primary': 'rgba(255, 255, 255, .92)', | ||
'white:secondary': 'rgba(255, 255, 255, .60)', | ||
'black:primary': 'rgba(0, 0, 0, .92)', | ||
'black:secondary': 'rgba(0, 0, 0, .65)', | ||
|
||
// nested theme tokens | ||
white: { | ||
primary: { | ||
value: 'rgba(255, 255, 255, .92)', | ||
}, | ||
secondary: { | ||
value: 'rgba(255, 255, 255, .60)', | ||
}, | ||
}, | ||
black: { | ||
primary: { | ||
value: 'rgba(0, 0, 0, .92)', | ||
}, | ||
secondary: { | ||
value: 'rgba(0, 0, 0, .65)', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
it('should resolve flat color tokens', () => { | ||
expect(getter(theme.colors, 'white:primary')).toBe('rgba(255, 255, 255, .92)'); | ||
expect(getter(theme.colors, 'white:secondary')).toBe('rgba(255, 255, 255, .60)'); | ||
expect(getter(theme.colors, 'black:primary')).toBe('rgba(0, 0, 0, .92)'); | ||
expect(getter(theme.colors, 'black:secondary')).toBe('rgba(0, 0, 0, .65)'); | ||
}); | ||
|
||
it('should resolve nested color tokens with dot notation', () => { | ||
expect(getter(theme.colors, 'white.primary')).toBe('rgba(255, 255, 255, .92)'); | ||
expect(getter(theme.colors, 'white.secondary')).toBe('rgba(255, 255, 255, .60)'); | ||
expect(getter(theme.colors, 'black.primary')).toBe('rgba(0, 0, 0, .92)'); | ||
expect(getter(theme.colors, 'black.secondary')).toBe('rgba(0, 0, 0, .65)'); | ||
}); | ||
|
||
it('should fallback to original value when token path does not exist', () => { | ||
expect(getter(theme.colors, 'white')).toBe('white'); | ||
}); | ||
|
||
it('should handle undefined theme values', () => { | ||
expect(getter(undefined, 'white.undefined')).toBe('white.undefined'); | ||
}); | ||
|
||
it('should handle nested objects without value property', () => { | ||
const customTheme = { | ||
colors: { | ||
custom: { | ||
primary: 'rgb(100, 100, 100)', | ||
}, | ||
}, | ||
}; | ||
const result = getter(customTheme.colors, 'custom.primary'); | ||
expect(result).toBe('rgb(100, 100, 100)'); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/styled-system/src/transforms/__tests__/positiveOrNegative.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import positiveOrNegative from '../positiveOrNegative'; | ||
|
||
describe('positiveOrNegative', () => { | ||
const theme = { | ||
sizes: { | ||
'1x': '.25rem', | ||
'2x': '.5rem', | ||
'3x': '.75rem', | ||
'4x': '1rem', | ||
}, | ||
}; | ||
|
||
it('should handle positive values', () => { | ||
expect(positiveOrNegative(theme.sizes, '1x')).toBe('.25rem'); | ||
expect(positiveOrNegative(theme.sizes, '2x')).toBe('.5rem'); | ||
expect(positiveOrNegative(theme.sizes, '3x')).toBe('.75rem'); | ||
expect(positiveOrNegative(theme.sizes, '4x')).toBe('1rem'); | ||
}); | ||
|
||
it('should handle negative values', () => { | ||
expect(positiveOrNegative(theme.sizes, '-1x')).toBe('-.25rem'); | ||
expect(positiveOrNegative(theme.sizes, '-2x')).toBe('-.5rem'); | ||
expect(positiveOrNegative(theme.sizes, '-3x')).toBe('-.75rem'); | ||
expect(positiveOrNegative(theme.sizes, '-4x')).toBe('-1rem'); | ||
}); | ||
|
||
it('should return original value when theme.sizes value is not found', () => { | ||
expect(positiveOrNegative(theme.sizes, '5x')).toBe('5x'); | ||
expect(positiveOrNegative(theme.sizes, '-5x')).toBe('-5x'); | ||
}); | ||
|
||
it('should handle undefined theme.sizes', () => { | ||
expect(positiveOrNegative(undefined, '2x')).toBe('2x'); | ||
expect(positiveOrNegative(undefined, '-2x')).toBe('-2x'); | ||
}); | ||
|
||
it('should handle non-numeric strings', () => { | ||
expect(positiveOrNegative(theme.sizes, 'auto')).toBe('auto'); | ||
expect(positiveOrNegative(theme.sizes, '4px')).toBe('4px'); | ||
expect(positiveOrNegative(theme.sizes, '-4px')).toBe('-4px'); | ||
}); | ||
}); |
Oops, something went wrong.