Skip to content

Commit

Permalink
refactor(storybook): re-use remix stub
Browse files Browse the repository at this point in the history
  • Loading branch information
chohner committed Nov 16, 2023
1 parent d9f9b1f commit c21d5c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .storybook/remixContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createRemixStub } from "@remix-run/testing";
import { ComponentType, createElement } from "react";

export function remixContext(component: ComponentType) {
return createElement(createRemixStub([{ path: "/", Component: component }]));
}
8 changes: 2 additions & 6 deletions stories/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import Checkbox from "../app/components/inputs/Checkbox";
import { createRemixStub } from "@remix-run/testing";
import { createElement } from "react";
import { remixContext } from "../.storybook/remixContext";
const component = Checkbox;

const meta = {
Expand All @@ -18,9 +17,6 @@ export const Default = {
label: "label",
formId: "formId",
},
decorators: [
(Story) =>
createElement(createRemixStub([{ path: "/", Component: Story }])),
],
decorators: [(Story) => remixContext(Story)],
} satisfies StoryObj<typeof meta>;
export default meta;
14 changes: 2 additions & 12 deletions stories/UserFeedback.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import UserFeedback, { BannerState } from "../app/components/UserFeedback";
import { createRemixStub } from "@remix-run/testing";
import { remixContext } from "../.storybook/remixContext";

const meta = {
title: "Content/UserFeedback",
Expand Down Expand Up @@ -32,15 +32,5 @@ export const Example: StoryObj<typeof meta> = {
text: "Ihr Feedback hilft uns, diese Seite für alle Nutzenden zu verbessern!",
},
},
decorators: [
(Story) => {
const RemixStub = createRemixStub([
{
path: "/",
Component: Story,
},
]);
return <RemixStub />;
},
],
decorators: [(Story) => remixContext(Story)],
};

0 comments on commit c21d5c9

Please sign in to comment.