Field
A polymorphic input component supporting multiple types with built-in validation, character limits, and error handling.
import { Field } from '@kaynora/ui' export default function () { return ( <Field label='Full name' /> ) }
The type prop determines the input type. Supported types include text, textarea, number, email, and password.
import { Field } from '@kaynora/ui' export default function () { return ( <div style={{ display: 'flex', flexFlow: 'column', gap: '15px', }}> <Field label='Email' type='email' /> <Field label='Password' type='password' /> <Field label='Age' type='number' /> <Field label='Message' type='textarea' height='8rem' /> </div> ) }
The limit prop sets a maximum character count with a counter displayed in the field.
0/100
import { Field } from '@kaynora/ui' export default function () { return ( <Field label='Bio' type='textarea' limit={100} /> ) }
The errors prop accepts an array of error objects with states and messages that display when conditions are met.
import { Field } from '@kaynora/ui' import { useState } from 'react' export default function () { const [value, setValue] = useState('') return ( <Field label='Username' value={value} onChange={setValue} errors={[ { failState: value.length < 3 && value.length > 0, message: 'Minimum 3 characters required' } ]} /> ) }
<Field />
| Prop | Type | Default |
|---|---|---|
label | | — |
type | | 'text' |
name | | undefined |
limit | | 0 |
resizable | | false |
height | | '6rem' |
width | | '100%' |
errors | | [] |
value | | undefined |
defaultValue | | '' |
onChange | | undefined |
disabled | | false |
internal | | undefined |