-
Notifications
You must be signed in to change notification settings - Fork 4k
/
enumeration-field.js
42 lines (41 loc) · 1017 Bytes
/
enumeration-field.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* WordPress dependencies
*/
import { Button, __experimentalVStack as VStack } from '@wordpress/components';
import { check } from '@wordpress/icons';
export function EnumerationFieldEdit( { item, field } ) {
const currentValue = field.getValue( { item } );
return (
<VStack
spacing={ 2 }
justify="flex-start"
className="enumeration-field-edit-wrapper"
>
{ ( field.editElements || field.elements ).map( ( element ) => {
return (
<Button
key={ element.value.toString() }
className="enumeration-field-edit-item"
onClick={ () => {
if ( element.value !== currentValue ) {
field.setValue( {
value: element.value,
item,
} );
}
} }
icon={
element.value === currentValue ? check : undefined
}
style={ {
backgroundColor: element.color || undefined,
} }
disabled={ element.value === currentValue }
>
{ element.label }
</Button>
);
} ) }
</VStack>
);
}