mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-28 05:10:17 +08:00
Added loader stories
This commit is contained in:
parent
7cc44aceab
commit
80b64da752
@ -1,7 +0,0 @@
|
||||
export default {
|
||||
title: 'Core/Loaders',
|
||||
loaders: [async () => new Promise((r) => setTimeout(() => r({ kindValue: 7 }), 3000))],
|
||||
};
|
||||
|
||||
export const Story = (args, { loaded }) =>
|
||||
`<div>Loaded Value is ${JSON.stringify(loaded, null, 2)}</div>`;
|
@ -1,25 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
export default {
|
||||
title: 'Core/Loaders',
|
||||
loaders: [async () => new Promise((r) => setTimeout(() => r({ kindValue: 7 }), 3000))],
|
||||
};
|
||||
|
||||
export const Story = (args, { loaded }) => (
|
||||
<div>Loaded Value is {JSON.stringify(loaded, null, 2)}</div>
|
||||
);
|
||||
Story.loaders = [async () => ({ storyValue: 3 })];
|
||||
|
||||
export const ZIndex = (args, { loaded }) => (
|
||||
<div
|
||||
style={{
|
||||
position: 'relative',
|
||||
zIndex: 1000,
|
||||
width: '100px',
|
||||
height: '100px',
|
||||
background: 'coral',
|
||||
}}
|
||||
>
|
||||
This story has a very high <code>z-index</code>
|
||||
</div>
|
||||
);
|
33
code/lib/store/template/stories/loaders.stories.ts
Normal file
33
code/lib/store/template/stories/loaders.stories.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import globalThis from 'global';
|
||||
import { PlayFunctionContext, StoryContext } from '@storybook/csf';
|
||||
import { within } from '@storybook/testing-library';
|
||||
import { expect } from '@storybook/jest';
|
||||
|
||||
export default {
|
||||
component: globalThis.Components.Code,
|
||||
loaders: [async () => new Promise((r) => setTimeout(() => r({ componentValue: 7 }), 3000))],
|
||||
render: (_: any, context: StoryContext) =>
|
||||
globalThis.Components.render({ code: JSON.stringify(context.loaded, null, 2) }, context),
|
||||
};
|
||||
|
||||
export const Inheritance = {
|
||||
loaders: [async () => new Promise((r) => setTimeout(() => r({ storyValue: 3 }), 1000))],
|
||||
play: async ({ canvasElement }: PlayFunctionContext) => {
|
||||
const canvas = within(canvasElement);
|
||||
await expect(canvas.getByTestId('code').innerHTML).toEqual(
|
||||
JSON.stringify({ componentValue: 7, storyValue: 3 }, null, 2)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const ZIndex = {
|
||||
decorators: [
|
||||
globalThis.Components.styleDecorator({
|
||||
position: 'relative',
|
||||
zIndex: 1000,
|
||||
width: '500px',
|
||||
height: '500px',
|
||||
background: 'coral',
|
||||
}),
|
||||
],
|
||||
};
|
@ -4,5 +4,6 @@ import { render } from '@storybook/react/preview';
|
||||
|
||||
import { Button } from './Button.jsx';
|
||||
import { Code } from './Code.jsx';
|
||||
import { styleDecorator } from './styleDecorator.jsx';
|
||||
|
||||
globalThis.Components = { Button, Code, render };
|
||||
globalThis.Components = { Button, Code, styleDecorator, render };
|
||||
|
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
export function styleDecorator(style) {
|
||||
return (StoryFn) => (
|
||||
<div style={style}>
|
||||
<StoryFn />
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user