PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.1
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.1
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / gutenberg / src / components / select-control / index.js

index.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.1, at modules/gutenberg/src/components/select-control/index.js

64 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useLayoutEffect } from 'react';
2 import { SelectControl } from '@wordpress/components';
3 import styles from './editor.lazy.scss';
4 import PropTypes from 'prop-types';
5
6 // Use the onChange prop only if needed.
7 // When using the onChange prop, you may skip the label KV-Pair of the data prop and the setAttributes prop.
8 // Children can now be declared as Options or OptGroups, as in the WP Select Control. Skip the options prop in this case.
9
10 const propTypes = {
11 label: PropTypes.string,
12 layout: PropTypes.string,
13 options: PropTypes.array,
14 data: PropTypes.object,
15 setAttributes: PropTypes.func,
16 onChange: PropTypes.func,
17 help: PropTypes.string,
18 };
19
20 const defaultProps = {
21 layout: 'inline',
22 onChange: null,
23 };
24
25 export default function UAGSelectControl( { layout, label, options, data, setAttributes, onChange, help, children } ) {
26 useLayoutEffect( () => {
27 styles.use();
28 return () => {
29 styles.unuse();
30 };
31 }, [] );
32 return (
33 children ? (
34 <div className={ `uagb-select-control uagb-select-control--layout-${ layout }` }>
35 <SelectControl
36 label={ label }
37 value={ data.value }
38 onChange={ ( value ) => (
39 onChange ? onChange( value ) : setAttributes( { [data.label]: value } )
40 ) }
41 help={ help }
42 >
43 { children }
44 </SelectControl>
45 </div>
46 ) : (
47 <div className={ `uagb-select-control uagb-select-control--layout-${ layout }` }>
48 <SelectControl
49 label={ label }
50 value={ data.value }
51 onChange={ ( value ) => (
52 onChange ? onChange( value ) : setAttributes( { [data.label]: value } )
53 ) }
54 options={ options }
55 help={ help }
56 />
57 </div>
58 )
59 );
60 }
61
62 UAGSelectControl.propTypes = propTypes;
63 UAGSelectControl.defaultProps = defaultProps;
64