mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 13:31:19 +08:00
Add parameters story
This commit is contained in:
parent
3a7958b5af
commit
7cc44aceab
@ -1,27 +0,0 @@
|
||||
import { addParameters } from '@storybook/angular';
|
||||
import type { Meta, StoryFn } from '@storybook/angular';
|
||||
import { Button } from '../../angular-demo';
|
||||
|
||||
const globalParameter = 'globalParameter';
|
||||
const chapterParameter = 'chapterParameter';
|
||||
const storyParameter = 'storyParameter';
|
||||
|
||||
addParameters({ globalParameter });
|
||||
|
||||
export default {
|
||||
title: 'Core / Parameters / All parameters',
|
||||
parameters: {
|
||||
chapterParameter,
|
||||
},
|
||||
} as Meta;
|
||||
|
||||
export const PassedToStory: StoryFn = (_args, { parameters: { fileName, ...parameters } }) => ({
|
||||
component: Button,
|
||||
props: {
|
||||
text: `Parameters are ${JSON.stringify(parameters, null, 2)}`,
|
||||
onClick: () => 0,
|
||||
},
|
||||
});
|
||||
|
||||
PassedToStory.storyName = 'All parameters passed to story';
|
||||
PassedToStory.parameters = { storyParameter };
|
@ -1,24 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
// We would need to add this in config.js idiomatically however that would make this file a bit confusing
|
||||
import { addParameters } from '@storybook/react';
|
||||
|
||||
addParameters({ globalParameter: 'globalParameter' });
|
||||
|
||||
export default {
|
||||
title: 'Core/Parameters',
|
||||
parameters: {
|
||||
chapterParameter: 'chapterParameter',
|
||||
},
|
||||
};
|
||||
|
||||
// I'm not sure what we should recommend regarding propTypes? are they a good idea for examples?
|
||||
// Given we sort of control the props, should we export a prop type?
|
||||
export const Passed = (_args, { parameters: { options, fileName, ...parameters }, ...rest }) => (
|
||||
<div>
|
||||
Parameters:
|
||||
<pre>{JSON.stringify(parameters, null, 2)}</pre>
|
||||
</div>
|
||||
);
|
||||
Passed.storyName = 'passed to story';
|
||||
Passed.parameters = { storyParameter: 'storyParameter' };
|
51
code/lib/store/template/stories/parameters.stories.ts
Normal file
51
code/lib/store/template/stories/parameters.stories.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import globalThis from 'global';
|
||||
import { PlayFunctionContext, StoryContext } from '@storybook/csf';
|
||||
import { within } from '@storybook/testing-library';
|
||||
import { expect } from '@storybook/jest';
|
||||
|
||||
// TODO: is there some way to define a project-level annotation in sandboxes?
|
||||
|
||||
export default {
|
||||
component: globalThis.Components.Code,
|
||||
parameters: {
|
||||
componentParameter: 'componentParameter',
|
||||
storyParameter: 'componentStoryParameter', // Checking this gets overridden
|
||||
storyObject: {
|
||||
a: 'component',
|
||||
b: 'component',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Inheritance = {
|
||||
parameters: {
|
||||
storyParameter: 'storyParameter',
|
||||
storyObject: {
|
||||
a: 'story',
|
||||
},
|
||||
},
|
||||
render: (_: any, context: StoryContext) => {
|
||||
const { componentParameter, storyParameter, storyObject } = context.parameters;
|
||||
return globalThis.Components.render(
|
||||
{ code: JSON.stringify({ componentParameter, storyParameter, storyObject }, null, 2) },
|
||||
context
|
||||
);
|
||||
},
|
||||
play: async ({ canvasElement }: PlayFunctionContext) => {
|
||||
const canvas = within(canvasElement);
|
||||
await expect(canvas.getByTestId('code').innerHTML).toEqual(
|
||||
JSON.stringify(
|
||||
{
|
||||
componentParameter: 'componentParameter',
|
||||
storyParameter: 'storyParameter',
|
||||
storyObject: {
|
||||
a: 'story',
|
||||
b: 'component',
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user