Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コンポーネントのStoryの調整・不足分の追加 #2333

Merged
merged 17 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const preview: Preview = {
value: "#333",
},
],
grid: {
cellSize: 8,
cellAmount: 4,
opacity: 0.1,
},
},
},
decorators: [
Expand Down
23 changes: 19 additions & 4 deletions src/components/Base/BaseCheckbox.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { ref } from "vue";
import BaseCheckbox from "./BaseCheckbox.vue";

const meta: Meta<typeof BaseCheckbox> = {
Expand All @@ -9,17 +10,31 @@ const meta: Meta<typeof BaseCheckbox> = {
export default meta;
type Story = StoryObj<typeof BaseCheckbox>;

export const Default: Story = {
export const Unchecked: Story = {
args: {
label: "Default",
checked: false,
label: "Unchecked",
},
render: (args) => ({
components: { BaseCheckbox },
setup() {
const checked = ref(false);
return { args, checked };
},
template: `<BaseCheckbox v-bind="args" v-model:checked="checked"></BaseCheckbox>`,
}),
};

export const Checked: Story = {
...Default,
args: {
label: "Checked",
checked: true,
},
render: (args) => ({
components: { BaseCheckbox },
setup() {
const checked = ref(true);
return { args, checked };
},
template: `<BaseCheckbox v-bind="args" v-model:checked="checked"></BaseCheckbox>`,
}),
};
66 changes: 66 additions & 0 deletions src/components/Base/BaseSelect.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ref } from "vue";
import type { Meta, StoryObj } from "@storybook/vue3";

import BaseSelect from "./BaseSelect.vue";
import BaseSelectItem from "./BaseSelectItem.vue";

const meta: Meta<typeof BaseSelect> = {
component: BaseSelect,
};

export default meta;
type Story = StoryObj<typeof BaseSelect>;

export const Default: Story = {
render: (args) => ({
components: { BaseSelect, BaseSelectItem },
setup() {
const modelValue = ref("a");
return { args, modelValue };
},
template: `
<BaseSelect v-bind="args" v-model="modelValue">
<BaseSelectItem label="A" value="a" />
<BaseSelectItem label="B" value="b" />
<BaseSelectItem label="C" value="c" />
</BaseSelect>`,
}),
};

export const Placeholder: Story = {
args: {
placeholder: "placeholder",
},
render: (args) => ({
components: { BaseSelect, BaseSelectItem },
setup() {
const modelValue = ref("a");
return { args, modelValue };
},
template: `
<BaseSelect v-bind="args" v-model="modelValue">
<BaseSelectItem label="A" value="a" />
<BaseSelectItem label="B" value="b" />
<BaseSelectItem label="C" value="c" />
</BaseSelect>`,
}),
};

export const Disabled: Story = {
args: {
disabled: true,
},
render: (args) => ({
components: { BaseSelect, BaseSelectItem },
setup() {
const modelValue = ref("a");
return { args, modelValue };
},
template: `
<BaseSelect v-bind="args" v-model="modelValue">
<BaseSelectItem label="A" value="a" />
<BaseSelectItem label="B" value="b" />
<BaseSelectItem label="C" value="c" />
</BaseSelect>`,
}),
};
17 changes: 17 additions & 0 deletions src/components/Base/BaseSwitch.stories.ts
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { ref } from "vue";
import BaseSwitch from "./BaseSwitch.vue";

const meta: Meta<typeof BaseSwitch> = {
Expand All @@ -15,6 +16,14 @@ export const Unchecked: Story = {
checkedLabel: "On",
checked: false,
},
render: (args) => ({
components: { BaseSwitch },
setup() {
const checked = ref(false);
return { args, checked };
},
template: `<BaseSwitch v-bind="args" v-model:checked="checked"></BaseSwitch>`,
}),
};

export const Checked: Story = {
Expand All @@ -23,4 +32,12 @@ export const Checked: Story = {
checkedLabel: "On",
checked: true,
},
render: (args) => ({
components: { BaseSwitch },
setup() {
const checked = ref(true);
return { args, checked };
},
template: `<BaseSwitch v-bind="args" v-model:checked="checked"></BaseSwitch>`,
}),
};
51 changes: 51 additions & 0 deletions src/components/Base/BaseTooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { TooltipProvider } from "radix-vue";
import BaseTooltip from "./BaseTooltip.vue";

const meta: Meta<typeof BaseTooltip> = {
component: BaseTooltip,
};

export default meta;
type Story = StoryObj<typeof BaseTooltip>;

export const Default: Story = {
args: {
label: "Default",
},
render: (args) => ({
components: { BaseTooltip, TooltipProvider },
setup() {
return { args };
},
template: `
<TooltipProvider>
<BaseTooltip v-bind="args">
<span>Hover</span>
</BaseTooltip>
</TooltipProvider>`,
}),
};

export const Disabled: Story = {
args: {
label: "Default",
disabled: true,
},
render: (args) => ({
components: {
BaseTooltip,
TooltipProvider,
},
setup() {
return { args };
},
template: `
<TooltipProvider>
<BaseTooltip v-bind="args">
<span>Hover</span>
</BaseTooltip>
</TooltipProvider>`,
}),
};
65 changes: 65 additions & 0 deletions src/components/Dialog/AcceptDialog/AcceptDialog.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { userEvent, within, expect, fn } from "@storybook/test";

import { Meta, StoryObj } from "@storybook/vue3";
import AcceptDialog from "./AcceptDialog.vue";

const meta: Meta<typeof AcceptDialog> = {
component: AcceptDialog,
args: {
modelValue: false,
title: "タイトル",
heading: "見出し",
terms: "# 見出し1\n文章文章文章\n## 見出し2\n文章文章文章",
rejectLabel: "拒否",
acceptLabel: "承諾",
"onUpdate:modelValue": fn(),
onAccept: fn(),
onReject: fn(),
},
tags: ["!autodocs"], // ダイアログ系はautodocsのプレビューが正しく表示されないので無効化
};

export default meta;
type Story = StoryObj<typeof meta>;

export const Opened: Story = {
name: "開いている",
args: {
modelValue: true,
},
};

export const Accept: Story = {
name: "承諾ボタンを押す",
args: { ...Opened.args },
play: async ({ args }) => {
const canvas = within(document.body); // ダイアログなので例外的にdocument.bodyを使う

const button = canvas.getByRole("button", { name: /承諾/ });
await userEvent.click(button);

// 承諾イベントが呼ばれる
await expect(args["onAccept"]).toBeCalledWith();
},
};

export const Reject: Story = {
name: "拒否ボタンを押す",
args: {
...Opened.args,
},
play: async ({ args }) => {
const canvas = within(document.body); // ダイアログなので例外的にdocument.bodyを使う

const button = canvas.getByRole("button", { name: /拒否/ });
await userEvent.click(button);

// 拒否イベントが呼ばれる
await expect(args["onReject"]).toBeCalledWith();
},
};

export const Closed: Story = {
name: "閉じている",
tags: ["skip-screenshot"],
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.