mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
refactored hooks directory
This commit is contained in:
parent
efa3ba902d
commit
f76a5a4798
106 changed files with 122 additions and 144 deletions
10
src/hooks/color/useColorFromString.ts
Normal file
10
src/hooks/color/useColorFromString.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { useMemo } from 'react';
|
||||
import { normalizeBrightColor } from '~/utils/color';
|
||||
import { stringToColour } from '~/utils/dom';
|
||||
|
||||
export const useColorFromString = (val?: string, saturation = 3, lightness = 3) => {
|
||||
return useMemo(
|
||||
() => (val && normalizeBrightColor(stringToColour(val), saturation, lightness)) || '',
|
||||
[lightness, saturation, val]
|
||||
);
|
||||
};
|
22
src/hooks/color/useColorGradientFromString.ts
Normal file
22
src/hooks/color/useColorGradientFromString.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { useMemo } from 'react';
|
||||
import { adjustHue } from 'color2k';
|
||||
import { normalizeBrightColor } from '~/utils/color';
|
||||
import { stringToColour } from '~/utils/dom';
|
||||
|
||||
export const useColorGradientFromString = (
|
||||
val?: string,
|
||||
saturation = 3,
|
||||
lightness = 3,
|
||||
angle = 155
|
||||
) =>
|
||||
useMemo(() => {
|
||||
if (!val) {
|
||||
return '';
|
||||
}
|
||||
|
||||
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(${angle}deg, ${color}, ${second}, ${third})`;
|
||||
}, [angle, lightness, saturation, val]);
|
Loading…
Add table
Add a link
Reference in a new issue