-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
62 lines (53 loc) · 1.02 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
Placeholder,
SelectControl,
Spinner
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
const ACFImageSelect = ({
label,
value,
onChange
}) => {
const { fields, isLoaded } = useSelect( select => {
const { groups } = select( 'otter-pro' ).getACFData();
const isLoaded = select( 'otter-pro' ).isACFLoaded();
const fields = [];
groups.forEach( group => {
group.fields.forEach( field => {
if ( 'image' === field.type || 'url' === field.type ) {
fields.push({
label: field.label,
value: field.key
});
}
});
});
return {
fields,
isLoaded
};
}, []);
if ( ! isLoaded ) {
return <Placeholder><Spinner /></Placeholder>;
}
return (
<SelectControl
label={ label }
value={ value }
options={ [
{
label: __( 'Select a field', 'otter-blocks' ),
value: 'none'
},
...fields
] }
onChange={ onChange }
/>
);
};
export default ACFImageSelect;