-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a chromatic test for mount args for React, Vue and Svelte
- Loading branch information
1 parent
9aab3bd
commit 530c0ef
Showing
5 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
code/renderers/react/template/stories/mount-in-play.stories.tsx
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,20 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import type { StoryObj } from '@storybook/react'; | ||
|
||
const Button: FC<{ label?: string; disabled?: boolean }> = (props) => { | ||
return <button disabled={props.disabled}>{props.label}</button>; | ||
}; | ||
|
||
export default { | ||
component: Button, | ||
}; | ||
|
||
export const Basic: StoryObj<typeof Button> = { | ||
args: { | ||
disabled: true, | ||
}, | ||
async play({ mount, args }) { | ||
await mount(<Button {...args} label={'set in play'} />); | ||
}, | ||
}; |
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,44 @@ | ||
<script> | ||
import { createEventDispatcher } from 'svelte'; | ||
/** | ||
* Is this the principal call to action on the page? | ||
*/ | ||
export let primary = false; | ||
/** | ||
* What background color to use | ||
*/ | ||
export let backgroundColor = undefined; | ||
/** | ||
* How large should the button be? | ||
*/ | ||
export let size = 'medium'; | ||
/** | ||
* Button contents | ||
*/ | ||
export let label = ''; | ||
$: mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary'; | ||
$: style = backgroundColor ? `background-color: ${backgroundColor}` : ''; | ||
const dispatch = createEventDispatcher(); | ||
/** | ||
* Optional click handler | ||
*/ | ||
export let onClick = (event) => { | ||
dispatch('click', event); | ||
}; | ||
</script> | ||
|
||
<button | ||
type="button" | ||
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')} | ||
{style} | ||
on:click={onClick} | ||
> | ||
{label} | ||
</button> |
15 changes: 15 additions & 0 deletions
15
code/renderers/svelte/template/stories/mount-in-play.stories.ts
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,15 @@ | ||
import Button from './Button.svelte'; | ||
import type { StoryObj } from '@storybook/svelte'; | ||
|
||
export default { | ||
component: Button, | ||
}; | ||
|
||
export const Basic: StoryObj = { | ||
args: { | ||
disabled: true, | ||
}, | ||
async play({ mount, args }) { | ||
await mount(Button, { props: { ...args, label: 'set in play' } }); | ||
}, | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
code/renderers/vue3/template/stories_vue3-vite-default-ts/mount-in-play.stories.ts
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,20 @@ | ||
import type { StoryObj } from '@storybook/vue3'; | ||
import { defineComponent } from 'vue'; | ||
|
||
const Button = defineComponent({ | ||
template: '<button :disabled="disabled">{{label}}</button>', | ||
props: ['disabled', 'label'], | ||
}); | ||
|
||
export default { | ||
component: Button, | ||
}; | ||
|
||
export const Basic: StoryObj<typeof Button> = { | ||
args: { | ||
disabled: true, | ||
}, | ||
async play({ mount, args }) { | ||
await mount(Button, { props: { ...args, label: 'set in play' } }); | ||
}, | ||
}; |