| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { BaseControl } from '@wordpress/components'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Component Class |
| 7 |
* |
| 8 |
* @param props |
| 9 |
*/ |
| 10 |
export default function ImagePicker(props) { |
| 11 |
const { value, options, itemsPerRow = 2, onChange, label } = props; |
| 12 |
|
| 13 |
return ( |
| 14 |
<BaseControl |
| 15 |
id={label} |
| 16 |
label={label} |
| 17 |
className={classnames( |
| 18 |
'ghostkit-component-image-picker', |
| 19 |
`ghostkit-component-image-picker-${itemsPerRow}` |
| 20 |
)} |
| 21 |
> |
| 22 |
{options.map((option) => ( |
| 23 |
<button |
| 24 |
key={`image-pircker-${option.value}`} |
| 25 |
onClick={() => { |
| 26 |
onChange(option.value); |
| 27 |
}} |
| 28 |
className={classnames( |
| 29 |
'ghostkit-component-image-picker-item', |
| 30 |
value === option.value |
| 31 |
? 'ghostkit-component-image-picker-item-active' |
| 32 |
: '', |
| 33 |
option.className |
| 34 |
)} |
| 35 |
> |
| 36 |
{option.image && typeof option.image === 'string' ? ( |
| 37 |
<img |
| 38 |
src={option.image} |
| 39 |
alt={option.label || option.value} |
| 40 |
/> |
| 41 |
) : null} |
| 42 |
{option.image && typeof option.image !== 'string' |
| 43 |
? option.image |
| 44 |
: ''} |
| 45 |
{option.label ? <span>{option.label}</span> : ''} |
| 46 |
</button> |
| 47 |
))} |
| 48 |
</BaseControl> |
| 49 |
); |
| 50 |
} |
| 51 |
|