import type { Meta, Story } from "@storybook/react"; import type { ArgType } from "@storybook/addons"; import { symToStr } from "tsafe/symToStr"; import { theme, ThemeProvider } from "../ui/theme"; import { id } from "tsafe/id"; import { GlobalStyles } from "tss-react/compat"; export function getStoryFactory>(params: { sectionName: string; wrappedComponent: Record ReturnType>; /** https://storybook.js.org/docs/react/essentials/controls */ argTypes?: Partial>; defaultWidth?: number; }) { const { sectionName, wrappedComponent, argTypes = {}, defaultWidth } = params; const Component: any = Object.entries(wrappedComponent).map(([, component]) => component)[0]; const Template: Story< Props & { width: number; targetWindowInnerWidth: number; } > = ({ width, ...props }) => { return (
); }; function getStory(props: Props): typeof Template { const out = Template.bind({}); out.args = { "width": defaultWidth ?? 0, "targetWindowInnerWidth": 0, "chromeFontSize": "Medium (Recommended)", ...props, }; return out; } return { "meta": id({ "title": `${sectionName}/${symToStr(wrappedComponent)}`, "component": Component, "argTypes": { "width": { "control": { "type": "range", "min": 0, "max": 1920, "step": 1, }, }, "targetWindowInnerWidth": { "control": { "type": "range", "min": 0, "max": 2560, "step": 10, }, }, ...argTypes, }, }), getStory, }; } export function logCallbacks(propertyNames: readonly T[]): Record void> { const out: Record void> = id>({}); propertyNames.forEach(propertyName => (out[propertyName] = console.log.bind(console, propertyName))); return out; }