| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { InnerBlocks } from '@wordpress/block-editor'; |
| 4 |
import { Component } from '@wordpress/element'; |
| 5 |
import { applyFilters } from '@wordpress/hooks'; |
| 6 |
|
| 7 |
import IconPicker from '../../components/icon-picker'; |
| 8 |
import metadata from './block.json'; |
| 9 |
|
| 10 |
const { name } = metadata; |
| 11 |
|
| 12 |
export default [ |
| 13 |
// v2.23.2 |
| 14 |
{ |
| 15 |
...metadata, |
| 16 |
attributes: { |
| 17 |
icon: { |
| 18 |
type: 'string', |
| 19 |
default: |
| 20 |
'%3Csvg%20class%3D%22ghostkit-svg-icon%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M16.7813%209.75C16.7813%207.10939%2014.6406%204.96875%2012%204.96875C9.35939%204.96875%207.21875%207.10939%207.21875%209.75C7.21875%2012.3906%209.35939%2014.5312%2012%2014.5312C14.6406%2014.5312%2016.7813%2012.3906%2016.7813%209.75Z%22%20stroke%3D%22currentColor%22%20stroke-width%3D%221.5%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3Cpath%20d%3D%22M8.15625%2018C10.6023%2019.25%2013.3977%2019.25%2015.8437%2018%22%20stroke%3D%22currentColor%22%20stroke-width%3D%221.5%22%20stroke-linecap%3D%22round%22%2F%3E%3C%2Fsvg%3E', |
| 21 |
}, |
| 22 |
iconPosition: { |
| 23 |
type: 'string', |
| 24 |
default: 'left', |
| 25 |
}, |
| 26 |
iconSize: { |
| 27 |
type: 'number', |
| 28 |
}, |
| 29 |
showContent: { |
| 30 |
type: 'boolean', |
| 31 |
default: true, |
| 32 |
}, |
| 33 |
iconColor: { |
| 34 |
type: 'string', |
| 35 |
}, |
| 36 |
hoverIconColor: { |
| 37 |
type: 'string', |
| 38 |
}, |
| 39 |
url: { |
| 40 |
type: 'string', |
| 41 |
}, |
| 42 |
target: { |
| 43 |
type: 'string', |
| 44 |
}, |
| 45 |
rel: { |
| 46 |
type: 'string', |
| 47 |
}, |
| 48 |
}, |
| 49 |
save: class BlockSave extends Component { |
| 50 |
render() { |
| 51 |
const { icon, iconPosition, showContent, url, target, rel } = |
| 52 |
this.props.attributes; |
| 53 |
|
| 54 |
let className = classnames( |
| 55 |
'ghostkit-icon-box', |
| 56 |
url && 'ghostkit-icon-box-with-link' |
| 57 |
); |
| 58 |
className = applyFilters( |
| 59 |
'ghostkit.blocks.className', |
| 60 |
className, |
| 61 |
{ |
| 62 |
name, |
| 63 |
...this.props, |
| 64 |
} |
| 65 |
); |
| 66 |
|
| 67 |
const classNameIcon = classnames( |
| 68 |
'ghostkit-icon-box-icon', |
| 69 |
`ghostkit-icon-box-icon-align-${iconPosition || 'left'}` |
| 70 |
); |
| 71 |
|
| 72 |
return ( |
| 73 |
<div className={className}> |
| 74 |
{url ? ( |
| 75 |
<a |
| 76 |
className="ghostkit-icon-box-link" |
| 77 |
href={url} |
| 78 |
target={target || false} |
| 79 |
rel={rel || false} |
| 80 |
> |
| 81 |
<span /> |
| 82 |
</a> |
| 83 |
) : null} |
| 84 |
{icon ? ( |
| 85 |
<IconPicker.Render |
| 86 |
name={icon} |
| 87 |
tag="div" |
| 88 |
className={classNameIcon} |
| 89 |
/> |
| 90 |
) : null} |
| 91 |
{showContent ? ( |
| 92 |
<div className="ghostkit-icon-box-content"> |
| 93 |
<InnerBlocks.Content /> |
| 94 |
</div> |
| 95 |
) : null} |
| 96 |
</div> |
| 97 |
); |
| 98 |
} |
| 99 |
}, |
| 100 |
}, |
| 101 |
]; |
| 102 |
|