-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import overflowFixture from "../../cypress/fixtures/overflowingData.json"; | ||
import { expect, within } from "@storybook/test"; | ||
|
||
// Note this type is re-used in the Dropdown.stories.ts file | ||
export type HTMLDetailsElementCustom = HTMLDetailsElement & { | ||
optionText: string; | ||
role: string; | ||
ariaInvalid: string; | ||
}; | ||
|
||
const meta: Meta<HTMLDetailsElementCustom> = { | ||
title: "Components/Accordion", | ||
|
||
tags: ["autodocs"], | ||
|
||
render: ({ title, open, role, optionText }) => ({ | ||
template: `<details ${open ? "open" : ""}><summary | ||
${ | ||
role ? `role="${role}"` : "" | ||
}>${title}</summary><p>${optionText}</p></details>`, | ||
}), | ||
|
||
argTypes: { | ||
role: { | ||
options: [undefined, "button"], | ||
}, | ||
}, | ||
|
||
args: { | ||
title: "Hello World", | ||
open: false, | ||
role: undefined, | ||
optionText: "This is a dropdown option", | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLDetailsElementCustom>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
open: true, | ||
}, | ||
}; | ||
|
||
export const ButtonRole: Story = { | ||
args: { | ||
role: "button", | ||
}, | ||
}; | ||
|
||
export const OpenWithOverflow: Story = { | ||
args: { | ||
...Open.args, | ||
title: overflowFixture.text_without_spaces, | ||
optionText: overflowFixture.text_without_spaces, | ||
}, | ||
play: async ({ canvasElement }: any) => { | ||
const canvas = within(canvasElement); | ||
const summary = canvas.getByText(overflowFixture.text_without_spaces); | ||
|
||
expect(summary).toBeVisible(); | ||
|
||
// Weird issue caused by font line-height changing size of contents within div means the following fails for now, although no user-impact seems to be visible | ||
// eslint-disable-next-line no-secrets/no-secrets | ||
// checkElementForTextOverflow(summary); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
import overflowFixture from "../../cypress/fixtures/overflowingData.json"; | ||
import { expect, within } from "@storybook/test"; | ||
import { checkElementForTextOverflow } from "./utils"; | ||
import type { HTMLDetailsElementCustom } from "./Accordion.stories"; | ||
|
||
const meta: Meta<HTMLDetailsElementCustom> = { | ||
title: "Components/Dropdown", | ||
|
||
tags: ["autodocs"], | ||
|
||
render: (args) => ({ | ||
template: `<summary | ||
${args.role ? `role="${args.role}"` : ""} ${ | ||
args.ariaInvalid ? `aria-invalid="${args.ariaInvalid}"` : "" | ||
}>${args.title}</summary><ul><li><a href="#">${ | ||
args.optionText | ||
}</a></li><li><a href="#">${args.optionText}</a></li><li><a href="#">${ | ||
args.optionText | ||
}</a></li></ul>`, | ||
}), | ||
|
||
decorators: [ | ||
(story, { args }) => ({ | ||
template: `<details ${ | ||
args.open ? "open" : "" | ||
} class="dropdown"><story /></details> | ||
`, | ||
}), | ||
], | ||
|
||
argTypes: { | ||
role: { | ||
options: [undefined, "button"], | ||
}, | ||
ariaInvalid: { | ||
options: [undefined, "true", "false"], | ||
}, | ||
}, | ||
|
||
args: { | ||
title: "Hello World", | ||
open: false, | ||
role: undefined, | ||
ariaInvalid: undefined, | ||
optionText: "This is a dropdown option", | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLDetailsElementCustom>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
open: true, | ||
}, | ||
}; | ||
|
||
export const ButtonRole: Story = { | ||
args: { | ||
role: "button", | ||
}, | ||
}; | ||
|
||
export const OpenWithOverflow: Story = { | ||
args: { | ||
...Open.args, | ||
title: overflowFixture.text_without_spaces, | ||
optionText: overflowFixture.text_without_spaces, | ||
}, | ||
play: async ({ canvasElement }: any) => { | ||
const canvas = within(canvasElement); | ||
const summary = canvas.getByText(overflowFixture.text_without_spaces); | ||
|
||
expect(summary).toBeVisible(); | ||
|
||
checkElementForTextOverflow(summary); | ||
}, | ||
}; | ||
|
||
export const WithRadioButtons: Story = { | ||
render: ({ optionText }) => ({ | ||
template: ` | ||
<summary> | ||
Select a phase of matter... | ||
</summary> | ||
<ul> | ||
<li> | ||
<label> | ||
<input type="radio" name="phase" value="solid" /> | ||
Solid | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="radio" name="phase" value="liquid" /> | ||
Liquid | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="radio" name="phase" value="gas" /> | ||
${optionText} | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="radio" name="phase" value="plasma" /> | ||
Plasma | ||
</label> | ||
</li> | ||
</ul>`, | ||
}), | ||
}; | ||
|
||
export const WithCheckboxes: Story = { | ||
render: ({ optionText }) => ({ | ||
template: ` | ||
<summary> | ||
Select phases of matter... | ||
</summary> | ||
<ul> | ||
<li> | ||
<label> | ||
<input type="checkbox" name="solid" /> | ||
Solid | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="checkbox" name="liquid" /> | ||
Liquid | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="checkbox" name="gas" /> | ||
${optionText} | ||
</label> | ||
</li> | ||
<li> | ||
<label> | ||
<input type="checkbox" name="plasma" /> | ||
Plasma | ||
</label> | ||
</li> | ||
</ul>`, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters