diff --git a/apps/storybook/stories/text-input.stories.tsx b/apps/storybook/stories/text-input.stories.tsx index d607ddce..c99ff409 100644 --- a/apps/storybook/stories/text-input.stories.tsx +++ b/apps/storybook/stories/text-input.stories.tsx @@ -14,12 +14,12 @@ export default { autoComplete: { control: 'text', }, + disabled: { + control: 'boolean', + }, errorMessage: { control: 'text', }, - isDisabled: { - control: 'boolean', - }, isLabelHidden: { control: 'boolean', }, @@ -103,7 +103,7 @@ export function Icon() { export function Disabled() { return ( , + | 'autoComplete' + | 'disabled' + | 'max' + | 'maxLength' + | 'min' + | 'minLength' + | 'name' + | 'pattern' + | 'placeholder' + | 'required' + | 'type' +>; + +type TextInputDOMAttributes = Pick< + InputHTMLAttributes, + 'onBlur' | 'onFocus' +>; type Props = Readonly<{ - autoComplete?: string; defaultValue?: string; endIcon?: React.ComponentType>; errorMessage?: React.ReactNode; id?: string; - isDisabled?: boolean; isLabelHidden?: boolean; label: string; - name?: string; + onBlur?: (event: FocusEvent) => void; onChange?: (value: string, event: ChangeEvent) => void; - placeholder?: string; startIcon?: React.ComponentType>; - type?: 'email' | 'password' | 'text'; value?: string; -}>; +}> & + Readonly & + Readonly; type State = 'error' | 'normal'; @@ -28,22 +51,23 @@ const stateClasses: Record = { 'placeholder:text-slate-400 focus:ring-primary-500 focus:border-primary-500 border-slate-300', }; -export default function TextInput({ - autoComplete, - defaultValue, - endIcon: EndIcon, - errorMessage, - id: idParam, - isDisabled, - isLabelHidden = false, - label, - name, - placeholder, - startIcon: StartIcon, - type = 'text', - value, - onChange, -}: Props) { +function TextInput( + { + defaultValue, + disabled, + endIcon: EndIcon, + errorMessage, + id: idParam, + isLabelHidden = false, + label, + startIcon: StartIcon, + type = 'text', + value, + onChange, + ...props + }: Props, + ref: ForwardedRef, +) { const hasError = errorMessage != null; const generatedId = useId(); const id = idParam ?? generatedId; @@ -68,21 +92,19 @@ export default function TextInput({ )} { @@ -92,6 +114,7 @@ export default function TextInput({ onChange(event.target.value, event); }} + {...props} /> {EndIcon && (
@@ -107,3 +130,5 @@ export default function TextInput({
); } + +export default forwardRef(TextInput);