From 3324b0549af1d8994e4f3cff80832a9dbd7e03b2 Mon Sep 17 00:00:00 2001 From: Miroslav Petrik Date: Mon, 4 Dec 2023 19:23:31 +0100 Subject: [PATCH] docs(ReviewList): add submittable form --- .../review-list/ReviewList.stories.tsx | 16 ++++++++- src/showcase/review-list/ReviewList.tsx | 36 +++++++++---------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/showcase/review-list/ReviewList.stories.tsx b/src/showcase/review-list/ReviewList.stories.tsx index 622e51d..6027a3c 100644 --- a/src/showcase/review-list/ReviewList.stories.tsx +++ b/src/showcase/review-list/ReviewList.stories.tsx @@ -1,5 +1,19 @@ -export { ReviewList as Primary } from "./ReviewList"; +import { ReviewList, reviewItemBuilder } from "./ReviewList"; +import { formStory, meta } from "../../components/story-form"; export default { title: "showcase/ReviewList", + ...meta, }; + +const fields = { + positives: reviewItemBuilder(["quality materials used", "waterproof"]), + negatives: reviewItemBuilder(["could be lighter"]), +}; + +export const Primary = formStory({ + args: { + fields, + children: ({ form }) => , + }, +}); diff --git a/src/showcase/review-list/ReviewList.tsx b/src/showcase/review-list/ReviewList.tsx index 38c9c72..97075e7 100644 --- a/src/showcase/review-list/ReviewList.tsx +++ b/src/showcase/review-list/ReviewList.tsx @@ -2,11 +2,12 @@ import { AddItemButtonProps, ListField, RemoveItemButtonProps, + type TextField as TTextField, listFieldBuilder, textField, } from "@form-atoms/field"; import { Button, Card, Label } from "flowbite-react"; -import { formAtom } from "form-atoms"; +import { FormAtom } from "form-atoms"; import { HiOutlineMinusCircle, HiOutlinePlusCircle, @@ -15,20 +16,6 @@ import { import { TextField } from "../../components"; -const textFieldBuilder = listFieldBuilder((value) => - textField({ - name: "positive", - value: value, - }), -); - -const fields = { - positives: textFieldBuilder(["quality materials used", "waterproof"]), - negatives: textFieldBuilder(["could be lighter"]), -}; - -const form = formAtom(fields); - const AddButton = ({ add }: AddItemButtonProps) => ( // The div makes it non-full width
@@ -42,7 +29,20 @@ const RemoveButton = ({ remove }: RemoveItemButtonProps) => ( ); -export const ReviewList = () => ( +export const reviewItemBuilder = listFieldBuilder((value) => + textField({ + value: value, + }), +); + +/** + * Generic permits to include this review list in different forms having the positives/negatives fields at minimum. + */ +export const ReviewList = ({ + form, +}: { + form: FormAtom<{ positives: TTextField[]; negatives: TTextField[] }>; +}) => (
@@ -51,7 +51,7 @@ export const ReviewList = () => ( @@ -70,7 +70,7 @@ export const ReviewList = () => (