1
1
import { Button , Flex , InvertTheme , subscribeTheme } from '@stoplight/mosaic' ;
2
2
import { action } from '@storybook/addon-actions' ;
3
- import { boolean , number , object , select , withKnobs } from '@storybook/addon-knobs' ;
3
+ import { number , object , select , withKnobs } from '@storybook/addon-knobs' ;
4
4
import { storiesOf } from '@storybook/react' ;
5
5
import { JSONSchema4 } from 'json-schema' ;
6
6
import * as React from 'react' ;
7
7
8
- import { JsonSchemaViewer , RowRenderer , SchemaRow } from '../' ;
8
+ import { JsonSchemaViewer , RowAddonRenderer } from '../' ;
9
9
import { Wrapper } from './utils/Wrapper' ;
10
10
11
11
const allOfSchema = require ( '../__fixtures__/combiners/allOfs/base.json' ) ;
12
12
const schema = require ( '../__fixtures__/default-schema.json' ) ;
13
13
const stressSchema = require ( '../__fixtures__/stress-schema.json' ) ;
14
+ const refSchema = require ( '../__fixtures__/references/base.json' ) ;
15
+ const nullRefSchema = require ( '../__fixtures__/references/nullish.json' ) ;
16
+ const brokenRefArraySchema = require ( '../__fixtures__/arrays/of-refs.json' ) ;
17
+ const oneOfWithArraySchema = require ( '../__fixtures__/combiners/oneof-with-array-type.json' ) ;
14
18
15
19
subscribeTheme ( { mode : 'light' } ) ;
16
20
@@ -21,7 +25,6 @@ storiesOf('JsonSchemaViewer', module)
21
25
< JsonSchemaViewer
22
26
schema = { schema as JSONSchema4 }
23
27
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 0 ) }
24
- onGoToRef = { action ( 'onGoToRef' ) }
25
28
viewMode = { select (
26
29
'viewMode' ,
27
30
{
@@ -31,58 +34,48 @@ storiesOf('JsonSchemaViewer', module)
31
34
} ,
32
35
'standalone' ,
33
36
) }
37
+ onGoToRef = { action ( 'onGoToRef' ) }
34
38
/>
35
39
) )
36
40
. add ( 'custom schema' , ( ) => (
37
41
< JsonSchemaViewer
38
42
schema = { object ( 'schema' , { } ) }
39
43
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 0 ) }
40
44
onGoToRef = { action ( 'onGoToRef' ) }
41
- maxRows = { number ( 'maxRows' , 5 ) }
42
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
43
45
/>
44
46
) )
45
- . add ( 'custom row renderer ' , ( ) => {
46
- const customRowRenderer : RowRenderer = ( node , rowOptions ) => {
47
+ . add ( 'custom row addon ' , ( ) => {
48
+ const customRowAddonRenderer : RowAddonRenderer = ( ) => {
47
49
return (
48
- < >
49
- < SchemaRow treeListNode = { node } rowOptions = { rowOptions } />
50
- < Flex h = "full" alignItems = "center" >
51
- < Button pl = { 1 } mr = { 1 } size = "sm" appearance = "minimal" icon = "issue" />
52
- < input type = "checkbox" />
53
- </ Flex >
54
- </ >
50
+ < Flex h = "full" alignItems = "center" >
51
+ < Button pl = { 1 } mr = { 1 } size = "sm" appearance = "minimal" icon = "issue" />
52
+ < input type = "checkbox" />
53
+ </ Flex >
55
54
) ;
56
55
} ;
57
56
58
57
return (
59
58
< JsonSchemaViewer
60
59
schema = { object ( 'schema' , schema as JSONSchema4 ) }
61
60
onGoToRef = { action ( 'onGoToRef' ) }
62
- maxRows = { number ( 'maxRows' , 5 ) }
63
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
64
- rowRenderer = { customRowRenderer }
61
+ renderRowAddon = { customRowAddonRenderer }
65
62
/>
66
63
) ;
67
64
} )
68
65
. add ( 'stress-test schema' , ( ) => (
69
66
< >
70
- < div style = { { height : 345 } } >
67
+ < div style = { { height : 345 , overflowY : 'scroll' } } >
71
68
< JsonSchemaViewer
72
69
schema = { stressSchema as JSONSchema4 }
73
70
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
74
71
onGoToRef = { action ( 'onGoToRef' ) }
75
- maxRows = { number ( 'maxRows' , 10 ) }
76
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
77
72
/>
78
73
</ div >
79
- < div style = { { height : 345 } } >
74
+ < div style = { { height : 345 , overflowY : 'scroll' } } >
80
75
< JsonSchemaViewer
81
76
schema = { stressSchema as JSONSchema4 }
82
77
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
83
78
onGoToRef = { action ( 'onGoToRef' ) }
84
- maxRows = { number ( 'maxRows' , 10 ) }
85
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
86
79
/>
87
80
</ div >
88
81
</ >
@@ -91,7 +84,13 @@ storiesOf('JsonSchemaViewer', module)
91
84
< JsonSchemaViewer
92
85
schema = { allOfSchema as JSONSchema4 }
93
86
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
94
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
87
+ onGoToRef = { action ( 'onGoToRef' ) }
88
+ />
89
+ ) )
90
+ . add ( 'anyOf-array-schema' , ( ) => (
91
+ < JsonSchemaViewer
92
+ schema = { oneOfWithArraySchema as JSONSchema4 }
93
+ defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
95
94
onGoToRef = { action ( 'onGoToRef' ) }
96
95
/>
97
96
) )
@@ -108,7 +107,6 @@ storiesOf('JsonSchemaViewer', module)
108
107
) }
109
108
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
110
109
onGoToRef = { action ( 'onGoToRef' ) }
111
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
112
110
/>
113
111
) )
114
112
. add ( 'invalid types property pretty error message' , ( ) => (
@@ -140,7 +138,6 @@ storiesOf('JsonSchemaViewer', module)
140
138
} }
141
139
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
142
140
onGoToRef = { action ( 'onGoToRef' ) }
143
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
144
141
/>
145
142
) )
146
143
. add ( 'dark' , ( ) => {
@@ -151,9 +148,29 @@ storiesOf('JsonSchemaViewer', module)
151
148
schema = { schema as JSONSchema4 }
152
149
defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
153
150
onGoToRef = { action ( 'onGoToRef' ) }
154
- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
155
151
/>
156
152
</ div >
157
153
</ InvertTheme >
158
154
) ;
159
- } ) ;
155
+ } )
156
+ . add ( 'refs/normal' , ( ) => (
157
+ < JsonSchemaViewer
158
+ schema = { refSchema as JSONSchema4 }
159
+ defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
160
+ onGoToRef = { action ( 'onGoToRef' ) }
161
+ />
162
+ ) )
163
+ . add ( 'refs/nullish' , ( ) => (
164
+ < JsonSchemaViewer
165
+ schema = { nullRefSchema as JSONSchema4 }
166
+ defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
167
+ onGoToRef = { action ( 'onGoToRef' ) }
168
+ />
169
+ ) )
170
+ . add ( 'refs/broken' , ( ) => (
171
+ < JsonSchemaViewer
172
+ schema = { brokenRefArraySchema as JSONSchema4 }
173
+ defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
174
+ onGoToRef = { action ( 'onGoToRef' ) }
175
+ />
176
+ ) ) ;
0 commit comments