react-color
Advanced tools
Comparing version 2.17.2 to 2.17.3
@@ -55,3 +55,2 @@ 'use strict'; | ||
var colors = _color2.default.toState(data, data.h || _this.state.oldHue); | ||
_this.setState(colors); | ||
_this.props.onSwatchHover && _this.props.onSwatchHover(colors, event); | ||
@@ -58,0 +57,0 @@ } |
@@ -7,3 +7,2 @@ 'use strict'; | ||
var calculateChange = exports.calculateChange = function calculateChange(e, hsl, direction, initialA, container) { | ||
e.preventDefault(); | ||
var containerWidth = container.clientWidth; | ||
@@ -10,0 +9,0 @@ var containerHeight = container.clientHeight; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.red = undefined; | ||
exports.red = exports.getContrastingColor = exports.isValidHex = exports.toState = exports.simpleCheckForValidColor = undefined; | ||
@@ -19,61 +19,63 @@ var _each = require('lodash/each'); | ||
exports.default = { | ||
simpleCheckForValidColor: function simpleCheckForValidColor(data) { | ||
var keysToCheck = ['r', 'g', 'b', 'a', 'h', 's', 'l', 'v']; | ||
var checked = 0; | ||
var passed = 0; | ||
(0, _each2.default)(keysToCheck, function (letter) { | ||
if (data[letter]) { | ||
checked += 1; | ||
if (!isNaN(data[letter])) { | ||
var simpleCheckForValidColor = exports.simpleCheckForValidColor = function simpleCheckForValidColor(data) { | ||
var keysToCheck = ['r', 'g', 'b', 'a', 'h', 's', 'l', 'v']; | ||
var checked = 0; | ||
var passed = 0; | ||
(0, _each2.default)(keysToCheck, function (letter) { | ||
if (data[letter]) { | ||
checked += 1; | ||
if (!isNaN(data[letter])) { | ||
passed += 1; | ||
} | ||
if (letter === 's' || letter === 'l') { | ||
var percentPatt = /^\d+%$/; | ||
if (percentPatt.test(data[letter])) { | ||
passed += 1; | ||
} | ||
if (letter === 's' || letter === 'l') { | ||
var percentPatt = /^\d+%$/; | ||
if (percentPatt.test(data[letter])) { | ||
passed += 1; | ||
} | ||
} | ||
} | ||
}); | ||
return checked === passed ? data : false; | ||
}, | ||
toState: function toState(data, oldHue) { | ||
var color = data.hex ? (0, _tinycolor2.default)(data.hex) : (0, _tinycolor2.default)(data); | ||
var hsl = color.toHsl(); | ||
var hsv = color.toHsv(); | ||
var rgb = color.toRgb(); | ||
var hex = color.toHex(); | ||
if (hsl.s === 0) { | ||
hsl.h = oldHue || 0; | ||
hsv.h = oldHue || 0; | ||
} | ||
var transparent = hex === '000000' && rgb.a === 0; | ||
}); | ||
return checked === passed ? data : false; | ||
}; | ||
return { | ||
hsl: hsl, | ||
hex: transparent ? 'transparent' : '#' + hex, | ||
rgb: rgb, | ||
hsv: hsv, | ||
oldHue: data.h || oldHue || hsl.h, | ||
source: data.source | ||
}; | ||
}, | ||
isValidHex: function isValidHex(hex) { | ||
// disable hex4 and hex8 | ||
var lh = String(hex).charAt(0) === '#' ? 1 : 0; | ||
return hex.length !== 4 + lh && hex.length < 7 + lh && (0, _tinycolor2.default)(hex).isValid(); | ||
}, | ||
getContrastingColor: function getContrastingColor(data) { | ||
if (!data) { | ||
return '#fff'; | ||
} | ||
var col = this.toState(data); | ||
if (col.hex === 'transparent') { | ||
return 'rgba(0,0,0,0.4)'; | ||
} | ||
var yiq = (col.rgb.r * 299 + col.rgb.g * 587 + col.rgb.b * 114) / 1000; | ||
return yiq >= 128 ? '#000' : '#fff'; | ||
var toState = exports.toState = function toState(data, oldHue) { | ||
var color = data.hex ? (0, _tinycolor2.default)(data.hex) : (0, _tinycolor2.default)(data); | ||
var hsl = color.toHsl(); | ||
var hsv = color.toHsv(); | ||
var rgb = color.toRgb(); | ||
var hex = color.toHex(); | ||
if (hsl.s === 0) { | ||
hsl.h = oldHue || 0; | ||
hsv.h = oldHue || 0; | ||
} | ||
var transparent = hex === '000000' && rgb.a === 0; | ||
return { | ||
hsl: hsl, | ||
hex: transparent ? 'transparent' : '#' + hex, | ||
rgb: rgb, | ||
hsv: hsv, | ||
oldHue: data.h || oldHue || hsl.h, | ||
source: data.source | ||
}; | ||
}; | ||
var isValidHex = exports.isValidHex = function isValidHex(hex) { | ||
// disable hex4 and hex8 | ||
var lh = String(hex).charAt(0) === '#' ? 1 : 0; | ||
return hex.length !== 4 + lh && hex.length < 7 + lh && (0, _tinycolor2.default)(hex).isValid(); | ||
}; | ||
var getContrastingColor = exports.getContrastingColor = function getContrastingColor(data) { | ||
if (!data) { | ||
return '#fff'; | ||
} | ||
var col = toState(data); | ||
if (col.hex === 'transparent') { | ||
return 'rgba(0,0,0,0.4)'; | ||
} | ||
var yiq = (col.rgb.r * 299 + col.rgb.g * 587 + col.rgb.b * 114) / 1000; | ||
return yiq >= 128 ? '#000' : '#fff'; | ||
}; | ||
var red = exports.red = { | ||
@@ -84,2 +86,4 @@ hsl: { a: 1, h: 0, l: 0.5, s: 1 }, | ||
hsv: { h: 0, s: 1, v: 1, a: 1 } | ||
}; | ||
}; | ||
exports.default = exports; |
@@ -7,3 +7,2 @@ 'use strict'; | ||
var calculateChange = exports.calculateChange = function calculateChange(e, direction, hsl, container) { | ||
e.preventDefault(); | ||
var containerWidth = container.clientWidth; | ||
@@ -10,0 +9,0 @@ var containerHeight = container.clientHeight; |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var calculateChange = exports.calculateChange = function calculateChange(e, hsl, container) { | ||
e.preventDefault(); | ||
var _container$getBoundin = container.getBoundingClientRect(), | ||
@@ -11,0 +9,0 @@ containerWidth = _container$getBoundin.width, |
{ | ||
"name": "react-color", | ||
"version": "2.17.2", | ||
"version": "2.17.3", | ||
"description": "A Collection of Color Pickers from Sketch, Photoshop, Chrome & more", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
229238
94
5758