| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { InnerBlocks, RichText } 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%22M13.5954%2010.708C15.7931%205.55696%2021.1071%205%2021.1071%205L21.3565%205.16714C18.945%206.72641%2019.0559%208.98169%2019.0559%208.98169C19.0559%208.98169%2022.1211%209.70495%2022.7979%2012.2673C23.5186%2014.996%2022.2158%2017.2944%2020.4141%2018.3373C18.1801%2019.6305%2015.4248%2018.9499%2014.0389%2017.0008C12.6134%2014.996%2012.8469%2012.4623%2013.5954%2010.708Z%22%20fill%3D%22currentColor%22%2F%3E%3Cpath%20d%3D%22M1.59537%2010.708C3.79305%205.55696%209.10709%205%209.10709%205L9.35651%205.16714C6.945%206.72641%207.05592%208.98169%207.05592%208.98169C7.05592%208.98169%2010.1211%209.70495%2010.7979%2012.2673C11.5186%2014.996%2010.2158%2017.2944%208.41413%2018.3373C6.18005%2019.6305%203.42475%2018.9499%202.03887%2017.0008C0.61344%2014.996%200.846929%2012.4623%201.59537%2010.708Z%22%20fill%3D%22currentColor%22%2F%3E%3C%2Fsvg%3E', |
| 21 |
}, |
| 22 |
photoId: { |
| 23 |
type: 'number', |
| 24 |
}, |
| 25 |
photoUrl: { |
| 26 |
attribute: 'src', |
| 27 |
selector: '.ghostkit-testimonial-photo img', |
| 28 |
source: 'attribute', |
| 29 |
type: 'string', |
| 30 |
}, |
| 31 |
photoAlt: { |
| 32 |
attribute: 'alt', |
| 33 |
selector: '.ghostkit-testimonial-photo img', |
| 34 |
source: 'attribute', |
| 35 |
type: 'string', |
| 36 |
default: '', |
| 37 |
}, |
| 38 |
photoWidth: { |
| 39 |
type: 'number', |
| 40 |
}, |
| 41 |
photoHeight: { |
| 42 |
type: 'number', |
| 43 |
}, |
| 44 |
photoSizeSlug: { |
| 45 |
type: 'string', |
| 46 |
}, |
| 47 |
name: { |
| 48 |
type: 'string', |
| 49 |
source: 'html', |
| 50 |
selector: '.ghostkit-testimonial-name', |
| 51 |
default: '<strong>Katrina Craft</strong>', |
| 52 |
}, |
| 53 |
source: { |
| 54 |
type: 'string', |
| 55 |
source: 'html', |
| 56 |
selector: '.ghostkit-testimonial-source', |
| 57 |
default: 'Designer', |
| 58 |
}, |
| 59 |
stars: { |
| 60 |
type: 'number', |
| 61 |
}, |
| 62 |
starsIcon: { |
| 63 |
type: 'string', |
| 64 |
default: |
| 65 |
'%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%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M12.6724%202.66808C12.5461%202.41207%2012.2853%202.25%2011.9998%202.25C11.7144%202.25%2011.4536%202.41207%2011.3273%202.66808L8.56287%208.26941L2.38143%209.16762C2.09892%209.20868%201.86421%209.40656%201.77599%209.67807C1.68777%209.94958%201.76134%2010.2476%201.96577%2010.4469L6.4387%2014.8069L5.38279%2020.9634C5.33453%2021.2448%205.45019%2021.5291%205.68115%2021.6969C5.91211%2021.8647%206.21831%2021.8869%206.471%2021.754L11.9998%2018.8473L17.5287%2021.754C17.7814%2021.8869%2018.0876%2021.8647%2018.3185%2021.6969C18.5495%2021.5291%2018.6652%2021.2448%2018.6169%2020.9634L17.561%2014.8069L22.0339%2010.4469C22.2383%2010.2476%2022.3119%209.94958%2022.2237%209.67807C22.1355%209.40656%2021.9008%209.20868%2021.6183%209.16762L15.4368%208.26941L12.6724%202.66808Z%22%20fill%3D%22currentColor%22%2F%3E%3C%2Fsvg%3E', |
| 66 |
}, |
| 67 |
url: { |
| 68 |
type: 'string', |
| 69 |
}, |
| 70 |
target: { |
| 71 |
type: 'string', |
| 72 |
}, |
| 73 |
rel: { |
| 74 |
type: 'string', |
| 75 |
}, |
| 76 |
}, |
| 77 |
save: class BlockSave extends Component { |
| 78 |
render() { |
| 79 |
const { attributes } = this.props; |
| 80 |
|
| 81 |
const { |
| 82 |
photoId, |
| 83 |
photoUrl, |
| 84 |
photoAlt, |
| 85 |
photoWidth, |
| 86 |
photoHeight, |
| 87 |
|
| 88 |
icon, |
| 89 |
source, |
| 90 |
stars, |
| 91 |
starsIcon, |
| 92 |
url, |
| 93 |
target, |
| 94 |
rel, |
| 95 |
} = attributes; |
| 96 |
|
| 97 |
let className = classnames( |
| 98 |
'ghostkit-testimonial', |
| 99 |
url && 'ghostkit-testimonial-with-link' |
| 100 |
); |
| 101 |
|
| 102 |
className = applyFilters( |
| 103 |
'ghostkit.blocks.className', |
| 104 |
className, |
| 105 |
{ |
| 106 |
name, |
| 107 |
...this.props, |
| 108 |
} |
| 109 |
); |
| 110 |
|
| 111 |
return ( |
| 112 |
<div className={className}> |
| 113 |
{url ? ( |
| 114 |
<a |
| 115 |
className="ghostkit-testimonial-link" |
| 116 |
href={url} |
| 117 |
target={target || false} |
| 118 |
rel={rel || false} |
| 119 |
> |
| 120 |
<span /> |
| 121 |
</a> |
| 122 |
) : null} |
| 123 |
{icon ? ( |
| 124 |
<IconPicker.Render |
| 125 |
name={icon} |
| 126 |
tag="div" |
| 127 |
className="ghostkit-testimonial-icon" |
| 128 |
/> |
| 129 |
) : null} |
| 130 |
<div className="ghostkit-testimonial-content"> |
| 131 |
<InnerBlocks.Content /> |
| 132 |
</div> |
| 133 |
{photoUrl ? ( |
| 134 |
<div className="ghostkit-testimonial-photo"> |
| 135 |
<img |
| 136 |
src={photoUrl} |
| 137 |
alt={photoAlt} |
| 138 |
className={ |
| 139 |
photoId ? `wp-image-${photoId}` : null |
| 140 |
} |
| 141 |
width={photoWidth} |
| 142 |
height={photoHeight} |
| 143 |
/> |
| 144 |
</div> |
| 145 |
) : null} |
| 146 |
{!RichText.isEmpty(attributes.name) || |
| 147 |
!RichText.isEmpty(source) ? ( |
| 148 |
<div className="ghostkit-testimonial-meta"> |
| 149 |
{!RichText.isEmpty(attributes.name) ? ( |
| 150 |
<div className="ghostkit-testimonial-name"> |
| 151 |
<RichText.Content |
| 152 |
value={attributes.name} |
| 153 |
/> |
| 154 |
</div> |
| 155 |
) : null} |
| 156 |
{!RichText.isEmpty(source) ? ( |
| 157 |
<div className="ghostkit-testimonial-source"> |
| 158 |
<RichText.Content value={source} /> |
| 159 |
</div> |
| 160 |
) : null} |
| 161 |
</div> |
| 162 |
) : null} |
| 163 |
{typeof stars === 'number' && starsIcon ? ( |
| 164 |
<div className="ghostkit-testimonial-stars"> |
| 165 |
<div className="ghostkit-testimonial-stars-wrap"> |
| 166 |
<div |
| 167 |
className="ghostkit-testimonial-stars-front" |
| 168 |
style={{ |
| 169 |
width: `${(100 * stars) / 5}%`, |
| 170 |
}} |
| 171 |
> |
| 172 |
<IconPicker.Render name={starsIcon} /> |
| 173 |
<IconPicker.Render name={starsIcon} /> |
| 174 |
<IconPicker.Render name={starsIcon} /> |
| 175 |
<IconPicker.Render name={starsIcon} /> |
| 176 |
<IconPicker.Render name={starsIcon} /> |
| 177 |
</div> |
| 178 |
<div className="ghostkit-testimonial-stars-back"> |
| 179 |
<IconPicker.Render name={starsIcon} /> |
| 180 |
<IconPicker.Render name={starsIcon} /> |
| 181 |
<IconPicker.Render name={starsIcon} /> |
| 182 |
<IconPicker.Render name={starsIcon} /> |
| 183 |
<IconPicker.Render name={starsIcon} /> |
| 184 |
</div> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
) : null} |
| 188 |
</div> |
| 189 |
); |
| 190 |
} |
| 191 |
}, |
| 192 |
}, |
| 193 |
]; |
| 194 |
|