import React, { useMemo } from 'react' import withDefaults from 'components/utils/with-defaults' import useTheme from 'components/use-theme' import { GeistUIThemes } from 'components/themes/presets' interface Props { plain?: number | boolean } const defaultProps = { plain: false, } export type ExampleBlockProps = Props & typeof defaultProps const getBackground = (theme: GeistUIThemes, plain: number | boolean) => { if (typeof plain !== 'number') return theme.palette.success const colors = [ theme.palette.accents_1, theme.palette.accents_2, theme.palette.accents_3, theme.palette.accents_4, theme.palette.accents_5, theme.palette.accents_6, ] return colors[plain - 1] || theme.palette.success } const ExampleBlock: React.FC> = React.memo( ({ plain, children, ...props }) => { const theme = useTheme() const bg = useMemo(() => getBackground(theme, plain), [theme, plain]) return (
{children}
) }, ) export default withDefaults(ExampleBlock, defaultProps)