|
1 | 1 | import React from 'react'; |
2 | 2 |
|
3 | 3 | import {Button} from '@gravity-ui/uikit'; |
4 | | -import type {Meta, Story} from '@storybook/react'; |
| 4 | +import type {Meta, StoryFn} from '@storybook/react'; |
5 | 5 |
|
6 | 6 | import {NavigationTree} from '../NavigationTree'; |
7 | 7 | import type {NavigationTreeProps} from '../NavigationTree'; |
8 | 8 | import type {NavigationTreeDataItem, NavigationTreeNodeType} from '../types'; |
9 | 9 |
|
10 | 10 | export default { |
| 11 | + parameters: { |
| 12 | + controls: {expanded: true}, |
| 13 | + }, |
11 | 14 | title: 'NavigationTree', |
12 | 15 | 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 | + }, |
13 | 47 | } as Meta<NavigationTreeProps>; |
14 | 48 |
|
15 | | -export const Default: Story<NavigationTreeProps> = () => { |
| 49 | +const Template: StoryFn<NavigationTreeProps> = (props) => { |
16 | 50 | const [activePath, setActivePath] = React.useState(''); |
17 | 51 |
|
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} />; |
33 | 53 | }; |
34 | 54 |
|
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 | +}; |
37 | 65 |
|
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 | + }, |
53 | 75 | }; |
54 | 76 |
|
55 | 77 | const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); |
|
0 commit comments