Skip to content

Commit 972c0db

Browse files
chore: allow changing args in stories (#82)
1 parent d09e3bf commit 972c0db

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

src/components/NavigationTree/__stories__/NavigationTree.stories.tsx

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,77 @@
11
import React from 'react';
22

33
import {Button} from '@gravity-ui/uikit';
4-
import type {Meta, Story} from '@storybook/react';
4+
import type {Meta, StoryFn} from '@storybook/react';
55

66
import {NavigationTree} from '../NavigationTree';
77
import type {NavigationTreeProps} from '../NavigationTree';
88
import type {NavigationTreeDataItem, NavigationTreeNodeType} from '../types';
99

1010
export default {
11+
parameters: {
12+
controls: {expanded: true},
13+
},
1114
title: 'NavigationTree',
1215
component: NavigationTree,
16+
args: {
17+
cache: true,
18+
virtualize: false,
19+
rootState: {
20+
path: '',
21+
name: 'ru/maps/maps_prod',
22+
type: 'database',
23+
collapsed: false,
24+
},
25+
getActions: getActions,
26+
},
27+
argTypes: {
28+
rootState: {
29+
control: false,
30+
},
31+
fetchPath: {
32+
control: false,
33+
},
34+
getActions: {
35+
control: false,
36+
},
37+
renderAdditionalNodeElements: {
38+
control: false,
39+
},
40+
activePath: {
41+
control: false,
42+
},
43+
onActivePathUpdate: {
44+
control: false,
45+
},
46+
},
1347
} as Meta<NavigationTreeProps>;
1448

15-
export const Default: Story<NavigationTreeProps> = () => {
49+
const Template: StoryFn<NavigationTreeProps> = (props) => {
1650
const [activePath, setActivePath] = React.useState('');
1751

18-
return (
19-
<NavigationTree
20-
rootState={{
21-
path: '',
22-
name: 'ru/maps/maps_prod',
23-
type: 'database',
24-
collapsed: false,
25-
}}
26-
fetchPath={fetchPath}
27-
getActions={getActions}
28-
renderAdditionalNodeElements={renderAdditionalNodeElements}
29-
activePath={activePath}
30-
onActivePathUpdate={setActivePath}
31-
/>
32-
);
52+
return <NavigationTree activePath={activePath} onActivePathUpdate={setActivePath} {...props} />;
3353
};
3454

35-
export const Virtualized: Story<NavigationTreeProps> = () => {
36-
const [activePath, setActivePath] = React.useState('');
55+
export const Default: Meta<NavigationTreeProps> = {
56+
component: NavigationTree,
57+
render: (props) => {
58+
return <Template {...props} />;
59+
},
60+
args: {
61+
fetchPath: fetchPath,
62+
renderAdditionalNodeElements: renderAdditionalNodeElements,
63+
},
64+
};
3765

38-
return (
39-
<NavigationTree
40-
rootState={{
41-
path: '',
42-
name: 'ru/maps/maps_prod',
43-
type: 'database',
44-
collapsed: false,
45-
}}
46-
fetchPath={fetchPathWithLargeResults}
47-
getActions={getActions}
48-
activePath={activePath}
49-
onActivePathUpdate={setActivePath}
50-
virtualize
51-
/>
52-
);
66+
export const Virtualized: Meta<NavigationTreeProps> = {
67+
component: NavigationTree,
68+
render: (props) => {
69+
return <Template {...props} />;
70+
},
71+
args: {
72+
fetchPath: fetchPathWithLargeResults,
73+
virtualize: true,
74+
},
5375
};
5476

5577
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

0 commit comments

Comments
 (0)