diff --git a/code/examples/html-kitchen-sink/stories/loaders.stories.js b/code/examples/html-kitchen-sink/stories/loaders.stories.js deleted file mode 100644 index ae8b4616195..00000000000 --- a/code/examples/html-kitchen-sink/stories/loaders.stories.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - title: 'Core/Loaders', - loaders: [async () => new Promise((r) => setTimeout(() => r({ kindValue: 7 }), 3000))], -}; - -export const Story = (args, { loaded }) => - `
Loaded Value is ${JSON.stringify(loaded, null, 2)}
`; diff --git a/code/examples/official-storybook/stories/core/loaders.stories.js b/code/examples/official-storybook/stories/core/loaders.stories.js deleted file mode 100644 index e18cdb9795a..00000000000 --- a/code/examples/official-storybook/stories/core/loaders.stories.js +++ /dev/null @@ -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 }) => ( -
Loaded Value is {JSON.stringify(loaded, null, 2)}
-); -Story.loaders = [async () => ({ storyValue: 3 })]; - -export const ZIndex = (args, { loaded }) => ( -
- This story has a very high z-index -
-); diff --git a/code/lib/store/template/stories/loaders.stories.ts b/code/lib/store/template/stories/loaders.stories.ts new file mode 100644 index 00000000000..3be29c10937 --- /dev/null +++ b/code/lib/store/template/stories/loaders.stories.ts @@ -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', + }), + ], +}; diff --git a/code/renderers/react/template/components/index.js b/code/renderers/react/template/components/index.js index 801c57b0955..cd79b6a4c33 100644 --- a/code/renderers/react/template/components/index.js +++ b/code/renderers/react/template/components/index.js @@ -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 }; diff --git a/code/renderers/react/template/components/styleDecorator.jsx b/code/renderers/react/template/components/styleDecorator.jsx new file mode 100644 index 00000000000..f9d77852f44 --- /dev/null +++ b/code/renderers/react/template/components/styleDecorator.jsx @@ -0,0 +1,9 @@ +import React from 'react'; + +export function styleDecorator(style) { + return (StoryFn) => ( +
+ +
+ ); +}