1- import { ITreeListNode , TreeStore } from '@stoplight/tree-list' ;
1+ import { IRowRendererOptions , ITreeListNode , TreeStore } from '@stoplight/tree-list' ;
22import { Omit } from '@stoplight/types' ;
3- import { Button , Checkbox , Icon } from '@stoplight/ui-kit' ;
3+ import { Button , Checkbox , Colors , Icon } from '@stoplight/ui-kit' ;
44import * as cn from 'classnames' ;
55import * as pluralize from 'pluralize' ;
66import * as React from 'react' ;
@@ -11,10 +11,13 @@ import { Divider, Types } from './';
1111
1212export interface ISchemaRow extends Omit < React . HTMLAttributes < HTMLDivElement > , 'onClick' | 'onSelect' > , IMasking {
1313 node : ITreeListNode < object > ;
14+ rowOptions : IRowRendererOptions ;
1415 onMaskEdit ( node : SchemaNodeWithMeta ) : void ;
1516 treeStore : TreeStore ;
1617}
1718
19+ const ICON_SIZE = 12 ;
20+
1821export const SchemaRow : React . FunctionComponent < ISchemaRow > = ( {
1922 node,
2023 treeStore,
@@ -53,57 +56,82 @@ export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({
5356
5457 const validationCount = 'validations' in schemaNode ? Object . keys ( schemaNode . validations ) . length : 0 ;
5558
56- return (
57- < div className = "flex flex-1 items-center text-sm leading-tight relative select-none mr-3" >
58- { showDivider && < Divider > or</ Divider > }
59-
60- < div className = "flex-1 truncate" >
61- < div className = "flex items-baseline" >
62- { name && < span className = "mr-3" > { name } </ span > }
63-
64- < Types type = { type } subtype = { subtype } >
65- { type === '$ref' ? `[${ $ref } ]` : null }
66- </ Types >
67-
68- { inheritedFrom ? (
69- < >
70- < span className = "text-darken-7 mx-2" > { `{${ formatRef ( inheritedFrom ) } }` } </ span >
71- { onMaskEdit !== undefined && < span onClick = { handleEditMask } > (edit mask)</ span > }
72- </ >
73- ) : null }
74- </ div >
75-
76- { description && < span className = "text-darken-7 text-xs" > { description } </ span > }
77- </ div >
59+ const showCaretIcon = node . level > 0 && node . canHaveChildren ? true : false ;
7860
79- { ( canSelect || validationCount || required ) && (
80- < div className = "items-center text-right ml-auto text-xs" >
81- { canSelect ? (
82- < Checkbox onChange = { handleChange } checked = { selected && selected . includes ( pathToString ( path ) ) } />
83- ) : (
84- < >
85- { validationCount ? (
86- < span className = "mr-2 text-darken-7" >
87- { validationCount } { pluralize ( 'validation' , validationCount ) }
88- </ span >
89- ) : null }
90-
91- { required && < span className = "font-semibold" > required</ span > }
92- </ >
93- ) }
94- </ div >
95- ) }
61+ const marginLeft = ICON_SIZE * node . level ;
9662
97- { ( validationCount || description ) &&
98- node . canHaveChildren && (
63+ return (
64+ < div className = "flex-1 flex items-center" style = { { marginLeft : ICON_SIZE , marginRight : ICON_SIZE } } >
65+ < div
66+ className = "flex flex-1 items-center text-sm leading-tight w-full h-full relative"
67+ style = { { marginLeft, marginRight : ICON_SIZE } }
68+ >
69+ { showCaretIcon && (
9970 < Button
71+ minimal
10072 small
101- className = { cn ( required && 'ml-2' ) }
102- id = { `${ node . id } -showMore` }
103- icon = { < Icon icon = "info-sign" className = "opacity-75" iconSize = { 12 } /> }
104- onClick = { handleButtonClick }
73+ className = "absolute"
74+ style = { { left : ICON_SIZE * - 2 } }
75+ icon = {
76+ < Icon
77+ iconSize = { ICON_SIZE }
78+ icon = { treeStore . isNodeExpanded ( node ) ? 'caret-down' : 'caret-right' }
79+ color = { Colors . GRAY1 }
80+ />
81+ }
10582 />
10683 ) }
84+
85+ { showDivider && < Divider > or</ Divider > }
86+
87+ < div className = "flex-1 truncate" >
88+ < div className = "flex items-baseline" >
89+ { name && < span className = "mr-3" > { name } </ span > }
90+
91+ < Types type = { type } subtype = { subtype } >
92+ { type === '$ref' ? `[${ $ref } ]` : null }
93+ </ Types >
94+
95+ { inheritedFrom ? (
96+ < >
97+ < span className = "text-darken-7 mx-2" > { `{${ formatRef ( inheritedFrom ) } }` } </ span >
98+ { onMaskEdit !== undefined && < span onClick = { handleEditMask } > (edit mask)</ span > }
99+ </ >
100+ ) : null }
101+ </ div >
102+
103+ { description && < span className = "text-darken-7 text-xs" > { description } </ span > }
104+ </ div >
105+
106+ { ( canSelect || validationCount || required ) && (
107+ < div className = "items-center text-right ml-auto text-xs" >
108+ { canSelect ? (
109+ < Checkbox onChange = { handleChange } checked = { selected && selected . includes ( pathToString ( path ) ) } />
110+ ) : (
111+ < >
112+ { validationCount ? (
113+ < span className = "mr-2 text-darken-7" >
114+ { validationCount } { pluralize ( 'validation' , validationCount ) }
115+ </ span >
116+ ) : null }
117+
118+ { required && < span className = "font-semibold" > required</ span > }
119+ </ >
120+ ) }
121+ </ div >
122+ ) }
123+
124+ { ( validationCount || description ) &&
125+ node . canHaveChildren && (
126+ < Button
127+ small
128+ className = { cn ( required && 'ml-2' ) }
129+ id = { `${ node . id } -showMore` }
130+ icon = { < Icon icon = "info-sign" className = "opacity-75" iconSize = { ICON_SIZE } /> }
131+ onClick = { handleButtonClick }
132+ />
133+ ) }
134+ </ div >
107135 </ div >
108136 ) ;
109137} ;
0 commit comments