@@ -7,13 +7,25 @@ import {
7
7
__experimentalGrid as Grid ,
8
8
CardBody ,
9
9
Card ,
10
+ __experimentalItemGroup as ItemGroup ,
11
+ __experimentalItem as Item ,
12
+ Flex ,
13
+ FlexBlock ,
14
+ FlexItem ,
10
15
} from '@wordpress/components' ;
11
16
import { __ } from '@wordpress/i18n' ;
12
- import { useEntityProp } from '@wordpress/core-data' ;
13
17
import { useState } from '@wordpress/element' ;
14
- import { trash , chevronUp , chevronDown } from '@wordpress/icons' ;
18
+ import {
19
+ trash ,
20
+ chevronUp ,
21
+ chevronDown ,
22
+ blockDefault ,
23
+ post ,
24
+ } from '@wordpress/icons' ;
15
25
import { useEffect } from '@wordpress/element' ;
16
26
27
+ import SUPPORTED_BLOCK_ATTRIBUTES from './_supported-attributes' ;
28
+
17
29
/**
18
30
* Display a form to edit a field.
19
31
* @param {Object } props
@@ -51,6 +63,18 @@ const EditFieldForm = ( {
51
63
marginBottom : '1rem' ,
52
64
} }
53
65
>
66
+ { formData . type . indexOf ( 'core/' ) === - 1 ? (
67
+ < Button icon = { post } title = { formData . type } >
68
+ { __ ( 'Custom Field' ) }
69
+ </ Button >
70
+ ) : (
71
+ < Button
72
+ icon = { blockDefault }
73
+ title = { formData . type }
74
+ >
75
+ { __ ( 'Block Binding' ) }
76
+ </ Button >
77
+ ) }
54
78
{ index > 0 && (
55
79
< Button
56
80
icon = { chevronUp }
@@ -69,17 +93,19 @@ const EditFieldForm = ( {
69
93
} }
70
94
/>
71
95
) }
72
- < Button
73
- icon = { trash }
74
- title = { __ ( 'Delete Field' ) }
75
- onClick = { ( ) => {
76
- confirm (
77
- __ (
78
- 'Are you sure you want to delete this field?'
79
- )
80
- ) && onDelete ( formData ) ;
81
- } }
82
- />
96
+ { formData . type . indexOf ( 'core/' ) === - 1 ?? (
97
+ < Button
98
+ icon = { trash }
99
+ title = { __ ( 'Delete Field' ) }
100
+ onClick = { ( ) => {
101
+ confirm (
102
+ __ (
103
+ 'Are you sure you want to delete this field?'
104
+ )
105
+ ) && onDelete ( formData ) ;
106
+ } }
107
+ />
108
+ ) }
83
109
</ ButtonGroup >
84
110
85
111
< Grid columns = { 3 } >
@@ -97,35 +123,6 @@ const EditFieldForm = ( {
97
123
setFormData ( { ...formData , slug : value } )
98
124
}
99
125
/>
100
- < SelectControl
101
- label = { __ ( 'Type' ) }
102
- value = { formData . type }
103
- disabled = { formData . type . indexOf ( 'core/' ) === 0 }
104
- options = { [
105
- { label : __ ( 'Text' ) , value : 'text' } ,
106
- { label : __ ( 'Textarea' ) , value : 'textarea' } ,
107
- { label : __ ( 'URL' ) , value : 'url' } ,
108
- { label : __ ( 'Image' ) , value : 'image' } ,
109
- { label : __ ( 'Number' ) , value : 'number' } ,
110
- {
111
- label : __ ( 'Image Block' ) ,
112
- value : 'core/image' ,
113
- } ,
114
- {
115
- label : __ ( 'Button Block' ) ,
116
- value : 'core/button' ,
117
- } ,
118
- {
119
- label : __ ( 'Group Block' ) ,
120
- value : 'core/group' ,
121
- } ,
122
- ] }
123
- onChange = { ( value ) =>
124
- setFormData ( { ...formData , type : value } )
125
- }
126
- />
127
- </ Grid >
128
- < Grid columns = { 2 } alignment = "bottom" >
129
126
< TextControl
130
127
label = { __ ( 'Description (optional)' ) }
131
128
value = { formData . description }
@@ -136,20 +133,90 @@ const EditFieldForm = ( {
136
133
} )
137
134
}
138
135
/>
139
-
140
- < ToggleControl
141
- label = { __ ( 'Show Field in Custom Fields Form' ) }
142
- checked = { formData . visible ?? false }
143
- disabled = { formData . type . indexOf ( 'core/' ) === 0 }
144
- onChange = { ( value ) =>
145
- setFormData ( { ...formData , visible : value } )
146
- }
147
- />
148
136
</ Grid >
137
+ { formData . type . indexOf ( 'core/' ) === - 1 && (
138
+ < Grid columns = { 2 } alignment = "bottom" >
139
+ < SelectControl
140
+ label = { __ ( 'Type' ) }
141
+ value = { formData . type }
142
+ disabled = {
143
+ formData . type . indexOf ( 'core/' ) === 0
144
+ }
145
+ options = { [
146
+ { label : __ ( 'Text' ) , value : 'text' } ,
147
+ {
148
+ label : __ ( 'Textarea' ) ,
149
+ value : 'textarea' ,
150
+ } ,
151
+ { label : __ ( 'URL' ) , value : 'url' } ,
152
+ { label : __ ( 'Image' ) , value : 'image' } ,
153
+ { label : __ ( 'Number' ) , value : 'number' } ,
154
+ ] }
155
+ onChange = { ( value ) =>
156
+ setFormData ( { ...formData , type : value } )
157
+ }
158
+ />
159
+ < ToggleControl
160
+ label = { __ (
161
+ 'Show Field in Custom Fields Form'
162
+ ) }
163
+ checked = { formData . visible ?? false }
164
+ onChange = { ( value ) =>
165
+ setFormData ( {
166
+ ...formData ,
167
+ visible : value ,
168
+ } )
169
+ }
170
+ />
171
+ </ Grid >
172
+ ) }
173
+ { formData . type . indexOf ( 'core/' ) === 0 ? (
174
+ < BlockAttributes
175
+ slug = { formData . slug }
176
+ type = { formData . type }
177
+ />
178
+ ) : (
179
+ < ItemGroup isBordered isSeparated >
180
+ < Item >
181
+ < Flex >
182
+ < FlexBlock > { formData . type } </ FlexBlock >
183
+ < FlexItem >
184
+ < span >
185
+ < code > { formData . slug } </ code >
186
+ </ span >
187
+ </ FlexItem >
188
+ </ Flex >
189
+ </ Item >
190
+ </ ItemGroup >
191
+ ) }
149
192
</ CardBody >
150
193
</ Card >
151
194
</ >
152
195
) ;
153
196
} ;
154
197
198
+ const BlockAttributes = ( { slug, type } ) => {
199
+ const supportedAttributes = SUPPORTED_BLOCK_ATTRIBUTES [ type ] ;
200
+ return (
201
+ < ItemGroup isBordered isSeparated >
202
+ { supportedAttributes . map ( ( attribute ) => (
203
+ < Item key = { attribute } >
204
+ < Flex >
205
+ < FlexBlock > { attribute } </ FlexBlock >
206
+ < FlexItem >
207
+ < span >
208
+ { 'post_content' === slug ? (
209
+ < code > { slug } </ code >
210
+ ) : (
211
+ < code > { `${ slug } __${ attribute } ` } </ code >
212
+ ) }
213
+ </ span >
214
+ </ FlexItem >
215
+ </ Flex >
216
+ </ Item >
217
+ ) ) }
218
+ </ ItemGroup >
219
+ ) ;
220
+ } ;
221
+
155
222
export default EditFieldForm ;
0 commit comments