headplane/app/components/TextField.tsx

31 lines
882 B
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import type { Dispatch, SetStateAction } from 'react';
2024-12-31 10:30:14 +05:30
import { Input, TextField as AriaTextField } from 'react-aria-components';
import { cn } from '~/utils/cn';
2024-12-31 10:30:14 +05:30
type TextFieldProps = Parameters<typeof AriaTextField>[0] & {
readonly label: string;
readonly placeholder: string;
readonly state?: [string, Dispatch<SetStateAction<string>>];
2024-12-31 10:30:14 +05:30
};
2024-12-31 10:30:14 +05:30
export default function TextField(props: TextFieldProps) {
return (
2024-12-31 10:30:14 +05:30
<AriaTextField {...props} aria-label={props.label} className="w-full">
<Input
2024-12-31 10:30:14 +05:30
placeholder={props.placeholder}
value={props.state?.[0]}
name={props.name}
className={cn(
'block px-2.5 py-1.5 w-full rounded-lg my-1',
'border border-ui-200 dark:border-ui-600',
'dark:bg-ui-800 dark:text-ui-300',
2024-12-31 10:30:14 +05:30
props.className,
)}
2024-12-31 10:30:14 +05:30
onChange={(event) => {
props.state?.[1](event.target.value);
}}
/>
</AriaTextField>
2024-12-31 10:30:14 +05:30
);
}