An open API service indexing awesome lists of open source software.

https://github.com/form-atoms/field

FieldAtoms extended with required state and validated by zod schema.
https://github.com/form-atoms/field

form-atoms form-atoms-field jotai jotai-form react react-form

Last synced: about 2 months ago
JSON representation

FieldAtoms extended with required state and validated by zod schema.

Awesome Lists containing this project

README

          



@form-atoms/field


A `zod`-powered [`fieldAtoms`](https://github.com/form-atoms/form-atoms?tab=readme-ov-file#fieldatom) with pre-configured schemas for type & runtime safety.

```
npm install jotai jotai-effect form-atoms @form-atoms/field zod
```


Bundlephobia


NPM Version


Code coverage

## Features

- [x] **Well-typed fields** required & validated by default
- [x] **Initialized field values**, commonly with `undefined` empty value
- [x] **Optional fields** with schema defaulting to `z.optional()`
- [x] **Conditionally required fields** - the required state can depend on other jotai atoms
- [x] **Generic Single-choice Components** [RadioGroup](https://form-atoms.github.io/field/?path=/docs/components-radiogroup--docs) and [Select](https://form-atoms.github.io/field/?path=/docs/components-select--docs)
- [x] **Generic Multi-choice Components** [CheckboxGroup](https://form-atoms.github.io/field/?path=/docs/components-checkboxgroup--docs) and [MultiSelect](https://form-atoms.github.io/field/?path=/docs/components-multiselect--docs)

### Quick Start

```tsx
import { textField, numberField, stringField, Select } from "@form-atoms/field";
import { fromAtom, useForm, Input } from "form-atoms";
import { z } from "zod";

const personForm = formAtom({
name: textField(),
age: numberField({ schema: (s) => s.min(18) }); // extend the default schema
character: stringField().optional(); // make field optional
});

export const Form = () => {
const { fieldAtoms, submit } = useForm(personForm);

return (



option}
getLabel={(option) => option}
/>

);
};
```

See [Storybook docs](https://form-atoms.github.io/field/) for more.

## Integrations

`@form-atoms/field` comes pre-wired to popular UI libraries:

| 📦Package | 🎨 Storybook | About |
| ---------------------------------------------------- | --------------------------------------------------------- | ---------------------------------------------- |
| [flowbite](https://github.com/form-atoms/flowbite) | [Flowbite Fields](https://form-atoms.github.io/flowbite/) | Bindigs to Tailwind component library Flowbite |
| [chakra-ui](https://github.com/form-atoms/chakra-ui) | [ChakraUI Fields](https://form-atoms.github.io/chakra-ui) | Bindings to CSS-in-JS library Chakra UI |