import { Center, CenterProps, ComponentWithAs, ResponsiveValue, forwardRef, useBreakpointValue, useColorMode, } from '@chakra-ui/react'; import { useMemo } from 'react'; import { theme } from '../../modules/theme'; import { ColorScheme, DEFAULT_PROPS, Size, Variant } from './types'; type Props = CenterProps & { colorScheme?: ResponsiveValue; size?: ResponsiveValue; variant?: ResponsiveValue; }; export const IconCircle: ComponentWithAs<'div', Props> = forwardRef( ( { colorScheme: responsiveColorScheme = DEFAULT_PROPS.colorScheme, size: responsiveSize = DEFAULT_PROPS.size, // variant = DEFAULT_PROPS.variant, children, ...otherProps }, ref, ) => { const { colorMode } = useColorMode(); const size = useBreakpointValue(responsiveSize as any) ?? responsiveSize; const colorScheme = (useBreakpointValue(responsiveColorScheme as any) ?? responsiveColorScheme) as ColorScheme; const sizes = useMemo((): { inner: CenterProps['w']; outer: CenterProps['w']; icon: CenterProps['fontSize']; } => { if (size === 'sm') { return { inner: theme.sizes['10'], outer: theme.sizes['16'], icon: theme.sizes['8'], }; } if (size === 'md') { return { inner: theme.sizes['14'], outer: theme.sizes['20'], icon: theme.sizes['10'], }; } if (size === 'lg') { return { inner: theme.sizes['18'], outer: theme.sizes['24'], icon: theme.sizes['12'], }; } throw new Error(`Size "${size}" is not valid.`); }, [size]); return (
{children}
); }, );