templatized storymaking

This commit is contained in:
ari committed 2022-07-28 14:48:05 -04:00
1 parent 02ec81c16a
commit a9c3e9c890
9 files changed
+255 -172

No files matched your search

@@ -1,59 +1,44 @@
import "styles/root.css";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { Page } from "components/Page";
import { MetadataBox } from ".";
import { useTagDB } from "../TagDB";
import { useState } from "react";
export default {
title: "App/AutomationList/MetadataBox",
component: MetadataBox,
parameters: { actions: { argTypesRegex: "^on.*" } },
args: {
id: "dummy",
title: "Example",
description: "Cool!",
state: "on",
isSelected: false,
tags: {
room: "main bedroom",
routine: "night time",
import { makeStory } from "devUtils";
const { make, componentMeta } = makeStory({
Component: MetadataBox,
meta: {
title: "App/AutomationManager/MetadataBox",
args: {
id: "dummy",
title: "Example",
description: "Cool!",
state: "on",
isSelected: false,
tags: {
room: "main bedroom",
routine: "night time",
},
},
},
} as ComponentMeta<typeof MetadataBox>;
BaseTemplate: (args) => {
const [autoTags, setTags] = useState([{ id: args.id, tags: args.tags }]);
const tagsDB = useTagDB(autoTags, (aid, t) =>
setTags(
autoTags
.filter(({ id }) => id !== aid)
.concat({
id: aid,
tags: t,
})
)
);
return <MetadataBox {...args} tagsDB={tagsDB} />;
},
});
const Template: ComponentStory<typeof MetadataBox> = (args) => {
const [autoTags, setTags] = useState([{ id: args.id, tags: args.tags }]);
const tagsDB = useTagDB(autoTags, (aid, t) =>
setTags(
autoTags
.filter(({ id }) => id !== aid)
.concat({
id: aid,
tags: t,
})
)
);
return (
<Page>
<MetadataBox {...args} tagsDB={tagsDB} />
</Page>
);
};
export default componentMeta;
export const Basic = Template.bind({});
export const IsSelected = Template.bind({});
IsSelected.args = {
...IsSelected.args,
isSelected: true,
};
export const InvalidState = Template.bind({});
InvalidState.args = {
...InvalidState.args,
state: "unavailable",
};
export const WithIssue = Template.bind({});
WithIssue.args = {
...WithIssue.args,
issue: "look at me",
};
export const Basic = make({});
export const IsSelected = make({ isSelected: true });
export const InvalidState = make({ state: "unavailable" });
export const WithIssue = make({ issue: "look at me" });