-
-
Notifications
You must be signed in to change notification settings - Fork 360
docs(ui): add ButtonGroup stories to storybook #1964
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,116 @@ | ||
| import type { Meta, StoryObj } from '@storybook-vue/nuxt' | ||
| import ButtonBase from './Base.vue' | ||
|
|
||
| const meta = { | ||
| component: ButtonBase, | ||
| parameters: { | ||
| docs: { | ||
| source: { | ||
| type: 'dynamic', | ||
| transform: (code: string) => | ||
| code.replace(/<Base\b/g, '<ButtonBase').replace(/<\/Base>/g, '</ButtonBase>'), | ||
| }, | ||
| }, | ||
| }, | ||
| tags: ['autodocs'], | ||
| } satisfies Meta<typeof ButtonBase> | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| default: 'Button Text', | ||
| }, | ||
| } | ||
|
|
||
| export const Primary: Story = { | ||
| args: { | ||
| variant: 'primary', | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("nav.settings") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const Secondary: Story = { | ||
| args: { | ||
| variant: 'secondary', | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("nav.settings") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const Small: Story = { | ||
| args: { | ||
| size: 'small', | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("nav.settings") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const Disabled: Story = { | ||
| args: { | ||
| disabled: true, | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("nav.settings") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const WithIcon: Story = { | ||
| args: { | ||
| classicon: 'i-lucide:search', | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("search.button") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const WithKeyboardShortcut: Story = { | ||
| args: { | ||
| ariaKeyshortcuts: '/', | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("search.button") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
|
|
||
| export const Block: Story = { | ||
| args: { | ||
| block: true, | ||
| }, | ||
| render: args => ({ | ||
| components: { ButtonBase }, | ||
| setup() { | ||
| return { args } | ||
| }, | ||
| template: `<ButtonBase v-bind="args">{{ $t("nav.settings") }}</ButtonBase>`, | ||
| }), | ||
| } | ||
This file contains hidden or 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,106 @@ | ||
| import type { Meta, StoryObj } from '@storybook-vue/nuxt' | ||
| import ButtonBase from './Base.vue' | ||
| import ButtonGroup from './Group.vue' | ||
|
|
||
| const meta = { | ||
| component: ButtonGroup, | ||
| parameters: { | ||
| docs: { | ||
| source: { | ||
| type: 'dynamic', | ||
| transform: (code: string) => | ||
| code | ||
| .replace(/<Base\b/g, '<ButtonBase') | ||
| .replace(/<\/Base>/g, '</ButtonBase>') | ||
| .replace(/<Group\b/g, '<ButtonGroup') | ||
| .replace(/<\/Group>/g, '</ButtonGroup>'), | ||
| }, | ||
| }, | ||
| }, | ||
| tags: ['autodocs'], | ||
| } satisfies Meta<typeof ButtonGroup> | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const Default: Story = { | ||
| parameters: { | ||
| docs: { | ||
| source: { | ||
| code: ` | ||
| <template> | ||
| <ButtonGroup> | ||
| <ButtonBase>Back</ButtonBase> | ||
| <ButtonBase>Settings</ButtonBase> | ||
| <ButtonBase>Compare</ButtonBase> | ||
| </ButtonGroup> | ||
| </template> | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| render: () => ({ | ||
| components: { ButtonBase, ButtonGroup }, | ||
| template: ` | ||
| <ButtonGroup> | ||
| <ButtonBase>{{ $t('nav.back') }}</ButtonBase> | ||
| <ButtonBase>{{ $t('nav.settings') }}</ButtonBase> | ||
| <ButtonBase>{{ $t('nav.compare') }}</ButtonBase> | ||
| </ButtonGroup> | ||
| `, | ||
| }), | ||
| } | ||
|
|
||
| export const WithVariants: Story = { | ||
| parameters: { | ||
| docs: { | ||
| source: { | ||
| code: ` | ||
| <template> | ||
| <ButtonGroup> | ||
| <ButtonBase variant="primary">Back</ButtonBase> | ||
| <ButtonBase variant="primary">Settings</ButtonBase> | ||
| <ButtonBase variant="primary">Compare</ButtonBase> | ||
| </ButtonGroup> | ||
| </template> | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| render: () => ({ | ||
| components: { ButtonBase, ButtonGroup }, | ||
| template: ` | ||
| <ButtonGroup> | ||
| <ButtonBase variant="primary">{{ $t('nav.back') }}</ButtonBase> | ||
| <ButtonBase variant="primary">{{ $t('nav.settings') }}</ButtonBase> | ||
| <ButtonBase variant="primary">{{ $t('nav.compare') }}</ButtonBase> | ||
| </ButtonGroup> | ||
| `, | ||
| }), | ||
| } | ||
|
|
||
| export const WithIcons: Story = { | ||
| parameters: { | ||
| docs: { | ||
| source: { | ||
| code: ` | ||
| <template> | ||
| <ButtonGroup> | ||
| <ButtonBase variant="secondary" classicon="i-lucide:x">Close</ButtonBase> | ||
| <ButtonBase variant="secondary" classicon="i-lucide:search">Search</ButtonBase> | ||
| </ButtonGroup> | ||
| </template> | ||
| `, | ||
| }, | ||
| }, | ||
| }, | ||
| render: () => ({ | ||
| components: { ButtonBase, ButtonGroup }, | ||
| template: ` | ||
| <ButtonGroup> | ||
| <ButtonBase variant="secondary" classicon="i-lucide:x">{{ $t('common.close') }}</ButtonBase> | ||
| <ButtonBase variant="secondary" classicon="i-lucide:search">{{ $t('filters.search') }}</ButtonBase> | ||
| </ButtonGroup> | ||
| `, | ||
| }), | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default story may not render slot content without a render function.
All other stories use explicit render functions with templates to handle slot content, but
Defaultrelies onargs.defaultwithout a render function. In Vue Storybook, this pattern typically requires either a render function or specificargTypesconfiguration to pass slot content properly.Consider adding a render function for consistency and to ensure the button text displays:
Proposed fix
export const Default: Story = { - args: { - default: 'Button Text', - }, + render: args => ({ + components: { ButtonBase }, + setup() { + return { args } + }, + template: `<ButtonBase v-bind="args">Button Text</ButtonBase>`, + }), }📝 Committable suggestion
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the default story with the default render allow to someone viewing the storybook to change the story to alternative text in place of
Button Text. The other stories use the template render in order for the internationalization to work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cylewaitforit, that makes perfect sense! Usingargs.defaultwithout a render function is the correct approach here — it exposes the slot content as a Storybook control, allowing users to interactively edit the button text directly from the controls panel. The render function approach in the other stories is needed for i18n to work, but would prevent that interactive editing for theDefaultstory. Thanks for the clarification!ʕ •`ᴥ´• ʔ
✏️ Learnings added
🧠 Learnings used