| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import classnames from 'classnames/dedupe'; |
| 5 |
|
| 6 |
/** |
| 7 |
* WordPress dependencies |
| 8 |
*/ |
| 9 |
const { Component } = wp.element; |
| 10 |
|
| 11 |
const { BaseControl } = wp.components; |
| 12 |
|
| 13 |
/** |
| 14 |
* Component Class |
| 15 |
*/ |
| 16 |
export default class ImagePicker extends Component { |
| 17 |
render() { |
| 18 |
const { value, options, onChange, label } = this.props; |
| 19 |
|
| 20 |
return ( |
| 21 |
<BaseControl label={label} className="ghostkit-component-image-picker"> |
| 22 |
{options.map((option) => ( |
| 23 |
// eslint-disable-next-line react/button-has-type |
| 24 |
<button |
| 25 |
key={`image-pircker-${option.value}`} |
| 26 |
onClick={() => { |
| 27 |
onChange(option.value); |
| 28 |
}} |
| 29 |
className={classnames( |
| 30 |
'ghostkit-component-image-picker-item', |
| 31 |
value === option.value ? 'ghostkit-component-image-picker-item-active' : '', |
| 32 |
option.className |
| 33 |
)} |
| 34 |
> |
| 35 |
{option.image && typeof option.image === 'string' ? ( |
| 36 |
<img src={option.image} alt={option.label || option.value} /> |
| 37 |
) : ( |
| 38 |
'' |
| 39 |
)} |
| 40 |
{option.image && typeof option.image !== 'string' ? option.image : ''} |
| 41 |
{option.label ? <span>{option.label}</span> : ''} |
| 42 |
</button> |
| 43 |
))} |
| 44 |
</BaseControl> |
| 45 |
); |
| 46 |
} |
| 47 |
} |
| 48 |
|