mirror of
https://github.com/samuelcolvin/FastUI.git
synced 2023-12-01 22:22:11 +03:00
34 lines
892 B
TypeScript
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>
|
|
)
|
|
}
|