Skip to content

Commit

Permalink
fix(ListField): label
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavPetrik committed Dec 4, 2023
1 parent e7fae7c commit c77fdd0
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@emotion/react": "^11.11.1",
"@form-atoms/field": "^3.8.4",
"@form-atoms/field": "^3.8.7",
"@mdx-js/react": "^2.3.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/list-field/ListField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const AddressesListField = formStory({
fields,
children: ({ form }) => (
<ListField
form={form}
keyFrom="city"
path={["addresses"]}
form={form}
builder={addressBuilder}
>
{({ fields }) => (
Expand Down
4 changes: 2 additions & 2 deletions src/components/list-field/NestedListField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export const AddressesWithPeopleListField = formStory({
fields,
children: ({ form }) => (
<ListField
form={form}
keyFrom="street"
path={["addresses"]}
form={form}
builder={addressBuilder}
AddItemButton={({ add }) => (
<Button color="gray" onClick={add}>
Expand All @@ -75,10 +75,10 @@ export const AddressesWithPeopleListField = formStory({
<TextField label="Street" field={fields.street} />
</div>
<ListField
form={form}
keyFrom="name"
path={["addresses", index, "people"]}
builder={personBuilder}
form={form}
AddItemButton={({ add }) => (
<Button color="gray" onClick={add}>
Add Person
Expand Down
2 changes: 1 addition & 1 deletion src/components/list-field/Phones.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const PhonesListField = formStory({
<RadioControl name="primaryPhone">
{({ control }) => (
<ListField
keyFrom="primary"
form={form}
keyFrom="primary"
path={["phones"]}
builder={phoneBuilder}
>
Expand Down
5 changes: 1 addition & 4 deletions src/showcase/address-list-field/AddressListField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const AddressesListField = () => (
<div className="flex flex-col gap-4">
<ListField
keyFrom="city"
label="Adjust your addresses, the first one will be primary."
path={["addresses"]}
form={form}
builder={addressBuilder}
Expand All @@ -50,9 +49,7 @@ export const AddressesListField = () => (
<HiOutlineTrash />
</Button>
)}
AddItemButton={({ add }) => (
<Button onClick={add}>Pridaj address</Button>
)}
AddItemButton={({ add }) => <Button onClick={add}>Add address</Button>}
>
{({ fields, RemoveItemButton, index, moveUp, moveDown }) => (
<Card>
Expand Down
5 changes: 5 additions & 0 deletions src/showcase/review-list/ReviewList.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { ReviewList as Primary } from "./ReviewList";

export default {
title: "showcase/ReviewList",
};
89 changes: 89 additions & 0 deletions src/showcase/review-list/ReviewList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
AddItemButtonProps,
ListField,
RemoveItemButtonProps,
listFieldBuilder,
textField,
} from "@form-atoms/field";
import { Button, Card, Label } from "flowbite-react";
import { formAtom } from "form-atoms";
import {
HiOutlineMinusCircle,
HiOutlinePlusCircle,
HiOutlineTrash,
} from "react-icons/hi2";

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>
<Button onClick={add}>Add</Button>
</div>
);

const RemoveButton = ({ remove }: RemoveItemButtonProps) => (
<Button onClick={remove} color="light">
<HiOutlineTrash />
</Button>
);

export const ReviewList = () => (
<Card>
<Label>Please review your shoes:</Label>
<div className="flex gap-4">
<div className="flex flex-1 flex-col gap-4">
<Label>Positives</Label>
<ListField
form={form}
path={["positives"]}
builder={textFieldBuilder}
RemoveItemButton={RemoveButton}
AddItemButton={AddButton}
>
{({ fields, RemoveItemButton }) => (
<div className="flex items-center gap-2">
<RemoveItemButton />
<div className="w-full">
<TextField icon={HiOutlinePlusCircle} field={fields} />
</div>
</div>
)}
</ListField>
</div>
<div className="flex flex-1 flex-col gap-4">
<Label>Negatives</Label>
<ListField
form={form}
path={["negatives"]}
builder={textFieldBuilder}
RemoveItemButton={RemoveButton}
AddItemButton={AddButton}
>
{({ fields, RemoveItemButton }) => (
<div className="flex w-full items-center gap-2">
<RemoveItemButton />
<div className="w-full">
<TextField icon={HiOutlineMinusCircle} field={fields} />
</div>
</div>
)}
</ListField>
</div>
</div>
</Card>
);
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2706,9 +2706,9 @@ __metadata:
languageName: node
linkType: hard

"@form-atoms/field@npm:^3.8.4":
version: 3.8.4
resolution: "@form-atoms/field@npm:3.8.4"
"@form-atoms/field@npm:^3.8.7":
version: 3.8.7
resolution: "@form-atoms/field@npm:3.8.7"
dependencies:
react-render-prop-type: "npm:0.1.0"
peerDependencies:
Expand All @@ -2717,7 +2717,7 @@ __metadata:
jotai-effect: ^0
react: ">=16.8"
zod: ^3
checksum: bf4f0f9d6864a7f85a0fd320613455f196a5b75d3be132523833e2894c1faa18b800bf444163bbd4b7fdeec2fab324e2e52d90bac8ea2fce5d744fec13c92b85
checksum: baeca497ce2cc146180f2f53d2aede5e95038fc3b5d422a6939752573c7030db873c4de45ed156c9c64df2b9b6cf38f1c86cfb3ee9fbb675750cd1cd82cb3f38
languageName: node
linkType: hard

Expand All @@ -2726,7 +2726,7 @@ __metadata:
resolution: "@form-atoms/flowbite@workspace:."
dependencies:
"@emotion/react": "npm:^11.11.1"
"@form-atoms/field": "npm:^3.8.4"
"@form-atoms/field": "npm:^3.8.7"
"@mdx-js/react": "npm:^2.3.0"
"@semantic-release/changelog": "npm:^6.0.3"
"@semantic-release/commit-analyzer": "npm:^11.1.0"
Expand Down

0 comments on commit c77fdd0

Please sign in to comment.