| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { useBlockProps } from '@wordpress/block-editor'; |
| 4 |
import { Placeholder, SelectControl } from '@wordpress/components'; |
| 5 |
import { __ } from '@wordpress/i18n'; |
| 6 |
|
| 7 |
import getIcon from '../../utils/get-icon'; |
| 8 |
|
| 9 |
const { GHOSTKIT } = window; |
| 10 |
|
| 11 |
/** |
| 12 |
* Block Edit Class. |
| 13 |
* |
| 14 |
* @param props |
| 15 |
*/ |
| 16 |
export default function BlockEdit(props) { |
| 17 |
const { setAttributes, attributes } = props; |
| 18 |
|
| 19 |
let { className } = props; |
| 20 |
|
| 21 |
const { id } = attributes; |
| 22 |
|
| 23 |
className = classnames('ghostkit-widgetized-area', className); |
| 24 |
|
| 25 |
const blockProps = useBlockProps({ className }); |
| 26 |
|
| 27 |
return ( |
| 28 |
<div {...blockProps}> |
| 29 |
<Placeholder |
| 30 |
icon={getIcon('block-widgetized-area')} |
| 31 |
label={__('Widgetized Area', 'ghostkit')} |
| 32 |
> |
| 33 |
<SelectControl |
| 34 |
value={id} |
| 35 |
onChange={(value) => setAttributes({ id: value })} |
| 36 |
options={(() => { |
| 37 |
const sidebars = [ |
| 38 |
{ |
| 39 |
label: __('--- Select Sidebar ---', 'ghostkit'), |
| 40 |
value: '', |
| 41 |
}, |
| 42 |
]; |
| 43 |
|
| 44 |
if (GHOSTKIT.sidebars) { |
| 45 |
Object.keys(GHOSTKIT.sidebars).forEach((k) => { |
| 46 |
sidebars.push({ |
| 47 |
label: GHOSTKIT.sidebars[k].name, |
| 48 |
value: GHOSTKIT.sidebars[k].id, |
| 49 |
}); |
| 50 |
}); |
| 51 |
} |
| 52 |
|
| 53 |
return sidebars; |
| 54 |
})()} |
| 55 |
/> |
| 56 |
</Placeholder> |
| 57 |
</div> |
| 58 |
); |
| 59 |
} |
| 60 |
|