| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import IconPicker from '../../components/icon-picker'; |
| 4 |
import metadata from './block.json'; |
| 5 |
|
| 6 |
const { name } = metadata; |
| 7 |
|
| 8 |
import { useBlockProps } from '@wordpress/block-editor'; |
| 9 |
import { applyFilters } from '@wordpress/hooks'; |
| 10 |
|
| 11 |
/** |
| 12 |
* Block Save Class. |
| 13 |
* |
| 14 |
* @param props |
| 15 |
*/ |
| 16 |
export default function BlockSave(props) { |
| 17 |
const { attributes } = props; |
| 18 |
const { flipV, flipH } = attributes; |
| 19 |
|
| 20 |
let className = classnames('ghostkit-icon', { |
| 21 |
'ghostkit-icon-flip-vertical': flipV, |
| 22 |
'ghostkit-icon-flip-horizontal': flipH, |
| 23 |
}); |
| 24 |
|
| 25 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 26 |
...{ name }, |
| 27 |
...props, |
| 28 |
}); |
| 29 |
|
| 30 |
const blockProps = useBlockProps.save({ className }); |
| 31 |
|
| 32 |
return ( |
| 33 |
<div {...blockProps}> |
| 34 |
<Icon attributes={props.attributes} /> |
| 35 |
</div> |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
function Icon({ attributes }) { |
| 40 |
const { icon, url, target, ariaLabel, rel } = attributes; |
| 41 |
|
| 42 |
const tag = url ? 'a' : 'div'; |
| 43 |
const attrs = {}; |
| 44 |
|
| 45 |
if (tag === 'a') { |
| 46 |
attrs.href = url; |
| 47 |
attrs.target = target || null; |
| 48 |
attrs.rel = rel || null; |
| 49 |
attrs.ariaLabel = ariaLabel || null; |
| 50 |
} |
| 51 |
|
| 52 |
return ( |
| 53 |
<IconPicker.Render |
| 54 |
{...attrs} |
| 55 |
name={icon} |
| 56 |
tag={tag} |
| 57 |
className="ghostkit-icon-inner" |
| 58 |
/> |
| 59 |
); |
| 60 |
} |
| 61 |
|