|
4 | 4 | * Block dependencies
|
5 | 5 | */
|
6 | 6 | import './style.scss';
|
| 7 | +import { isEmpty } from 'lodash'; |
| 8 | +import { BaseControl } from '@wordpress/components'; |
| 9 | +import { withInstanceId } from '@wordpress/compose'; |
7 | 10 |
|
8 |
| -/** |
9 |
| - * Internal dependencies |
10 |
| - */ |
11 |
| -const { isEmpty } = lodash; |
12 |
| - |
13 |
| -const { BaseControl } = wp.components; |
14 |
| - |
15 |
| -const { withInstanceId } = wp.compose; |
16 |
| - |
17 |
| - |
18 |
| -function RadioImageControl( { label, selected, help, instanceId, onChange, disabled, options = [] } ) { |
19 |
| - const id = `inspector-radio-image-control-${ instanceId }`; |
20 |
| - const onChangeValue = ( event ) => onChange( event.target.value ); |
| 11 | +function RadioImageControl({ |
| 12 | + label, |
| 13 | + selected, |
| 14 | + help, |
| 15 | + instanceId, |
| 16 | + onChange, |
| 17 | + disabled, |
| 18 | + options = [], |
| 19 | +}) { |
| 20 | + const id = `inspector-radio-image-control-${instanceId}`; |
| 21 | + const onChangeValue = (event) => onChange(event.target.value); |
21 | 22 |
|
22 |
| - return ! isEmpty( options ) && ( |
23 |
| - <BaseControl label={ label } id={ id } help={ help } className="components-radio-image-control feedzy-template"> |
24 |
| - <div className="components-radio-image-control__container"> |
25 |
| - { options.map( ( option, index ) => |
26 |
| - <div |
27 |
| - key={ `${ id }-${ index }` } |
28 |
| - className="components-radio-image-control__option" |
29 |
| - > |
30 |
| - <input |
31 |
| - id={ `${ id }-${ index }` } |
32 |
| - className="components-radio-image-control__input" |
33 |
| - type="radio" |
34 |
| - name={ id } |
35 |
| - value={ option.value } |
36 |
| - onChange={ onChangeValue } |
37 |
| - checked={ option.value === selected } |
38 |
| - aria-describedby={ !! help ? `${ id }__help` : undefined } |
39 |
| - disabled={ disabled } |
40 |
| - /> |
41 |
| - <label htmlFor={ `${ id }-${ index }` } title={ option.label }> |
42 |
| - <img src={ option.src } /> |
43 |
| - <span class="image-clickable"></span> |
44 |
| - </label> |
45 |
| - <span>{ option.label }</span> |
46 |
| - </div> |
47 |
| - ) } |
48 |
| - </div> |
49 |
| - </BaseControl> |
| 23 | + return ( |
| 24 | + !isEmpty(options) && ( |
| 25 | + <BaseControl |
| 26 | + label={label} |
| 27 | + id={id} |
| 28 | + help={help} |
| 29 | + className="components-radio-image-control feedzy-template" |
| 30 | + > |
| 31 | + <div className="components-radio-image-control__container"> |
| 32 | + {options.map((option, index) => ( |
| 33 | + <div |
| 34 | + key={`${id}-${index}`} |
| 35 | + className="components-radio-image-control__option" |
| 36 | + > |
| 37 | + <input |
| 38 | + id={`${id}-${index}`} |
| 39 | + className="components-radio-image-control__input" |
| 40 | + type="radio" |
| 41 | + name={id} |
| 42 | + value={option.value} |
| 43 | + onChange={onChangeValue} |
| 44 | + checked={option.value === selected} |
| 45 | + aria-describedby={ |
| 46 | + !!help ? `${id}__help` : undefined |
| 47 | + } |
| 48 | + disabled={disabled} |
| 49 | + /> |
| 50 | + <label |
| 51 | + htmlFor={`${id}-${index}`} |
| 52 | + title={option.label} |
| 53 | + > |
| 54 | + <img src={option.src} /> |
| 55 | + <span className="image-clickable"></span> |
| 56 | + </label> |
| 57 | + <span>{option.label}</span> |
| 58 | + </div> |
| 59 | + ))} |
| 60 | + </div> |
| 61 | + </BaseControl> |
| 62 | + ) |
50 | 63 | );
|
51 | 64 | }
|
52 | 65 |
|
53 |
| -export default withInstanceId( RadioImageControl ); |
| 66 | +export default withInstanceId(RadioImageControl); |
0 commit comments