Skip to content

Commit

Permalink
Merge pull request #355 from MuckRock/storybook-updates
Browse files Browse the repository at this point in the history
Storybook updates and fixes
  • Loading branch information
allanlasser authored Dec 7, 2023
2 parents 698e334 + a587fb0 commit e3f7865
Show file tree
Hide file tree
Showing 60 changed files with 809 additions and 843 deletions.
2 changes: 1 addition & 1 deletion src/addons/browser/SearchInput.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script context="module">
<script lang="ts" context="module">
import { _ } from "svelte-i18n";
import { writable } from "svelte/store";
Expand Down
16 changes: 8 additions & 8 deletions src/addons/browser/stories/AddOnList.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import defaultAddons from "../../fixtures/addons.json";
import AddOnList from "../AddOnList.svelte";
Expand All @@ -9,13 +9,13 @@
loading: false,
error: null,
};
</script>
<Meta
title="Add-Ons / Browser / Components / List"
component={AddOnList}
parameters={{ layout: "centered" }}
/>
export const meta = {
title: "Add-Ons / Browser / Components / List",
component: AddOnList,
parameters: { layout: "centered" },
};
</script>

<Template let:args>
<AddOnList {...args} />
Expand Down
20 changes: 0 additions & 20 deletions src/addons/browser/stories/AddOnListItem.demo.svelte

This file was deleted.

26 changes: 17 additions & 9 deletions src/addons/browser/stories/AddOnListItem.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import AddOnListItem from "../AddOnListItem.svelte";
import AddOnListItemDemo from "./AddOnListItem.demo.svelte";
const addon = {
active: false,
Expand All @@ -16,16 +15,25 @@
};
const args = { addon };
export const meta = {
title: "Add-Ons / Browser / Components / List Item",
component: AddOnListItem,
parameters: { layout: "centered" },
};
</script>

<Meta
title="Add-Ons / Browser / Components / List Item"
component={AddOnListItem}
parameters={{ layout: "centered" }}
/>
<style>
.container {
max-width: 32rem;
border: 1px solid #eee;
}
</style>

<Template let:args>
<AddOnListItemDemo {args} />
<div class="container">
<AddOnListItem {...args} />
</div>
</Template>

<Story name="Default" {args} />
Expand Down
53 changes: 22 additions & 31 deletions src/addons/browser/stories/Browser.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
<script>
import { rest } from "msw";
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import Browser from "../Browser.svelte";
import listFixture from "../../fixtures/addon-list.json";
import { baseApiUrl } from "../../../api/base.js";
const args = { visible: true };
const mockUrl = new URL(`addons/`, baseApiUrl).toString();
/* Mock Request Handlers */
const data = rest.get(mockUrl, (req, res, ctx) => res(ctx.json(listFixture)));
const loading = rest.get(mockUrl, (req, res, ctx) =>
res(ctx.delay("infinite")),
);
const error = rest.get(mockUrl, (req, res, ctx) =>
res(
ctx.status(400, "Ambiguous Error"),
ctx.json("Something went horribly wrong."),
),
);
const empty = rest.get(mockUrl, (req, res, ctx) =>
res(ctx.json({ next: null, previous: null, results: [] })),
);
</script>
import { addons } from "./mockData";
<Meta
title="Add-Ons / Browser"
tags={["autodocs"]}
parameters={{ layout: "fullscreen" }}
component={Browser}
/>
export const meta = {
title: "Add-Ons / Browser",
tags: ["autodocs"],
parameters: { layout: "fullscreen" },
component: Browser,
};
</script>

<Template let:args>
<Browser {...args} />
</Template>

<Story name="Success" {args} parameters={{ msw: { handlers: [data] } }} />
<Story name="Loading" {args} parameters={{ msw: { handlers: [loading] } }} />
<Story name="Error" {args} parameters={{ msw: { handlers: [error] } }} />
<Story name="Empty" {args} parameters={{ msw: { handlers: [empty] } }} />
<Story
name="Success"
{args}
parameters={{ msw: { handlers: [addons.data] } }}
/>
<Story
name="Loading"
{args}
parameters={{ msw: { handlers: [addons.loading] } }}
/>
<Story name="Error" {args} parameters={{ msw: { handlers: [addons.error] } }} />
<Story name="Empty" {args} parameters={{ msw: { handlers: [addons.empty] } }} />
10 changes: 0 additions & 10 deletions src/addons/browser/stories/Filter.demo.svelte

This file was deleted.

26 changes: 14 additions & 12 deletions src/addons/browser/stories/Filter.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import Filter from "../Filter.svelte";
import FilterDemo from "./Filter.demo.svelte";
import Star from "../../../common/icons/Star.svelte";
let args = { selected: false, name: "Pinned" };
</script>
<Meta
title="Add-Ons / Browser / Components / Filter"
tags={["autodocs"]}
parameters={{ layout: "centered" }}
component={Filter}
argTypes={{ selected: { control: "boolean" } }}
/>
export const meta = {
title: "Add-Ons / Browser / Components / Filter",
tags: ["autodocs"],
parameters: { layout: "centered" },
component: Filter,
argTypes: { selected: { control: "boolean" } },
};
</script>

