import { assignInlineVars } from '@vanilla-extract/dynamic'; import clsx from 'clsx'; import type { ChangeEvent, CSSProperties, FocusEvent, FocusEventHandler, ForwardedRef, InputHTMLAttributes, KeyboardEvent, KeyboardEventHandler, ReactNode, } from 'react'; import { forwardRef, useCallback, useState } from 'react'; import { input, inputWrapper, widthVar } from './style.css'; export type InputProps = { disabled?: boolean; width?: CSSProperties['width']; onChange?: (value: string) => void; onBlur?: FocusEventHandler; onKeyDown?: KeyboardEventHandler; noBorder?: boolean; status?: 'error' | 'success' | 'warning' | 'default'; size?: 'default' | 'large' | 'extraLarge'; preFix?: ReactNode; endFix?: ReactNode; type?: HTMLInputElement['type']; inputStyle?: CSSProperties; onEnter?: () => void; } & Omit, 'onChange' | 'size'>; export const Input = forwardRef(function Input( { disabled, width, onChange: propsOnChange, noBorder = false, className, status = 'default', style = {}, inputStyle = {}, size = 'default', onFocus, onBlur, preFix, endFix, onEnter, onKeyDown, ...otherProps }: InputProps, ref: ForwardedRef ) { const [isFocus, setIsFocus] = useState(false); return (
{preFix} ) => { setIsFocus(true); onFocus?.(e); }, [onFocus] )} onBlur={useCallback( (e: FocusEvent) => { setIsFocus(false); onBlur?.(e); }, [onBlur] )} onChange={useCallback( (e: ChangeEvent) => { propsOnChange?.(e.target.value); }, [propsOnChange] )} onKeyDown={useCallback( (e: KeyboardEvent) => { if (e.key === 'Enter') { onEnter?.(); } onKeyDown?.(e); }, [onKeyDown, onEnter] )} {...otherProps} /> {endFix}
); });