-
Notifications
You must be signed in to change notification settings - Fork 87
/
editor-select.js
58 lines (54 loc) · 1.38 KB
/
editor-select.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
/**
* Internal imports
*/
import * as modelSelect from '../model-select';
/**
* External imports
*/
import { Component } from '@wordpress/element';
import { BaseControl, withInstanceId } from '@wordpress/components';
import { PropTypes } from 'prop-types';
/**
* ModelSelect Component wrapped in a BaseControl component.
*/
class EditorSelect extends Component {
static propTypes = {
modelName: PropTypes.string,
selectLabel: PropTypes.string,
instanceId: PropTypes.oneOfType( [
PropTypes.number,
PropTypes.string,
] ),
className: PropTypes.string,
help: PropTypes.string,
};
render() {
const { modelName, selectLabel, instanceId, className, help, children } = this.props;
const id = `inspector-${ modelName }-select-control-${ instanceId }`;
if ( help ) {
this.props[ 'aria-describedby' ] = id + '__help';
}
return (
<BaseControl
label={ selectLabel }
id={ id }
className={ className }
help={ help }
>
{ children }
</BaseControl>
);
}
}
export default withInstanceId( EditorSelect );
export const getEditorSelectProps = ( selectProps ) => {
const editorProps = {
modelName: selectProps.modelName,
selectLabel: selectProps.selectLabel,
className: selectProps.className,
help: selectProps.help,
};
selectProps.selectLabel = modelSelect.MODEL_SELECT_LABEL_NONE;
delete selectProps.help;
return { editorProps, selectProps };
};