import React, { useMemo } from 'react' import useTheme from '../use-theme' import { NormalTypes } from '../utils/prop-types' import { GeistUIThemes } from '../themes/presets' import useScaleable, { withScaleable } from '../use-scaleable' export type NoteTypes = NormalTypes interface Props { type?: NoteTypes label?: string | boolean filled?: boolean className?: string } const defaultProps = { type: 'default' as NoteTypes, label: 'note' as string | boolean, filled: false, className: '', } type NativeAttrs = Omit, keyof Props> export type NoteProps = Props & NativeAttrs const getStatusColor = (type: NoteTypes, filled: boolean, theme: GeistUIThemes) => { const colors: { [key in NoteTypes]?: string } = { secondary: theme.palette.secondary, success: theme.palette.success, warning: theme.palette.warning, error: theme.palette.error, } const statusColor = colors[type] if (!filled) return { color: statusColor || theme.palette.foreground, borderColor: statusColor || theme.palette.border, bgColor: theme.palette.background, } const filledColor = statusColor ? 'white' : theme.palette.background return { color: filledColor, borderColor: statusColor || theme.palette.foreground, bgColor: statusColor || theme.palette.foreground, } } export const NoteComponent: React.FC> = ({ children, type, label, filled, className, ...props }: React.PropsWithChildren & typeof defaultProps) => { const theme = useTheme() const { SCALES } = useScaleable() const { color, borderColor, bgColor } = useMemo( () => getStatusColor(type, filled, theme), [type, filled, theme], ) return (
{label && ( {label}: )} {children}
) } NoteComponent.defaultProps = defaultProps NoteComponent.displayName = 'GeistNote' const Note = withScaleable(NoteComponent) export default Note