@@ -17,17 +17,18 @@ import {
17
17
import { SchemaRecordType } from '../utils/types' ;
18
18
19
19
interface SchemaControlsProps {
20
- schema : SchemaRecordType ;
21
- schemakey : string ;
22
20
isCollapsed ?: boolean ;
23
- onDelete ?: ( ) => void ;
24
21
onAdd ?: ( ) => void ;
25
- onCollapse ?: ( ) => void ;
26
22
onChangeKey ?: ( key : string ) => void ;
27
23
onChange : ( schema : SchemaRecordType ) => void ;
24
+ onCollapse ?: ( ) => void ;
25
+ onDelete ?: ( ) => void ;
26
+ root ?: boolean ;
27
+ schema : SchemaRecordType ;
28
+ schemakey : string ;
28
29
}
29
30
30
- const SchemaControls = ( { onAdd, onChange, onChangeKey, onDelete, schema, schemakey} : SchemaControlsProps ) => {
31
+ const SchemaControls = ( { onAdd, onChange, onChangeKey, onDelete, root , schema, schemakey} : SchemaControlsProps ) => {
31
32
const [ isMenuOpen , setIsMenuOpen ] = useState < boolean > ( false ) ;
32
33
33
34
const isObjectSchema = getSchemaType ( schema ) === 'object' ;
@@ -41,8 +42,8 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak
41
42
} , [ schema , onChange ] ) ;
42
43
43
44
return (
44
- < div className = "flex w-full flex-row " >
45
- < div className = " flex flex-1 gap-2" >
45
+ < div className = "flex w-full items-end " >
46
+ < div className = { twMerge ( ' flex gap-2' , root ? 'mr-1' : 'flex-1' ) } >
46
47
< SchemaTypesSelect
47
48
onChange = { ( translation ) => onChange ( setSchemaTypeAndRemoveWrongFields ( translation , schema ) ) }
48
49
type = { getSchemaType ( schema ) }
@@ -60,7 +61,12 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak
60
61
) }
61
62
</ div >
62
63
63
- < div className = "ml-auto grid shrink-0 grid-flow-col items-center gap-1" >
64
+ < div
65
+ className = { twMerge (
66
+ 'ml-auto grid shrink-0 grid-flow-col items-center gap-1' ,
67
+ root && 'ml-0 flex-1 justify-between'
68
+ ) }
69
+ >
64
70
< SchemaMenuPopover
65
71
onChange = { onChange }
66
72
onClose = { ( ) => setIsMenuOpen ( false ) }
@@ -70,11 +76,13 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak
70
76
< Button
71
77
className = { twMerge ( 'group px-2.5' , isMenuOpen && 'bg-surface-brand-secondary' ) }
72
78
onClick = { ( ) => setIsMenuOpen ( ( open ) => ! open ) }
73
- title = "Extra options "
79
+ title = "Extra fields "
74
80
variant = "ghost"
75
81
>
76
82
< CircleEllipsisIcon className = { twMerge ( isMenuOpen && 'text-content-brand-primary' ) } />
77
83
84
+ { root && < span > Extra fields</ span > }
85
+
78
86
{ extraFields . length > 0 && (
79
87
< Badge
80
88
className = { twMerge (
@@ -103,13 +111,18 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak
103
111
104
112
{ ( typeof onAdd === 'function' || isObjectSchema ) && (
105
113
< Button
114
+ className = { twMerge (
115
+ root && 'ml-auto bg-surface-brand-primary hover:bg-surface-brand-primary-hover'
116
+ ) }
106
117
disabled = { ! isObjectSchema }
107
118
onClick = { onAdd || ( ( ) => onChange ( addSchemaProperty ( schema ) ) ) }
108
- size = " icon"
119
+ size = { root ? 'default' : ' icon' }
109
120
title = "Add Property"
110
- variant = " ghost"
121
+ variant = { root ? 'default' : ' ghost' }
111
122
>
112
123
< PlusIcon />
124
+
125
+ { root && < span > Add a pill</ span > }
113
126
</ Button >
114
127
) }
115
128
</ div >
@@ -120,10 +133,11 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak
120
133
interface SchemaArrayControlsProps {
121
134
onAdd ?: ( ) => void ;
122
135
onChange : ( schema : SchemaRecordType ) => void ;
136
+ root ?: boolean ;
123
137
schema : SchemaRecordType ;
124
138
}
125
139
126
- const SchemaArrayControls = ( { onAdd, onChange, schema} : SchemaArrayControlsProps ) => {
140
+ const SchemaArrayControls = ( { onAdd, onChange, root , schema} : SchemaArrayControlsProps ) => {
127
141
const [ isMenuOpen , setIsMenuOpen ] = useState < boolean > ( false ) ;
128
142
129
143
const extraFields = Object . keys ( schema ) . filter ( ( key ) => key !== 'type' && key !== 'items' && key !== 'properties' ) ;
@@ -145,11 +159,13 @@ const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps
145
159
< Button
146
160
className = { twMerge ( 'group px-2.5' , isMenuOpen && 'bg-surface-brand-secondary' ) }
147
161
onClick = { ( ) => setIsMenuOpen ( ( open ) => ! open ) }
148
- title = "Extra options "
162
+ title = "Extra fields "
149
163
variant = "ghost"
150
164
>
151
165
< CircleEllipsisIcon className = { twMerge ( isMenuOpen && 'text-content-brand-primary' ) } />
152
166
167
+ { root && < span > Extra fields</ span > }
168
+
153
169
{ extraFields . length > 0 && (
154
170
< Badge
155
171
className = { twMerge (
0 commit comments