Skip to content

Commit

Permalink
fix: numeric values not being given px (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal authored Mar 12, 2021
1 parent c614dd8 commit 296ae26
Show file tree
Hide file tree
Showing 6 changed files with 1,155 additions and 1,049 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/createGetComputedCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import unitOnlyProps from './unitOnlyProps.js'
/** Token matcher. */
const captureTokens = /([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|--)([$\w-]+)/g

const toKebab = (value) => value.replace(/[A-Z]/g, (letter) => '-' + letter.toLowerCase())

/** Returns the name of a property with tokens & camel-casing transformed. */
const transformPropertyName = (name) => (/^\$/.test(name) ? '-' + name.replace(/\$/g, '-') : name.replace(/[A-Z]/g, (capital) => '-' + capital.toLowerCase()))
const transformPropertyName = (name) => (/^\$/.test(name) ? '-' + name.replace(/\$/g, '-') : toKebab(name))

/** Returns the data of a property with tokens & numerics transformed. */
const transformPropertyData = (name, data, themeMap) =>
// prettier-ignore
unitOnlyProps.test(name) && Number(data)
unitOnlyProps.test(toKebab(name)) && Number(data)
? String(data) + 'px'
: String(data).replace(
captureTokens,
Expand Down
Loading

0 comments on commit 296ae26

Please sign in to comment.