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:
parent
a09c129d04
commit
17e3f211ef
2 changed files with 5 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue