Skip to content

Commit

Permalink
Disable hex4 and hex8 (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
elvisvoer authored and casesandberg committed Feb 17, 2018
1 parent ccf5e98 commit 669bf04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/helpers/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export default {
},

isValidHex(hex) {
return tinycolor(hex).isValid()
// disable hex4 and hex8
const lh = (String(hex).charAt(0) === '#') ? 1 : 0
return hex.length !== (4 + lh) && hex.length < (7 + lh) && tinycolor(hex).isValid()
},

getContrastingColor(data) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ describe('helpers/color', () => {
})

describe('isValidHex', () => {
test('allows strings of length 3, 6, or 8', () => {
test('allows strings of length 3 or 6', () => {
expect(color.isValidHex('f')).toBeFalsy()
expect(color.isValidHex('ff')).toBeFalsy()
expect(color.isValidHex('fff')).toBeTruthy()
// expect(color.isValidHex('ffff')).toBeFalsy()
expect(color.isValidHex('ffff')).toBeFalsy()
expect(color.isValidHex('fffff')).toBeFalsy()
expect(color.isValidHex('ffffff')).toBeTruthy()
expect(color.isValidHex('fffffff')).toBeFalsy()
expect(color.isValidHex('ffffffff')).toBeTruthy()
expect(color.isValidHex('ffffffff')).toBeFalsy()
expect(color.isValidHex('fffffffff')).toBeFalsy()
expect(color.isValidHex('ffffffffff')).toBeFalsy()
expect(color.isValidHex('fffffffffff')).toBeFalsy()
Expand Down

0 comments on commit 669bf04

Please sign in to comment.