PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
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 2 years ago
index.js
84 lines
1 import Select from 'react-select';
2 import CreatableSelect from 'react-select/creatable';
3 import './editor.scss';
4 import { BaseControl } from '@wordpress/components';
5
6 export default ( props ) => {
7 const customStyles = {
8 indicatorSeparator: () => ( {
9 display: 'none',
10 } ),
11
12 indicatorsContainer: ( provided ) => ( {
13 ...provided,
14 maxHeight: '30px',
15 } ),
16
17 menuPortal: ( base ) => ( {
18 ...base,
19 zIndex: 999999,
20 } ),
21
22 control: ( base ) => ( {
23 ...base,
24 marginBottom: '8px',
25 } ),
26 valueContainer: ( base ) => ( {
27 ...base,
28 padding: '0 6px',
29 } ),
30 input: ( base ) => ( {
31 ...base,
32 margin: 0,
33 padding: 0,
34 } ),
35 };
36
37 const customTheme = ( provided ) => ( {
38 borderRadius: 2,
39 colors: {
40 ...provided.colors,
41 primary: 'var(--wp-admin-theme-color)',
42 neutral20: '#757575',
43 neutral30: '#757575',
44 },
45 spacing: {
46 controlHeight: 30,
47 baseUnit: 3,
48 menuGutter: 3,
49 },
50 } );
51
52 const defaultProps = {
53 className: 'generate-advanced-select',
54 classNamePrefix: 'generate-advanced-select',
55 isSearchable: false,
56 styles: customStyles,
57 instanceId: 'input-field',
58 maxMenuHeight: 250,
59 theme: customTheme,
60 menuPortalTarget: document.querySelector( 'body' ),
61 menuPlacement: 'auto',
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 className="gblocks-advanced-select" style={ wrapperStyles }>
74 <BaseControl
75 id={ finalProps.id }
76 label={ finalProps.label }
77 help={ finalProps.help }
78 >
79 <SelectComponent { ...finalProps } />
80 </BaseControl>
81 </div>
82 );
83 };
84