Forms
Form controls: input, password input with a show and hide button, textarea, custom select, multi select with chips, checkbox, radio group and switch, with validation messages.
How to use it
Run npx @blossomui/react add forms, or copy src/components/UI/Forms/Forms.tsx into your React project and import it.
import { Input, PasswordInput, Textarea, Select, MultiSelect, Checkbox, Radio, RadioGroup, Switch } from './components/ui/Forms'
Props
FieldProps
| Prop | Type | Description |
|---|
| required | boolean | Marks the field as required: an asterisk is shown next to the label. |
| color | string | Accent color of this field: any CSS color. Without it the field uses `--blossom-accent`, which is pink by default. |
| label | string | |
| hint | string | Helper text shown under the field. |
| error | string | Error message. Turns the field red. |
| success | string | Success message. Turns the field green. |
InputProps
| Prop | Type | Description |
|---|
| icon | ReactNode | Icon shown inside the field, on the left. |
| action | ReactNode | Content shown inside the field, on the right, for example a small button. |
PasswordInputProps
| Prop | Type | Description |
|---|
| showLabel | string | Accessible name of the button while the password is hidden. |
| hideLabel | string | Accessible name of the button while the password is visible. |
SelectOption
| Prop | Type | Description |
|---|
| value (required) | string | |
| label (required) | string | |
| disabled | boolean | |
| image | string | Image shown before the label, for example a flag. It is decorative: the label names the option. |
SelectProps
| Prop | Type | Description |
|---|
| options (required) | SelectOption[] | |
| value | string | Controlled value. Use together with `onChange`. |
| defaultValue | string | Initial value when the select is uncontrolled. |
| onChange | (value: string) => void | |
| placeholder | string | |
| name | string | Adds a hidden input with this name so the value is sent with native forms. |
| disabled | boolean | |
| className | string | |
MultiSelectProps
| Prop | Type | Description |
|---|
| noResultsLabel | string | Text shown when the search does not match any option. |
| options (required) | SelectOption[] | |
| value | string[] | Controlled list of selected values. Use together with `onChange`. |
| defaultValue | string[] | |
| onChange | (value: string[]) => void | |
| placeholder | string | |
| name | string | Adds one hidden input per selected value so they are sent with native forms. |
| max | number | Maximum number of values that can be selected. |
| disabled | boolean | |
| className | string | |
CheckboxProps
| Prop | Type | Description |
|---|
| label (required) | string | |
| description | string | Smaller text under the label. |
| indeterminate | boolean | Shows a dash instead of the check, for "some selected" states. |
| error | string | Error message. It is shown in red under the label and marks the checkbox as invalid. |
RadioProps
| Prop | Type | Description |
|---|
| label (required) | string | |
| description | string | |
RadioGroupOption
| Prop | Type | Description |
|---|
| value (required) | string | |
| label (required) | string | |
| description | string | |
| disabled | boolean | |
RadioGroupProps
| Prop | Type | Description |
|---|
| name (required) | string | |
| options (required) | RadioGroupOption[] | |
| value | string | |
| defaultValue | string | |
| onChange | (value: string) => void | |
| direction | 'vertical' | 'horizontal' | |
SwitchProps
| Prop | Type | Description |
|---|
| label (required) | string | |