Files
FastUI/react/fastui/components/FormField.tsx
Samuel Colvin eb6147512c moving python
2023-11-12 20:15:23 +00:00

34 lines
892 B
TypeScript

import { FC, useState } from 'react'
import { ClassName, useClassNameGenerator } from '../hooks/className'
export interface FormFieldProps {
type: 'FormField'
className?: ClassName
labelClassName?: ClassName
inputClassName?: ClassName
label: string
initialValue?: string
placeholder?: string
id?: string
name?: string
htmlType?: 'text' | 'password' | 'email' | 'url'
}
export const FormFieldComp: FC<FormFieldProps> = (props) => {
const [value, setValue] = useState(props.initialValue ?? '')
return (
<div className={useClassNameGenerator(props.className, props)}>
<label htmlFor={props.name}>{props.label}</label>
<input
type={props.htmlType ?? 'text'}
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder={props.placeholder}
id={props.id}
name={props.name}
/>
</div>
)
}