import { ReactNode, useId } from 'react'; import { fontSizeLookup, fontSizeMdLookup, fontSizeLgLookup, fontWeightLookup, fontWeightMdLookup, fontWeightLgLookup, gapLookup, gapMdLookup, gapLgLookup, gapXlLookup, fontSizeXlLookup, fontWeightXlLookup, fontSize2xlLookup, fontWeight2xlLookup, colorLookup, } from '../theme'; import { Text } from './Text'; import { getClassName, memo } from '../utils'; import { cn } from '../libs'; import { Responsive } from '../types/ui'; export type Gap = keyof typeof gapLookup; export type Size = keyof typeof fontSizeLookup; export type Weight = keyof typeof fontWeightLookup; export type Color = keyof typeof colorLookup; export interface FormFieldProps { label?: string; labelFontSize?: Size | Responsive; labelFontWeight?: Weight | Responsive; labelColor?: Color; labelClass?: string; gap?: Gap | Responsive; error?: string; errorFontSize?: Size | Responsive; errorFontWeight?: Weight | Responsive; errorColor?: Color | Responsive; className?: string; // Type mismatch in original JSDoc vs Usage? // Original JSDoc said className overrides? No, just passed. // Actually JSDoc said className property but destructured className... hide?: boolean | Responsive; hideLabel?: boolean | Responsive; children: ReactNode | ((id: string) => ReactNode); } const Component = ({ label, labelFontSize, labelFontWeight, labelColor, labelClass, gap = 2, hide, hideLabel, error, errorFontSize = 'xs', errorFontWeight = 'medium', errorColor = 'danger', className, children, }: FormFieldProps) => { const id = useId(); const markup = typeof children === 'function' ? children(id) : children; const g = gap as any; const h = hide as any; const hl = hideLabel as any; const lfs = labelFontSize as any; const lfw = labelFontWeight as any; return (
{label && (
)}
{markup}
{error && (
{error}
)}
); }; export const FormField = memo(Component);