1 import type { Instance as Color } from 'tinycolor2';
2 import tinycolor from 'tinycolor2';
4 import isBetween from '@proton/utils/isBetween';
6 import shade from './shade';
7 import tint from './tint';
9 function genMutation(color: Color) {
10 return function (mutation: number) {
11 const clone = color.clone();
13 return mutation > 0 ? tint(clone, mutation) : shade(clone, Math.abs(mutation));
17 function genButtonShades(base: Color, light: boolean) {
18 const hsv = base.toHsv();
22 return [70, 50, 0, -5, -10, -15].map(genMutation(base));
24 return [-70, -50, 0, 10, 20, 30].map(genMutation(base));
28 if (isBetween(hsv.h, 30, 60)) {
30 const tinted = [90, 80, 0].map(genMutation(base));
32 const shaded = [-5, -10, -15].map(genMutation(base)).map((c, i) => {
33 const hsl = c.toHsl();
34 hsl.h = hsl.h - 5 * (i + 1);
35 return tinycolor(hsl);
38 return [...tinted, ...shaded];
40 const shaded = [-80, -70].map(genMutation(base)).map((c) => {
41 const hsl = c.toHsl();
43 return tinycolor(hsl);
46 const tinted = [0, 10, 20, 30].map(genMutation(base));
48 return [...shaded, ...tinted];
53 return [90, 80, 0, -10, -20, -30].map(genMutation(base));
55 return [-80, -70, 0, 10, 20, 30].map(genMutation(base));
59 export default genButtonShades;