1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed lab color gradients calculation

This commit is contained in:
Fedor Katurov 2021-10-08 11:16:20 +07:00
parent a09c129d04
commit 17e3f211ef
2 changed files with 5 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import { DEFAULT_DOMINANT_COLOR } from '~/constants/node';
export const normalizeBrightColor = (color?: string, saturationExp = 3, lightnessExp = 3) => {
if (!color) {
return undefined;
return '';
}
const hsla = parseToHsla(color || DEFAULT_DOMINANT_COLOR);

View file

@ -1,18 +1,17 @@
import { useMemo } from 'react';
import { adjustHue } from 'color2k';
import { useColorFromString } from '~/utils/hooks/useColorFromString';
import { normalizeBrightColor } from '~/utils/color';
import { stringToColour } from '~/utils/dom';
export const useColorGradientFromString = (val?: string, saturation = 3, lightness = 3) => {
return useMemo(() => {
export const useColorGradientFromString = (val?: string, saturation = 3, lightness = 3) =>
useMemo(() => {
if (!val) {
return '';
}
const color = useColorFromString(val, saturation, lightness);
const color = normalizeBrightColor(stringToColour(val), saturation, lightness);
const second = normalizeBrightColor(adjustHue(color, 45), saturation, lightness);
const third = normalizeBrightColor(adjustHue(color, 90), saturation, lightness);
return `linear-gradient(155deg, ${color}, ${second}, ${third})`;
}, [val]);
};