11import { Button , Flex , InvertTheme , subscribeTheme } from '@stoplight/mosaic' ;
22import { 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' ;
44import { storiesOf } from '@storybook/react' ;
55import { JSONSchema4 } from 'json-schema' ;
66import * as React from 'react' ;
77
8- import { JsonSchemaViewer , RowRenderer , SchemaRow } from '../' ;
8+ import { JsonSchemaViewer , RowAddonRenderer } from '../' ;
99import { Wrapper } from './utils/Wrapper' ;
1010
1111const allOfSchema = require ( '../__fixtures__/combiners/allOfs/base.json' ) ;
1212const schema = require ( '../__fixtures__/default-schema.json' ) ;
1313const 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' ) ;
1418
1519subscribeTheme ( { mode : 'light' } ) ;
1620
@@ -21,7 +25,6 @@ storiesOf('JsonSchemaViewer', module)
2125 < JsonSchemaViewer
2226 schema = { schema as JSONSchema4 }
2327 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 0 ) }
24- onGoToRef = { action ( 'onGoToRef' ) }
2528 viewMode = { select (
2629 'viewMode' ,
2730 {
@@ -31,58 +34,48 @@ storiesOf('JsonSchemaViewer', module)
3134 } ,
3235 'standalone' ,
3336 ) }
37+ onGoToRef = { action ( 'onGoToRef' ) }
3438 />
3539 ) )
3640 . add ( 'custom schema' , ( ) => (
3741 < JsonSchemaViewer
3842 schema = { object ( 'schema' , { } ) }
3943 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 0 ) }
4044 onGoToRef = { action ( 'onGoToRef' ) }
41- maxRows = { number ( 'maxRows' , 5 ) }
42- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
4345 />
4446 ) )
45- . add ( 'custom row renderer ' , ( ) => {
46- const customRowRenderer : RowRenderer = ( node , rowOptions ) => {
47+ . add ( 'custom row addon ' , ( ) => {
48+ const customRowAddonRenderer : RowAddonRenderer = ( ) => {
4749 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 >
5554 ) ;
5655 } ;
5756
5857 return (
5958 < JsonSchemaViewer
6059 schema = { object ( 'schema' , schema as JSONSchema4 ) }
6160 onGoToRef = { action ( 'onGoToRef' ) }
62- maxRows = { number ( 'maxRows' , 5 ) }
63- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
64- rowRenderer = { customRowRenderer }
61+ renderRowAddon = { customRowAddonRenderer }
6562 />
6663 ) ;
6764 } )
6865 . add ( 'stress-test schema' , ( ) => (
6966 < >
70- < div style = { { height : 345 } } >
67+ < div style = { { height : 345 , overflowY : 'scroll' } } >
7168 < JsonSchemaViewer
7269 schema = { stressSchema as JSONSchema4 }
7370 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
7471 onGoToRef = { action ( 'onGoToRef' ) }
75- maxRows = { number ( 'maxRows' , 10 ) }
76- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
7772 />
7873 </ div >
79- < div style = { { height : 345 } } >
74+ < div style = { { height : 345 , overflowY : 'scroll' } } >
8075 < JsonSchemaViewer
8176 schema = { stressSchema as JSONSchema4 }
8277 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
8378 onGoToRef = { action ( 'onGoToRef' ) }
84- maxRows = { number ( 'maxRows' , 10 ) }
85- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
8679 />
8780 </ div >
8881 </ >
@@ -91,7 +84,13 @@ storiesOf('JsonSchemaViewer', module)
9184 < JsonSchemaViewer
9285 schema = { allOfSchema as JSONSchema4 }
9386 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 ) }
9594 onGoToRef = { action ( 'onGoToRef' ) }
9695 />
9796 ) )
@@ -108,7 +107,6 @@ storiesOf('JsonSchemaViewer', module)
108107 ) }
109108 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
110109 onGoToRef = { action ( 'onGoToRef' ) }
111- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
112110 />
113111 ) )
114112 . add ( 'invalid types property pretty error message' , ( ) => (
@@ -140,7 +138,6 @@ storiesOf('JsonSchemaViewer', module)
140138 } }
141139 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
142140 onGoToRef = { action ( 'onGoToRef' ) }
143- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
144141 />
145142 ) )
146143 . add ( 'dark' , ( ) => {
@@ -151,9 +148,29 @@ storiesOf('JsonSchemaViewer', module)
151148 schema = { schema as JSONSchema4 }
152149 defaultExpandedDepth = { number ( 'defaultExpandedDepth' , 2 ) }
153150 onGoToRef = { action ( 'onGoToRef' ) }
154- mergeAllOf = { boolean ( 'mergeAllOf' , true ) }
155151 />
156152 </ div >
157153 </ InvertTheme >
158154 ) ;
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