import { ComponentPropsWithRef, ForwardedRef, MouseEventHandler, ReactNode, RefObject, useCallback, } from 'react'; import { buildTypographyOverrides, mapResponsiveSizeToTypography, type Responsive, } from '../../styles'; import { InputAppearanceVariants, inputWrapper } from './input.css'; import { inputAppearanceResponsive } from './input.responsive'; export type InputWrapperProps = ComponentPropsWithRef<'div'> & { children: ReactNode; className?: string; inputRef: RefObject; disabled?: boolean; } & Omit & { size?: Responsive>; }; export function InputWrapper({ children, className, inputRef, disabled, variant = 'outlined', size = 'md', tone, ref, }: InputWrapperProps) { const typographySize = mapResponsiveSizeToTypography(size); const typographyOverrides = buildTypographyOverrides({ variant: 'body', size: typographySize, }); const handleInputFocus = useCallback>( (e) => { if (disabled || !inputRef?.current || e.target === inputRef.current) { return; } inputRef.current.click(); inputRef.current.focus(); }, [inputRef, disabled], ); return (
} className={inputAppearanceResponsive( { variant, size, tone }, typographyOverrides, inputWrapper, className, )} onClick={handleInputFocus} > {children}
); }