diff --git a/src/components/list-field/Docs.mdx b/src/components/list-field/Docs.mdx index 7a94116..3e58fb3 100644 --- a/src/components/list-field/Docs.mdx +++ b/src/components/list-field/Docs.mdx @@ -110,33 +110,51 @@ import { ListField } from "@form-atoms/field"; ```tsx import { formAtom, fieldAtom } from "form-atoms"; -import { ListField } from "@form-atoms/field"; +import { + AddItemButtonProps, + ListField, + listFieldBuilder, + textField, +} from "@form-atoms/field"; + +const typescriptBenefits = listFieldBuilder((value) => + textField({ name: "ts-benefit", value }), +); -const hobbiesForm = formAtom({ - hobbies: [fieldAtom({ value: "gardening" })], +const form = formAtom({ + benefits: typescriptBenefits(["safe function calls", "it's fast"]), }); // NOTE: the keyFrom prop is not needed as the item/fieldAtom itself is used as the render key default. const Example = () => ( - fieldAtom({ value: "" })} - > - {({ fields, RemoveItemButton }) => ( -
- {/* NOTE: The item is itself a field atom */} - - -
- )} -
+ <> + + ( + + )} + builder={typescriptBenefits} + > + {({ fields, RemoveItemButton }) => ( +
+ + +
+ )} +
+ ); ``` diff --git a/src/components/list-field/ListField.stories.tsx b/src/components/list-field/ListField.stories.tsx index ff408b4..4a8ad48 100644 --- a/src/components/list-field/ListField.stories.tsx +++ b/src/components/list-field/ListField.stories.tsx @@ -78,40 +78,53 @@ export const Primary = formStory({ }, }); +const typescriptBenefits = listFieldBuilder((value) => + textField({ name: "ts-benefit", value }), +); + export const Flat = formStory({ parameters: { docs: { description: { story: - "The array items can be plain field atoms. This is usefull when you want to capture list of primitives, e.g. strings or numbers. Here our hobbies list contains `FieldAtom` items.", + "The array items can be plain field atoms. This is usefull when you want to capture list of primitives, e.g. strings or numbers. Here our list of TypeScript benefits contains `FieldAtom` items.", }, }, }, args: { fields: { - hobbies: [fieldAtom({ value: "gardening" })], + benefits: typescriptBenefits(["safe function calls", "it's fast"]), }, children: ({ form }) => ( - fieldAtom({ value: "" })} - > - {({ fields, RemoveItemButton }) => ( -
- - -
- )} -
+ <> + + ( + + )} + RemoveItemButton={RemoveButton} + builder={typescriptBenefits} + > + {({ fields, RemoveItemButton }) => ( +
+ + +
+ )} +
+ ), }, });