<Template let:args>
<FilterDemo {args} />
<Filter {...args}>
<Star slot="icon" />
</Filter>
</Template>

<Story name="Default" {args} />
Expand Down
18 changes: 9 additions & 9 deletions src/addons/browser/stories/Filters.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import Filters from "../Filters.svelte";
const args = {};
</script>
<Meta
title="Add-Ons / Browser / Components / Filters"
tags={["autodocs"]}
parameters={{ layout: "centered" }}
component={Filters}
/>
export const meta = {
title: "Add-Ons / Browser / Components / Filters",
tags: ["autodocs"],
parameters: { layout: "centered" },
component: Filters,
};
</script>

<Template let:args>
<Filters {...args} />
Expand Down
7 changes: 0 additions & 7 deletions src/addons/browser/stories/SearchInput.demo.svelte

This file was deleted.

27 changes: 15 additions & 12 deletions src/addons/browser/stories/SearchInput.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import SearchInput from "../SearchInput.svelte";
import SearchInputDemo from "./SearchInput.demo.svelte";
const args = {};
export const meta = {
title: "Add-Ons / Browser / Components / Search",
tags: ["autodocs"],
parameters: { layout: "centered" },
component: SearchInput,
};
</script>

<Meta
title="Add-Ons / Browser / Components / Search"
tags={["autodocs"]}
parameters={{ layout: "centered" }}
component={SearchInput}
/>
<Template let:args>
<SearchInput {...args} />
</Template>

<Story name="Search">
<SearchInputDemo />
</Story>
<Story name="Search" {args} />
21 changes: 21 additions & 0 deletions src/addons/browser/stories/mockData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { rest } from "msw";
import listFixture from "../../fixtures/addon-list.json";
import { baseApiUrl } from "../../../api/base.js";

const mockAddonUrl = new URL(`addons/`, baseApiUrl).toString();
/* Mock Request Handlers */
export const addons = {
data: rest.get(mockAddonUrl, (req, res, ctx) => res(ctx.json(listFixture))),
loading: rest.get(mockAddonUrl, (req, res, ctx) =>
res(ctx.delay("infinite")),
),
error: rest.get(mockAddonUrl, (req, res, ctx) =>
res(
ctx.status(400, "Ambiguous Error"),
ctx.json("Something went horribly wrong."),
),
),
empty: rest.get(mockAddonUrl, (req, res, ctx) =>
res(ctx.json({ next: null, previous: null, results: [] })),
),
};
16 changes: 8 additions & 8 deletions src/addons/dispatch/fields/stories/ArrayField.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import ArrayField from "../ArrayField.svelte";
Expand All @@ -8,13 +8,13 @@
title: "Array Field",
description: "An array of items",
};
</script>
<Meta
title="Add-Ons / Dispatch / Form / Fields / Array Field"
component={ArrayField}
parameters={{ layout: "centered" }}
/>
export const meta = {
title: "Add-Ons / Dispatch / Form / Fields / Array Field",
component: ArrayField,
parameters: { layout: "centered" },
};
</script>

<Template let:args>
<ArrayField {...args} />
Expand Down
18 changes: 9 additions & 9 deletions src/addons/dispatch/fields/stories/Checkbox.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import Checkbox from "../Checkbox.svelte";
let args = {
name: "checkbox",
title: "Checkbox",
description: "An array of items",
description: "Check to confirm",
required: false,
value: true,
};
</script>
<Meta
title="Add-Ons / Dispatch / Form / Fields / Checkbox"
component={Checkbox}
parameters={{ layout: "centered" }}
/>
export const meta = {
title: "Add-Ons / Dispatch / Form / Fields / Checkbox",
component: Checkbox,
parameters: { layout: "centered" },
};
</script>

<Template let:args>
<Checkbox {...args} />
Expand Down
16 changes: 8 additions & 8 deletions src/addons/dispatch/fields/stories/Number.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { Meta, Story, Template } from "@storybook/addon-svelte-csf";
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import Number from "../Number.svelte";
Expand All @@ -13,13 +13,13 @@
min: "0",
max: "2",
};
</script>
<Meta
title="Add-Ons / Dispatch / Form / Fields / Number"
component={Number}
parameters={{ layout: "centered" }}
/>
export const meta = {
title: "Add-Ons / Dispatch / Form / Fields / Number",
component: Number,
parameters: { layout: "centered" },
};
</script>

<Template let:args>
<Number {...args} />
Expand Down
Loading

0 comments on commit e3f7865

Please sign in to comment.