Skip to content

Commit

Permalink
Merge pull request #2389 from wahidrahim/fix-custom-properties
Browse files Browse the repository at this point in the history
fix(custom-properties): use default key name if pluralize returns empty
  • Loading branch information
hasparus authored Feb 7, 2023
2 parents 2d8bfc3 + 91f14e9 commit 4c84e7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/custom-properties/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function makeCustomProperties(theme: Theme, prefix?: string) {

const generateProperties = (object: object, previousKey?: string) => {
Object.entries(object).forEach(([key, value]) => {
let formattedKey = pluralize(key, 1)
let formattedKey = pluralize(key, 1) || key

if (
process.env.NODE_ENV !== 'production' &&
Expand Down
6 changes: 6 additions & 0 deletions packages/custom-properties/test/__snapshots__/test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ exports[`transforms a theme config to CSS custom properties 1`] = `
"--fontWeight-heading": 700,
"--lineHeight-0": 1.5,
"--lineHeight-1": 1.125,
"--radius-l": "0.5em",
"--radius-m": "0.25em",
"--radius-s": "0.125em",
"--size-0": "10em",
"--size-1": "20em",
"--size-2": "30em",
Expand Down Expand Up @@ -49,6 +52,9 @@ exports[`transforms a theme config to CSS custom properties with prefix 1`] = `
"--🍭-fontWeight-heading": 700,
"--🍭-lineHeight-0": 1.5,
"--🍭-lineHeight-1": 1.125,
"--🍭-radius-l": "0.5em",
"--🍭-radius-m": "0.25em",
"--🍭-radius-s": "0.125em",
"--🍭-size-0": "10em",
"--🍭-size-1": "20em",
"--🍭-size-2": "30em",
Expand Down
5 changes: 5 additions & 0 deletions packages/custom-properties/test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const theme = {
lineHeights: [1.5, 1.125],
space: [0, 2, 3, 4, 5, 6],
size: ['10em', '20em', '30em', '40em'],
radii: {
s: '0.125em',
m: '0.25em',
l: '0.5em',
},
}

it('transforms a theme config to CSS custom properties', () => {
Expand Down

0 comments on commit 4c84e7d

Please sign in to comment.