|
|
@ -62,6 +62,7 @@ type EndAddOnProps =
|
|
|
|
|
|
|
|
|
|
|
|
type BaseProps = Readonly<{
|
|
|
|
type BaseProps = Readonly<{
|
|
|
|
defaultValue?: string;
|
|
|
|
defaultValue?: string;
|
|
|
|
|
|
|
|
description?: React.ReactNode;
|
|
|
|
endIcon?: React.ComponentType<React.ComponentProps<'svg'>>;
|
|
|
|
endIcon?: React.ComponentType<React.ComponentProps<'svg'>>;
|
|
|
|
errorMessage?: React.ReactNode;
|
|
|
|
errorMessage?: React.ReactNode;
|
|
|
|
id?: string;
|
|
|
|
id?: string;
|
|
|
@ -99,6 +100,7 @@ const stateClasses: Record<
|
|
|
|
function TextInput(
|
|
|
|
function TextInput(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
defaultValue,
|
|
|
|
defaultValue,
|
|
|
|
|
|
|
|
description,
|
|
|
|
disabled,
|
|
|
|
disabled,
|
|
|
|
endAddOn,
|
|
|
|
endAddOn,
|
|
|
|
endAddOnType,
|
|
|
|
endAddOnType,
|
|
|
@ -119,7 +121,7 @@ function TextInput(
|
|
|
|
const hasError = errorMessage != null;
|
|
|
|
const hasError = errorMessage != null;
|
|
|
|
const generatedId = useId();
|
|
|
|
const generatedId = useId();
|
|
|
|
const id = idParam ?? generatedId;
|
|
|
|
const id = idParam ?? generatedId;
|
|
|
|
const errorId = useId();
|
|
|
|
const messageId = useId();
|
|
|
|
const state: State = hasError ? 'error' : 'normal';
|
|
|
|
const state: State = hasError ? 'error' : 'normal';
|
|
|
|
const { input: inputClass, container: containerClass } = stateClasses[state];
|
|
|
|
const { input: inputClass, container: containerClass } = stateClasses[state];
|
|
|
|
|
|
|
|
|
|
|
@ -175,7 +177,9 @@ function TextInput(
|
|
|
|
})()}
|
|
|
|
})()}
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
ref={ref}
|
|
|
|
ref={ref}
|
|
|
|
aria-describedby={hasError ? errorId : undefined}
|
|
|
|
aria-describedby={
|
|
|
|
|
|
|
|
hasError || description != null ? messageId : undefined
|
|
|
|
|
|
|
|
}
|
|
|
|
aria-invalid={hasError ? true : undefined}
|
|
|
|
aria-invalid={hasError ? true : undefined}
|
|
|
|
className={clsx(
|
|
|
|
className={clsx(
|
|
|
|
'w-0 flex-1 border-none text-sm focus:outline-none focus:ring-0 disabled:cursor-not-allowed disabled:bg-transparent disabled:text-slate-500',
|
|
|
|
'w-0 flex-1 border-none text-sm focus:outline-none focus:ring-0 disabled:cursor-not-allowed disabled:bg-transparent disabled:text-slate-500',
|
|
|
@ -224,9 +228,14 @@ function TextInput(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})()}
|
|
|
|
})()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{errorMessage && (
|
|
|
|
{(errorMessage ?? description) && (
|
|
|
|
<p className="text-danger-600 mt-2 text-sm" id={errorId}>
|
|
|
|
<p
|
|
|
|
{errorMessage}
|
|
|
|
className={clsx(
|
|
|
|
|
|
|
|
'mt-2 text-sm',
|
|
|
|
|
|
|
|
errorMessage ? 'text-danger-600' : 'text-slate-500',
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
id={messageId}>
|
|
|
|
|
|
|
|
{errorMessage ?? description}
|
|
|
|
</p>
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|