|
| 1 | +import { AppProvider, Card, Page, Text } from "@shopify/polaris"; |
| 2 | +import translations from "@shopify/polaris/locales/en.json"; |
| 3 | +import React from "react"; |
| 4 | +import { Provider } from "../../../src/GadgetProvider.tsx"; |
| 5 | +import { PolarisAutoForm } from "../../../src/auto/polaris/PolarisAutoForm.tsx"; |
| 6 | +import { PolarisAutoInput } from "../../../src/auto/polaris/inputs/PolarisAutoInput.tsx"; |
| 7 | +import { PolarisAutoBelongsToInput } from "../../../src/auto/polaris/inputs/relationships/PolarisAutoBelongsToInput.tsx"; |
| 8 | +import { PolarisAutoRelationshipForm } from "../../../src/auto/polaris/inputs/relationships/PolarisAutoRelationshipForm.tsx"; |
| 9 | +import { PolarisAutoSubmit } from "../../../src/auto/polaris/submit/PolarisAutoSubmit.tsx"; |
| 10 | +import { FormProvider, useForm } from "../../../src/useActionForm.ts"; |
| 11 | +import { testApi as api } from "../../apis.ts"; |
| 12 | + |
| 13 | +const ExampleAutoRelatedForm = (props) => { |
| 14 | + return ( |
| 15 | + <Page> |
| 16 | + <PolarisAutoForm {...props}> |
| 17 | + <Card> |
| 18 | + <Text as="h2" variant="headingSm"> |
| 19 | + Top Level Form -- Widget |
| 20 | + </Text> |
| 21 | + <PolarisAutoInput field="name" /> |
| 22 | + <PolarisAutoInput field="description" /> |
| 23 | + <PolarisAutoInput field="inventoryCount" /> |
| 24 | + </Card> |
| 25 | + |
| 26 | + <Card> |
| 27 | + <Text as="h2" variant="headingSm"> |
| 28 | + Belongs To Form -- Section |
| 29 | + </Text> |
| 30 | + <PolarisAutoBelongsToInput field="section" optionLabel="id" /> |
| 31 | + </Card> |
| 32 | + |
| 33 | + <Card> |
| 34 | + <Text as="h2" variant="headingSm"> |
| 35 | + Has Many Form -- Gizmos |
| 36 | + </Text> |
| 37 | + <PolarisAutoRelationshipForm |
| 38 | + field="gizmos" |
| 39 | + selectPaths={["name", "orientation"]} |
| 40 | + primaryLabel="name" |
| 41 | + secondaryLabel="orientation" |
| 42 | + > |
| 43 | + <PolarisAutoInput field="name" /> |
| 44 | + <PolarisAutoInput field="orientation" /> |
| 45 | + <PolarisAutoInput field="attachment" /> |
| 46 | + </PolarisAutoRelationshipForm> |
| 47 | + </Card> |
| 48 | + <PolarisAutoSubmit /> |
| 49 | + </PolarisAutoForm> |
| 50 | + </Page> |
| 51 | + ); |
| 52 | +}; |
| 53 | + |
| 54 | +export default { |
| 55 | + title: "Polaris/AutoForm/AutoRelationshipForm", |
| 56 | + component: ExampleAutoRelatedForm, |
| 57 | + decorators: [ |
| 58 | + (Story) => { |
| 59 | + return ( |
| 60 | + <Provider api={api}> |
| 61 | + <AppProvider i18n={translations}> |
| 62 | + <FormProvider {...useForm()}> |
| 63 | + <Story /> |
| 64 | + </FormProvider> |
| 65 | + </AppProvider> |
| 66 | + </Provider> |
| 67 | + ); |
| 68 | + }, |
| 69 | + ], |
| 70 | +}; |
| 71 | + |
| 72 | +export const Create = { |
| 73 | + args: { |
| 74 | + action: api.widget.create, |
| 75 | + }, |
| 76 | +}; |
| 77 | + |
| 78 | +export const Update = { |
| 79 | + args: { |
| 80 | + action: api.widget.update, |
| 81 | + findBy: "1", |
| 82 | + }, |
| 83 | +}; |
0 commit comments