diff --git a/src/components/list-field/Docs.mdx b/src/components/list-field/Docs.mdx index 095727d..7a94116 100644 --- a/src/components/list-field/Docs.mdx +++ b/src/components/list-field/Docs.mdx @@ -22,27 +22,32 @@ import { ListField } from "@form-atoms/field"; ```tsx -import { formAtom, fieldAtom } from "form-atoms"; -import { ListField } from "@form-atoms/field"; +import { formAtom } from "form-atoms"; +import { ListField, textField, listFieldBuilder } from "@form-atoms/field"; + +// listFieldBulder creates a builder which helps initialize form fields for you +// the callback item shape is based on the callback form fields returned from it! +const envVarsBuilder = listFieldBuilder((item: { variable; value }) => ({ + variable: textField({ name: "variable", value: variable }), + value: textField({ name: "value", value: value }), + // Uncommenting the following line will make item.owner property available! + // owner: textField({ name: "owner" }), +})); const envForm = formAtom({ - envVars: [ - { - name: fieldAtom({ value: "API_KEY" }), - value: fieldAtom({ value: "ff52d09a" }), - }, - ], + // call the builder with your data, when initializing the form + envVars: envVarsBuilder([ + { variable: "GITHUB_TOKEN", value: "ff52d09a" }, + { variable: "NPM_TOKEN", value: "deepsecret" }, + ]), }); const Example = () => ( ({ - name: fieldAtom({ value: "" }), - value: fieldAtom({ value: "" }), - })} + keyFrom="variable" + builder={envVarsBuilder} AddItemButton={({ add }) => (