|
1 | 1 | import React from 'react'; |
2 | 2 | import { StoryFn, Meta, StoryObj } from '@storybook/react'; |
3 | | -import { useArgs } from '@storybook/preview-api'; |
4 | 3 |
|
5 | | -import { |
6 | | - JsonView, |
7 | | - defaultStyles, |
8 | | - darkStyles, |
9 | | - allExpanded, |
10 | | - collapseAllNested, |
11 | | - NodeExpandingEvent |
12 | | -} from '../index'; |
| 4 | +import { JsonView, defaultStyles, darkStyles, allExpanded, collapseAllNested } from '../index'; |
13 | 5 |
|
14 | 6 | export default { |
15 | 7 | title: 'Json View', |
@@ -133,35 +125,24 @@ ClickOnFieldNameToExpand.args = { |
133 | 125 | clickToExpandNode: true |
134 | 126 | }; |
135 | 127 |
|
| 128 | +const tmp = { |
| 129 | + a: <a href='https://www.google.com'>Google</a> |
| 130 | +}; |
| 131 | + |
| 132 | +const JsonViewer: React.FC = () => { |
| 133 | + return ( |
| 134 | + <div> |
| 135 | + <JsonView data={tmp} shouldExpandNode={collapseAllNested} /> |
| 136 | + </div> |
| 137 | + ); |
| 138 | +}; |
| 139 | + |
136 | 140 | type JsonViewStory = StoryObj<typeof JsonView>; |
137 | 141 |
|
138 | 142 | export const ExpandOnlyFirstLevelWhenClickOnRoot: JsonViewStory = { |
139 | | - args: { |
140 | | - data: jsonData, |
141 | | - style: { ...defaultStyles }, |
142 | | - shouldExpandNode: collapseAll, |
143 | | - clickToExpandNode: true |
144 | | - }, |
145 | | - argTypes: {}, |
146 | | - name: 'Expand only first level on root click (using beforeExpandChange)', |
147 | | - |
148 | | - render: function Render(args) { |
149 | | - const [{ shouldExpandNode }, updateArgs] = useArgs(); |
150 | | - |
151 | | - const beforeExpandChange = (event: NodeExpandingEvent) => { |
152 | | - if (event.level === 0 && event.newExpandValue) { |
153 | | - updateArgs({ shouldExpandNode: (level: number) => level < 1 }); |
154 | | - return false; |
155 | | - } |
156 | | - return true; |
157 | | - }; |
158 | | - |
159 | | - return ( |
160 | | - <JsonView |
161 | | - {...args} |
162 | | - beforeExpandChange={beforeExpandChange} |
163 | | - shouldExpandNode={shouldExpandNode} |
164 | | - /> |
165 | | - ); |
| 143 | + name: 'Bug test', |
| 144 | + |
| 145 | + render: function Render() { |
| 146 | + return <JsonViewer />; |
166 | 147 | } |
167 | 148 | }; |
0 commit comments