import { BidiText } from '@/components/foundation/BidiText'; import { classNames } from '@/lib/components/classNames'; import { forwardRef, type InputHTMLAttributes, type SelectHTMLAttributes, type TextareaHTMLAttributes, } from 'react'; import styles from './TextInput.module.css'; export type TextInputType = 'text' | 'email' | 'tel' | 'url' | 'search'; interface TextInputProps extends Omit, 'type'> { type?: TextInputType; invalid?: boolean; describedBy?: string | undefined; bidiValue?: boolean; } export const TextInput = forwardRef(function TextInput( { type = 'text', invalid = false, describedBy, bidiValue = false, className, ...props }, ref, ) { const dir = bidiValue || type === 'email' || type === 'tel' || type === 'url' ? 'ltr' : undefined; const maxLength = props.maxLength ?? (type === 'email' ? 254 : type === 'tel' ? 20 : undefined); const pattern = props.pattern ?? (type === 'tel' ? '^(?:(?:\\+|00)212|0)\\s?[5-7](?:\\s?\\d){8}$' : undefined); return ( ); }); interface TextAreaProps extends TextareaHTMLAttributes { invalid?: boolean; describedBy?: string | undefined; characterCount?: { current: number; max: number; label: string }; } export function TextArea({ invalid = false, describedBy, characterCount, className, ...props }: TextAreaProps) { const countId = characterCount && props.id ? `${props.id}-count` : undefined; const ids = [describedBy, countId].filter(Boolean).join(' ') || undefined; return (