Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Apr 25, 2021
2 parents c9288bf + fbfb0f7 commit 0206409
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/shared/src/createInterpolator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,13 @@ describe('Interpolation', () => {

expect(interpolation(0.5)).toBe('rgba(2, 2, 2, 0.5)')
})

it('should not match partial color names', () => {
const interpolation = createInterpolator({
range: [0, 1],
output: ['grayscale(0%)', 'grayscale(100%)'],
})

expect(interpolation(0.5)).toBe('grayscale(50%)')
})
})
6 changes: 4 additions & 2 deletions packages/shared/src/stringInterpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export const createStringInterpolator = (
) => {
if (!namedColorRegex)
namedColorRegex = G.colors
? new RegExp(`(${Object.keys(G.colors).join('|')})`, 'g')
: /^\b$/ // never match
? // match color names, ignore partial matches
new RegExp(`(${Object.keys(G.colors).join('|')})(?!\\w)`, 'g')
: // never match
/^\b$/

// Convert colors to rgba(...)
const output = config.output.map(value =>
Expand Down

0 comments on commit 0206409

Please sign in to comment.