From 10702e9733277a14c3113f2cd56b1a555095238a Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 13 Sep 2023 16:56:40 -0500 Subject: [PATCH] add useMultiStyleExample --- src/lib/design-system/index.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/design-system/index.tsx b/src/lib/design-system/index.tsx index c35dd317df..dd221d5e29 100644 --- a/src/lib/design-system/index.tsx +++ b/src/lib/design-system/index.tsx @@ -77,6 +77,27 @@ export function useStyles(props: Props & T) { return {styles, props: rest} } +export function useMultiStyle< + O extends Record>[0]>, +>( + styles: O, +): { + [Name in keyof O]: ReturnType +} { + const {theme} = React.useContext(Context) + const breakpoints = useBreakpoints() + + return React.useMemo(() => { + return Object.entries(styles).reduce((acc, [key, style]) => { + acc[key as keyof O] = theme.style( + theme.applyBreakpoints(style, breakpoints.active), + ) + return acc + }, {} as {[Name in keyof O]: ReturnType}) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [styles, breakpoints.current, theme]) +} + export const Box = React.forwardRef>(function BoxThemed( {children, style, ...props}, ref,