import { c, classy, InputProps as BaseProps, m } from '@onfido/castor'; import { useField } from '@onfido/castor-react'; import React, { useMemo } from 'react'; import { withRef } from '../../utils'; export const Input = withRef(function Input( { id: initialId, // Optional id passed in type = 'text', invalid, className, ...restProps }: InputProps, ref: InputProps['ref'] ) { const { disabled, touched } = useField(); // Generate unique id only if `initialId` is not provided const id = useMemo( () => initialId || `castor_input_${++idCount}`, [initialId] ); return ( ); }); export type InputProps = BaseProps & Omit & { id?: string; // id is now optional }; type InputElementProps = JSX.IntrinsicElements['input']; let idCount = 0;