From 537641a9e61289036bc7aa23a22d535836455dbf Mon Sep 17 00:00:00 2001 From: Miroslav Petrik Date: Thu, 14 Mar 2024 08:07:12 +0100 Subject: [PATCH] docs: Migrate List usage --- .../list-field/NestedListField.stories.tsx | 17 ++++++++------ src/components/list-field/Phones.stories.tsx | 7 +++--- .../review-list/ReviewList.stories.tsx | 8 +++---- src/stories/review-list/ReviewList.tsx | 22 ++++++++++--------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/components/list-field/NestedListField.stories.tsx b/src/components/list-field/NestedListField.stories.tsx index 73aee3b..f737702 100644 --- a/src/components/list-field/NestedListField.stories.tsx +++ b/src/components/list-field/NestedListField.stories.tsx @@ -1,4 +1,5 @@ -import { List, listField, numberField, textField } from "@form-atoms/field"; +import { listField, numberField, textField } from "@form-atoms/field"; +import { List } from "@form-atoms/list-atom"; import { Button, Card } from "flowbite-react"; import { formStory, meta } from "../../stories/story-form"; @@ -11,6 +12,7 @@ export default { }; const addresses = listField({ + name: "address", value: [ { city: "Bratislava", @@ -23,7 +25,7 @@ const addresses = listField({ ], }, ], - builder: ({ city, street, people = [] }) => ({ + fields: ({ city, street, people = [] }) => ({ city: textField({ name: "city", value: city, @@ -33,8 +35,9 @@ const addresses = listField({ value: street, }), people: listField({ + name: "people", value: people, - builder: ({ name, age }) => ({ + fields: ({ name, age }) => ({ name: textField({ name: "name", value: name, @@ -53,9 +56,9 @@ export const AddressesWithPeopleListField = formStory({ fields: { addresses }, children: ({ fields }) => ( ( - )} @@ -67,9 +70,9 @@ export const AddressesWithPeopleListField = formStory({ ( - )} diff --git a/src/components/list-field/Phones.stories.tsx b/src/components/list-field/Phones.stories.tsx index 8fc793d..4204a4c 100644 --- a/src/components/list-field/Phones.stories.tsx +++ b/src/components/list-field/Phones.stories.tsx @@ -1,11 +1,11 @@ import { - List, Radio, RadioControl, checkboxField, listField, textField, } from "@form-atoms/field"; +import { List } from "@form-atoms/list-atom"; import { Card } from "flowbite-react"; import { formStory, meta } from "../../stories/story-form"; @@ -18,11 +18,12 @@ export default { }; const phones = listField({ + name: "phones", value: [ { number: "+421 933 888 999", primary: true }, { number: "+420 905 100 200", primary: false }, ], - builder: ({ number, primary }) => ({ + fields: ({ number, primary }) => ({ number: textField({ name: "number", value: number }), primary: checkboxField({ name: "primaryPhone", @@ -37,7 +38,7 @@ export const PhonesListField = formStory({ children: ({ required, fields }) => ( {({ control }) => ( - + {({ fields }) => ( textField({ value }), + value: [{ item: "quality materials used" }, { item: "waterproof" }], + fields: ({ item }) => ({ item: textField({ value: item }) }), }), negatives: listField({ - value: ["could be lighter"], - builder: (value) => textField({ value }), + value: [{ item: "could be lighter" }], + fields: ({ item }) => ({ item: textField({ value: item }) }), }), }; diff --git a/src/stories/review-list/ReviewList.tsx b/src/stories/review-list/ReviewList.tsx index 3e9014c..570324f 100644 --- a/src/stories/review-list/ReviewList.tsx +++ b/src/stories/review-list/ReviewList.tsx @@ -1,10 +1,12 @@ import { - AddButtonProps, - List, type ListField, - RemoveButtonProps, type TextField as TTextField, } from "@form-atoms/field"; +import { + type AddButtonProps, + List, + type RemoveButtonProps, +} from "@form-atoms/list-atom"; import { Button, Card, Label } from "flowbite-react"; import { HiOutlineMinusCircle, @@ -14,7 +16,7 @@ import { import { TextField } from "../../components"; -const AddButton = ({ add }: AddButtonProps) => ( +const AddButton = ({ add }: AddButtonProps) => ( // The div makes it non-full width
@@ -34,8 +36,8 @@ export const ReviewList = ({ fields, }: { fields: { - positives: ListField; - negatives: ListField; + positives: ListField<{ item: TTextField }, { item: string }>; + negatives: ListField<{ item: TTextField }, { item: string }>; }; }) => ( @@ -44,7 +46,7 @@ export const ReviewList = ({
@@ -52,7 +54,7 @@ export const ReviewList = ({
- +
)} @@ -61,7 +63,7 @@ export const ReviewList = ({
@@ -69,7 +71,7 @@ export const ReviewList = ({
- +
)}