Skip to content

Commit

Permalink
Fix transparent color (#714)
Browse files Browse the repository at this point in the history
Co-authored-by: Jefferson Vieira da Silva <[email protected]>
  • Loading branch information
jefferson-vieira and jefferson-vieira authored Aug 14, 2020
1 parent 6da9782 commit 2aa5380
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/helpers/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const toState = (data, oldHue) => {
}

export const isValidHex = (hex) => {
if (hex === 'transparent') {
return true
}
// disable hex4 and hex8
const lh = (String(hex).charAt(0) === '#') ? 1 : 0
return hex.length !== (4 + lh) && hex.length < (7 + lh) && tinycolor(hex).isValid()
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ describe('helpers/color', () => {
expect(color.isValidHex('FFFFFF')).toBeTruthy()
})

test('allow transparent color', () => {
expect(color.isValidHex('transparent')).toBeTruthy()
})

test('does not allow non-hex characters', () => {
expect(color.isValidHex('gggggg')).toBeFalsy()
})
Expand Down

0 comments on commit 2aa5380

Please sign in to comment.