-
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.
chore: add stories for input elements
- Loading branch information
Showing
6 changed files
with
333 additions
and
8 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,66 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
|
||
type HTMLInputElementCustom = Omit<HTMLInputElement, "type"> & { | ||
role?: "switch"; | ||
ariaInvalid: boolean | undefined; | ||
}; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories | ||
const meta: Meta<HTMLInputElementCustom> = { | ||
title: "Components/Inputs/Checkbox", | ||
// We will just show a simple input | ||
render: (args) => ({ | ||
setup() { | ||
return { args }; | ||
}, | ||
// We need to render the checkbox with options from args | ||
template: ` | ||
<label for='checkbox'> | ||
<input id='checkbox' type='checkbox' v-bind='args'></input> | ||
{{args.name}} | ||
</label> | ||
`, | ||
}), | ||
|
||
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ["autodocs"], | ||
argTypes: { | ||
disabled: { | ||
control: "boolean", | ||
description: "If the input is disabled", | ||
}, | ||
// aria-invalid can be true, false, or undefined | ||
ariaInvalid: { | ||
// We need 3 options, true, false, and undefined | ||
options: [true, false, undefined], | ||
control: { type: "select" }, | ||
description: | ||
"If the input is invalid. If false, the input is valid. If undefined, the input is neither valid nor invalid", | ||
}, | ||
role: { | ||
options: [undefined, "switch"], | ||
control: { type: "select" }, | ||
description: "The role of the input", | ||
}, | ||
}, | ||
args: { | ||
checked: true, | ||
name: "Checkbox", | ||
required: true, | ||
disabled: false, | ||
readOnly: false, | ||
role: undefined, | ||
}, // default value | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLInputElementCustom>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Switch: Story = { | ||
args: { | ||
name: "Switch", | ||
role: "switch", | ||
}, | ||
}; |
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,52 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
|
||
type HTMLInputElementCustom = Omit<HTMLInputElement, "type"> & { | ||
ariaInvalid: boolean | undefined; | ||
}; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories | ||
const meta: Meta<HTMLInputElementCustom> = { | ||
title: "Components/Inputs/Radio", | ||
// We will just show a simple input | ||
render: (args) => ({ | ||
setup() { | ||
return { args }; | ||
}, | ||
// We need to render the radio with options from args | ||
template: ` | ||
<label for='radio'> | ||
<input id='radio' type='radio' v-bind='args'></input> | ||
{{args.name}} | ||
</label> | ||
`, | ||
}), | ||
|
||
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ["autodocs"], | ||
argTypes: { | ||
disabled: { | ||
control: "boolean", | ||
description: "If the input is disabled", | ||
}, | ||
// aria-invalid can be true, false, or undefined | ||
ariaInvalid: { | ||
// We need 3 options, true, false, and undefined | ||
options: [true, false, undefined], | ||
control: { type: "select" }, | ||
description: | ||
"If the input is invalid. If false, the input is valid. If undefined, the input is neither valid nor invalid", | ||
}, | ||
}, | ||
args: { | ||
checked: true, | ||
name: "Radio", | ||
required: true, | ||
disabled: false, | ||
readOnly: false, | ||
}, // default value | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLInputElementCustom>; | ||
|
||
export const Default: Story = {}; |
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,68 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
|
||
// Custom HTMLSelectElement type to add options | ||
type HTMLSelectElementCustom = Omit<HTMLSelectElement, "options"> & { | ||
options: string[]; | ||
ariaInvalid: boolean | undefined; | ||
}; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories | ||
const meta: Meta<HTMLSelectElementCustom> = { | ||
title: "Components/Inputs/Select", | ||
// We will just show a simple input | ||
render: (args) => ({ | ||
setup() { | ||
return { args }; | ||
}, | ||
// We need to render the select with options from args | ||
template: | ||
"<label for='select'>{{args.name}}</label><select id='select' v-bind='args'><option v-for='option in args.options' :value='option'>{{ option }}</option></select>", | ||
}), | ||
|
||
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ["autodocs"], | ||
argTypes: { | ||
// @ts-ignore | ||
value: { | ||
control: "text", | ||
description: "The value of the input", | ||
}, | ||
disabled: { | ||
control: "boolean", | ||
description: "If the input is disabled", | ||
}, | ||
// aria-invalid can be true, false, or undefined | ||
ariaInvalid: { | ||
// We need 3 options, true, false, and undefined | ||
options: [true, false, undefined], | ||
control: { type: "select" }, | ||
description: | ||
"If the input is invalid. If false, the input is valid. If undefined, the input is neither valid nor invalid", | ||
}, | ||
size: { | ||
control: "number", | ||
description: "The size of the input", | ||
}, | ||
}, | ||
args: { | ||
value: "Option 1", | ||
required: true, | ||
disabled: false, | ||
multiple: false, | ||
name: "Select", | ||
options: ["Option 1", "Option 2", "Option 3"], | ||
size: undefined, | ||
}, // default value | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLSelectElementCustom>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Multiple: Story = { | ||
args: { | ||
multiple: true, | ||
size: 3, | ||
}, | ||
}; |
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,61 @@ | ||
import type { Meta, StoryObj } from "@storybook/vue3"; | ||
|
||
// Custom HTMLSelectElement type to add options | ||
type HTMLTextAreaElementCustom = Omit<HTMLTextAreaElement, "options"> & { | ||
options: string[]; | ||
ariaInvalid: boolean | undefined; | ||
}; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories | ||
const meta: Meta<HTMLTextAreaElementCustom> = { | ||
title: "Components/Inputs/Textarea", | ||
// We will just show a simple input | ||
render: (args) => ({ | ||
setup() { | ||
return { args }; | ||
}, | ||
// We need to render the textarea with options from args | ||
template: | ||
"<label for='textarea'>{{args.name}}</label><textarea id='textarea' v-bind='args'></textarea>", | ||
}), | ||
|
||
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ["autodocs"], | ||
argTypes: { | ||
// @ts-ignore | ||
value: { | ||
control: "text", | ||
description: "The value of the input", | ||
}, | ||
placeholder: { | ||
control: "text", | ||
description: "The placeholder of the input", | ||
}, | ||
disabled: { | ||
control: "boolean", | ||
description: "If the input is disabled", | ||
}, | ||
// aria-invalid can be true, false, or undefined | ||
ariaInvalid: { | ||
// We need 3 options, true, false, and undefined | ||
options: ["true", "false", undefined], | ||
control: { type: "select" }, | ||
description: | ||
"If the input is invalid. If false, the input is valid. If undefined, the input is neither valid nor invalid", | ||
}, | ||
}, | ||
args: { | ||
name: "Textarea", | ||
value: "Hello World", | ||
placeholder: "Hello World", | ||
required: true, | ||
disabled: false, | ||
readOnly: false, | ||
ariaInvalid: undefined, | ||
}, // default value | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<HTMLTextAreaElementCustom>; | ||
|
||
export const Default: Story = {}; |