-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28385 from storybookjs/kasper/mount-args
Test: Add args to `mount` in react, svelte, and vue renderers
- Loading branch information
Showing
16 changed files
with
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const parameters: {} = { renderer: 'react' }; | ||
export { render } from './render'; | ||
export { renderToCanvas } from './renderToCanvas'; | ||
export { mount } from './mount'; |
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,11 @@ | ||
import { type StoryContext, type ReactRenderer } from './public-types'; | ||
import type { BaseAnnotations } from '@storybook/types'; | ||
|
||
export const mount: BaseAnnotations<ReactRenderer>['mount'] = | ||
(context: StoryContext) => async (ui) => { | ||
if (ui != null) { | ||
context.originalStoryFn = () => ui; | ||
} | ||
await context.renderToCanvas(); | ||
return context.canvas; | ||
}; |
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
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
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 { type StoryContext, type SvelteRenderer } from './public-types'; | ||
import { type BaseAnnotations } from '@storybook/types'; | ||
|
||
export const mount: BaseAnnotations<SvelteRenderer>['mount'] = (context: StoryContext) => { | ||
return async (Component, options) => { | ||
if (Component) { | ||
context.originalStoryFn = () => ({ | ||
Component, | ||
props: options && 'props' in options ? options?.props : options, | ||
}); | ||
} | ||
await context.renderToCanvas(); | ||
return context.canvas; | ||
}; | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const parameters: {} = { renderer: 'vue3' }; | ||
export { render, renderToCanvas } from './render'; | ||
export { decorateStory as applyDecorators } from './decorateStory'; | ||
export { mount } from './mount'; |
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,13 @@ | ||
import { type StoryContext, type VueRenderer } from './public-types'; | ||
import { h } from 'vue'; | ||
import { type BaseAnnotations } from '@storybook/types'; | ||
|
||
export const mount: BaseAnnotations<VueRenderer>['mount'] = (context: StoryContext) => { | ||
return async (Component, options) => { | ||
if (Component) { | ||
context.originalStoryFn = () => () => h(Component, options?.props, options?.slots); | ||
} | ||
await context.renderToCanvas(); | ||
return context.canvas; | ||
}; | ||
}; |
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
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' } }); | ||
}, | ||
}; |