Skip to content

Commit

Permalink
docs(ReviewList): add submittable form
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavPetrik committed Dec 4, 2023
1 parent c77fdd0 commit 3324b05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
16 changes: 15 additions & 1 deletion src/showcase/review-list/ReviewList.stories.tsx
Original file line number Diff line number Diff line change
@@ -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 }) => <ReviewList form={form} />,
},
});
36 changes: 18 additions & 18 deletions src/showcase/review-list/ReviewList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
<div>
Expand All @@ -42,7 +29,20 @@ const RemoveButton = ({ remove }: RemoveItemButtonProps) => (
</Button>
);

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[] }>;
}) => (
<Card>
<Label>Please review your shoes:</Label>
<div className="flex gap-4">
Expand All @@ -51,7 +51,7 @@ export const ReviewList = () => (
<ListField
form={form}
path={["positives"]}
builder={textFieldBuilder}
builder={reviewItemBuilder}
RemoveItemButton={RemoveButton}
AddItemButton={AddButton}
>
Expand All @@ -70,7 +70,7 @@ export const ReviewList = () => (
<ListField
form={form}
path={["negatives"]}
builder={textFieldBuilder}
builder={reviewItemBuilder}
RemoveItemButton={RemoveButton}
AddItemButton={AddButton}
>
Expand Down

0 comments on commit 3324b05

Please sign in to comment.