import { ComponentWithAs, ResponsiveValue, StyleProps, forwardRef, useBreakpointValue, } from '@chakra-ui/react'; import { SVGAttributes, useId } from 'react'; import { getRandomColor, getUnit, hashCode } from './utils'; type Props = Omit> & { value: string; size: ResponsiveValue; colors?: `#${string}`[]; }; const ELEMENTS = 3; const SIZE = 80; // TODO: Get palette colours from designer. const COLORS: `#${string}`[] = ['#F4E196', '#A6BF91', '#5F9982', '#78576B', '#400428']; const generateColors = (name: string, colors: `#${string}`[]) => { const numFromName = hashCode(name); const range = colors && colors.length; const elementsProperties = Array.from({ length: ELEMENTS }, (_, i) => ({ color: getRandomColor(numFromName + i, colors, range), translateX: getUnit(numFromName * (i + 1), SIZE / 10, 1), translateY: getUnit(numFromName * (i + 1), SIZE / 10, 2), scale: 1.2 + getUnit(numFromName * (i + 1), SIZE / 20, 1) / 10, rotate: getUnit(numFromName * (i + 1), 360, 1), })); return elementsProperties; }; export const AvatarBlur: ComponentWithAs<'svg', Props> = forwardRef( ({ value, size: responsiveSize, colors = COLORS, ...otherProps }, ref) => { const size = useBreakpointValue(responsiveSize as any) ?? responsiveSize; const properties = generateColors(value, colors); const maskID = useId(); return ( ); }, );