| 1 |
/* |
| 2 |
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) |
| 3 |
*/ |
| 4 |
export const colorLuminance = (hex, lum) => { |
| 5 |
// Validate hex string |
| 6 |
hex = String(hex).replace(/[^0-9a-f]/gi, '') |
| 7 |
if (hex.length < 6) { |
| 8 |
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] |
| 9 |
} |
| 10 |
lum = lum || 0 |
| 11 |
|
| 12 |
// Convert to decimal and change luminosity |
| 13 |
let rgb = '#' |
| 14 |
for (let i = 0; i < 3; i++) { |
| 15 |
let c = parseInt(hex.substr(i * 2, 2), 16) |
| 16 |
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16) |
| 17 |
rgb += ('00' + c).substr(c.length) |
| 18 |
} |
| 19 |
|
| 20 |
return rgb |
| 21 |
} |
| 22 |
|
| 23 |
export const uniqueArray = (arr) => { |
| 24 |
const result = [] |
| 25 |
for (var i in arr) { |
| 26 |
if (result.indexOf(arr[i]) === -1) { |
| 27 |
result.push(arr[i]) |
| 28 |
} |
| 29 |
} |
| 30 |
return result |
| 31 |
} |
| 32 |
|