Skip to content

Commit

Permalink
FEATURE: Setup Actions on storybook (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrangPham authored Mar 7, 2024
1 parent 946757e commit 37cf52b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const config: StorybookConfig = {
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
"@storybook/addon-onboarding",
],
framework: {
name: "@storybook/react-vite",
Expand Down
8 changes: 7 additions & 1 deletion src/common/StorybookAntDJsonForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Props = {
uiSchema?: UISchema;
uiSchemaRegistryEntries?: JsonFormsUISchemaRegistryEntry[];
config?: Record<string, unknown>;
onChange: (data: Record<string, unknown>) => void;
};

// this component exists to facilitate storybook rendering
Expand All @@ -24,14 +25,19 @@ export function StorybookAntDJsonForm({
uiSchemaRegistryEntries,
rendererRegistryEntries,
config,
onChange
}: Props) {
const [data, setData] = useState(initialData);
const updateData = (newData: Record<string, unknown>) => {
setData(newData);
onChange(newData);
}
return (
<AntDJsonForm
uiSchema={uiSchema}
jsonSchema={jsonSchema}
data={data}
updateData={(newData) => setData(newData)}
updateData={(newData) => updateData(newData)}
uiSchemaRegistryEntries={uiSchemaRegistryEntries}
rendererRegistryEntries={rendererRegistryEntries}
config={config}
Expand Down
8 changes: 6 additions & 2 deletions src/stories/controls/AlertControl.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ const meta: Meta<typeof StorybookAntDJsonForm> = {
]
},
argTypes: {
rendererRegistryEntries: {},
rendererRegistryEntries: { table: { disable: true } },
uiSchemaRegistryEntries: { table: { disable: true } },
jsonSchema: {
control: "object",
}
},
data: {table: {disable: true}},
config: {control: "object"},
onChange: {table: {disable: true, action: "on-change"}},
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/stories/controls/BooleanControl.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { StorybookAntDJsonForm } from "../../common/StorybookAntDJsonForm";
const schema = {
type: "object",
properties: { checkbox: { type: "boolean" } },
// required: ["name"],
};

const meta: Meta<typeof StorybookAntDJsonForm> = {
Expand Down Expand Up @@ -37,10 +36,13 @@ const meta: Meta<typeof StorybookAntDJsonForm> = {
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
rendererRegistryEntries: { table: { disable: true } },
uiSchemaRegistryEntries: { table: { disable: true } },
jsonSchema: {
control: "object",
description: "this is a simple schema with one property (name)",
},
data: {table: {disable: true}},
config: {control: "object"},
onChange: {table: {disable: true, action: "on-change"}},
},
};

Expand Down
4 changes: 4 additions & 0 deletions src/stories/controls/TextControl.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const meta: Meta<typeof StorybookAntDJsonForm> = {
control: "object",
description: "this is a simple schema with one property (name)",
},
uiSchemaRegistryEntries: { table: { disable: true } },
data: {table: {disable: true}},
config: {control: "object"},
onChange: {table: {disable: true, action: "on-change"}},
},
};

Expand Down

0 comments on commit 37cf52b

Please sign in to comment.