@@ -3,70 +3,14 @@ import merge from 'merge';
33
44import { bemClasses } from '../../helpers' ;
55import { TypeWithKey , Schema } from '../../types' ;
6- import {
7- Markdown ,
8- TableAccessor ,
9- TableRow ,
10- TreeSpace ,
11- TreeLeaf ,
12- } from '../../components' ;
6+ import { Markdown , TreeSpace , TreeLeaf } from '../../components' ;
137
148type SchemaWithKey = TypeWithKey < string , Schema > ;
159interface SchemaElement {
1610 schema : SchemaWithKey ;
1711 treeSpace : number ;
1812}
1913
20- const schemaPropertiesAccessors : Array < TableAccessor < SchemaElement > > = [
21- el => (
22- < >
23- { ( ( ) => {
24- const treeSpaces = [ ] ;
25- if ( el . treeSpace ) {
26- for ( let i = 0 ; i < el . treeSpace ; i ++ ) {
27- treeSpaces . push ( < TreeSpace key = { i } /> ) ;
28- }
29- treeSpaces . push ( < TreeLeaf key = { el . treeSpace } /> ) ;
30- }
31- return treeSpaces ;
32- } ) ( ) }
33- { el . schema . key }
34- </ >
35- ) ,
36- el => < span > { el . schema . content . title } </ span > ,
37- el => (
38- < span >
39- { el . schema . content . type }
40- { el . schema . content . anyOf ? ` ${ el . schema . content . anyOf } ` : '' }
41- { el . schema . content . oneOf ? ` ${ el . schema . content . oneOf } ` : '' }
42- { el . schema . content . items && el . schema . content . items . type
43- ? ` (${ el . schema . content . items . type } )`
44- : '' }
45- </ span >
46- ) ,
47- el => < span > { el . schema . content . format } </ span > ,
48- el => < span > { el . schema . content . default } </ span > ,
49- el => {
50- const enumElements = getEnumHTMLElements ( el . schema ) ;
51- return (
52- < div >
53- { el . schema . content . description && (
54- < Markdown > { el . schema . content . description } </ Markdown >
55- ) }
56- { enumElements . length > 0 && < div > Enum: { enumElements } </ div > }
57- { el . schema . content . pattern && (
58- < div >
59- Must Match{ ' ' }
60- < span className = { bemClasses . element ( `pattern` ) } >
61- { el . schema . content . pattern }
62- </ span >
63- </ div >
64- ) }
65- </ div >
66- ) ;
67- } ,
68- ] ;
69-
7014const getEnumHTMLElements = ( schema : SchemaWithKey ) : HTMLElement [ ] => {
7115 let enumElements : any [ ] = [ ] ;
7216 if ( schema . content . enum && schema . content . enum . length ) {
@@ -151,6 +95,39 @@ interface Props {
15195 description ?: React . ReactNode ;
15296}
15397
98+ const renderPropertyName = ( el : SchemaElement ) : React . ReactNode => (
99+ < >
100+ { ( ( ) => {
101+ const treeSpaces = [ ] ;
102+ if ( el . treeSpace ) {
103+ for ( let i = 0 ; i < el . treeSpace ; i ++ ) {
104+ treeSpaces . push ( < TreeSpace key = { i } /> ) ;
105+ }
106+ treeSpaces . push ( < TreeLeaf key = { el . treeSpace } /> ) ;
107+ }
108+ return treeSpaces ;
109+ } ) ( ) }
110+ { el . schema . key }
111+ </ >
112+ ) ;
113+
114+ const renderPropertyDescription = ( el : SchemaElement ) : React . ReactNode => {
115+ const enumElements = getEnumHTMLElements ( el . schema ) ;
116+ return (
117+ < div >
118+ { el . schema . content . description && (
119+ < Markdown > { el . schema . content . description } </ Markdown >
120+ ) }
121+ { enumElements . length > 0 && < div > Enum: { enumElements } </ div > }
122+ { el . schema . content . default && (
123+ < div >
124+ Default: < span > { el . schema . content . default } </ span >
125+ </ div >
126+ ) }
127+ </ div >
128+ ) ;
129+ } ;
130+
154131export const SchemaPropertiesComponent : React . FunctionComponent < Props > = ( {
155132 name,
156133 properties,
@@ -167,12 +144,45 @@ export const SchemaPropertiesComponent: React.FunctionComponent<Props> = ({
167144 } ;
168145
169146 return (
170- < >
171- < TableRow accessors = { schemaPropertiesAccessors } element = { element } />
147+ < div >
148+ < div className = "flex py-2" >
149+ < div className = "flex-1" > { renderPropertyName ( element ) } </ div >
150+ < div className = "flex-1" >
151+ < span className = "capitalize text-sm text-teal font-bold" >
152+ { element . schema . content . type }
153+ { element . schema . content . anyOf
154+ ? ` ${ element . schema . content . anyOf } `
155+ : '' }
156+ { element . schema . content . oneOf
157+ ? ` ${ element . schema . content . oneOf } `
158+ : '' }
159+ { element . schema . content . items && element . schema . content . items . type
160+ ? ` (${ element . schema . content . items . type } )`
161+ : '' }
162+ </ span >
163+ { element . schema . content . format && (
164+ < span
165+ className = "bg-yellow-dark font-bold no-underline text-black rounded lowercase ml-2"
166+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
167+ >
168+ { element . schema . content . format }
169+ </ span >
170+ ) }
171+ { element . schema . content . pattern && (
172+ < span
173+ className = "bg-purple-dark font-bold no-underline text-white rounded normal-case ml-2"
174+ style = { { height : '20px' , fontSize : '11px' , padding : '3px' } }
175+ >
176+ must match { element . schema . content . pattern }
177+ </ span >
178+ ) }
179+ < div className = "py-2" > { renderPropertyDescription ( element ) } </ div >
180+ </ div >
181+ </ div >
172182 { renderOf ( space , alteredProperties . anyOf ) }
173183 { renderOf ( space , alteredProperties . oneOf ) }
174184 { renderProperties ( alteredProperties , space ) }
175185 { renderItems ( alteredProperties , space ) }
176- </ >
186+ </ div >
177187 ) ;
178188} ;
0 commit comments