PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.3
GenerateBlocks v1.5.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / advanced-select / index.js
generateblocks / src / components / advanced-select Last commit date
editor.scss 4 years ago index.js 4 years ago
index.js
80 lines
1
2 import Select from 'react-select';
3 import CreatableSelect from 'react-select/creatable';
4 import LabelAndHelpWrapper from '../LabelAndHelpWrapper';
5 import './editor.scss';
6
7 export default ( props ) => {
8 const customStyles = {
9 indicatorSeparator: () => ( {
10 display: 'none',
11 } ),
12
13 indicatorsContainer: ( provided ) => ( {
14 ...provided,
15 maxHeight: '30px',
16 } ),
17
18 menuPortal: ( base ) => ( {
19 ...base,
20 zIndex: 999999,
21 } ),
22
23 control: ( base ) => ( {
24 ...base,
25 marginBottom: '8px',
26 } ),
27 valueContainer: ( base ) => ( {
28 ...base,
29 padding: '0 6px',
30 } ),
31 input: ( base ) => ( {
32 ...base,
33 margin: 0,
34 padding: 0,
35 } ),
36 };
37
38 const customTheme = ( provided ) => ( {
39 borderRadius: 2,
40 colors: {
41 ...provided.colors,
42 primary: 'var(--wp-admin-theme-color)',
43 neutral20: '#757575',
44 neutral30: '#757575',
45 },
46 spacing: {
47 controlHeight: 30,
48 baseUnit: 3,
49 menuGutter: 3,
50 },
51 } );
52
53 const defaultProps = {
54 className: 'generate-advanced-select',
55 classNamePrefix: 'generate-advanced-select',
56 isSearchable: false,
57 styles: customStyles,
58 instanceId: 'input-field',
59 maxMenuHeight: 250,
60 theme: customTheme,
61 menuPortalTarget: document.querySelector( 'body' ),
62 };
63
64 const wrapperStyles = Object.assign( {}, {
65 marginBottom: '24px',
66 }, props?.wrapperStyles );
67
68 const SelectComponent = props?.isCreatable ? CreatableSelect : Select;
69
70 const finalProps = Object.assign( {}, defaultProps, props );
71
72 return (
73 <div style={ wrapperStyles }>
74 <LabelAndHelpWrapper label={ finalProps.label } htmlFor={ finalProps.id } help={ finalProps.help } >
75 <SelectComponent { ...finalProps } />
76 </LabelAndHelpWrapper>
77 </div>
78 );
79 };
80