| 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 { |
| 9 |
RichText, |
| 10 |
useBlockProps, |
| 11 |
useInnerBlocksProps, |
| 12 |
} from '@wordpress/block-editor'; |
| 13 |
import { applyFilters } from '@wordpress/hooks'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Block Save Class. |
| 17 |
* |
| 18 |
* @param props |
| 19 |
*/ |
| 20 |
export default function BlockSave(props) { |
| 21 |
const { attributes } = props; |
| 22 |
|
| 23 |
const { |
| 24 |
photoId, |
| 25 |
photoUrl, |
| 26 |
photoAlt, |
| 27 |
photoWidth, |
| 28 |
photoHeight, |
| 29 |
|
| 30 |
icon, |
| 31 |
source, |
| 32 |
stars, |
| 33 |
starsIcon, |
| 34 |
url, |
| 35 |
ariaLabel, |
| 36 |
target, |
| 37 |
rel, |
| 38 |
} = attributes; |
| 39 |
|
| 40 |
let className = classnames( |
| 41 |
'ghostkit-testimonial', |
| 42 |
url && 'ghostkit-testimonial-with-link' |
| 43 |
); |
| 44 |
|
| 45 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 46 |
...{ name }, |
| 47 |
...props, |
| 48 |
}); |
| 49 |
|
| 50 |
const blockProps = useBlockProps.save({ className }); |
| 51 |
const innerBlockProps = useInnerBlocksProps.save({ |
| 52 |
className: 'ghostkit-testimonial-content', |
| 53 |
}); |
| 54 |
|
| 55 |
return ( |
| 56 |
<div {...blockProps}> |
| 57 |
{url ? ( |
| 58 |
<a |
| 59 |
className="ghostkit-testimonial-link" |
| 60 |
href={url} |
| 61 |
target={target || null} |
| 62 |
rel={rel || null} |
| 63 |
aria-label={ariaLabel || null} |
| 64 |
> |
| 65 |
<span /> |
| 66 |
</a> |
| 67 |
) : null} |
| 68 |
{icon ? ( |
| 69 |
<IconPicker.Render |
| 70 |
name={icon} |
| 71 |
tag="div" |
| 72 |
className="ghostkit-testimonial-icon" |
| 73 |
/> |
| 74 |
) : null} |
| 75 |
<div {...innerBlockProps} /> |
| 76 |
{photoUrl ? ( |
| 77 |
<div className="ghostkit-testimonial-photo"> |
| 78 |
<img |
| 79 |
src={photoUrl} |
| 80 |
alt={photoAlt} |
| 81 |
className={photoId ? `wp-image-${photoId}` : null} |
| 82 |
width={photoWidth} |
| 83 |
height={photoHeight} |
| 84 |
/> |
| 85 |
</div> |
| 86 |
) : null} |
| 87 |
{!RichText.isEmpty(attributes.name) || !RichText.isEmpty(source) ? ( |
| 88 |
<div className="ghostkit-testimonial-meta"> |
| 89 |
{!RichText.isEmpty(attributes.name) ? ( |
| 90 |
<div className="ghostkit-testimonial-name"> |
| 91 |
<RichText.Content value={attributes.name} /> |
| 92 |
</div> |
| 93 |
) : null} |
| 94 |
{!RichText.isEmpty(source) ? ( |
| 95 |
<div className="ghostkit-testimonial-source"> |
| 96 |
<RichText.Content value={source} /> |
| 97 |
</div> |
| 98 |
) : null} |
| 99 |
</div> |
| 100 |
) : null} |
| 101 |
{typeof stars === 'number' && starsIcon ? ( |
| 102 |
<div className="ghostkit-testimonial-stars"> |
| 103 |
<div className="ghostkit-testimonial-stars-wrap"> |
| 104 |
<div |
| 105 |
className="ghostkit-testimonial-stars-front" |
| 106 |
style={{ width: `${(100 * stars) / 5}%` }} |
| 107 |
> |
| 108 |
<IconPicker.Render name={starsIcon} /> |
| 109 |
<IconPicker.Render name={starsIcon} /> |
| 110 |
<IconPicker.Render name={starsIcon} /> |
| 111 |
<IconPicker.Render name={starsIcon} /> |
| 112 |
<IconPicker.Render name={starsIcon} /> |
| 113 |
</div> |
| 114 |
<div className="ghostkit-testimonial-stars-back"> |
| 115 |
<IconPicker.Render name={starsIcon} /> |
| 116 |
<IconPicker.Render name={starsIcon} /> |
| 117 |
<IconPicker.Render name={starsIcon} /> |
| 118 |
<IconPicker.Render name={starsIcon} /> |
| 119 |
<IconPicker.Render name={starsIcon} /> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
) : null} |
| 124 |
</div> |
| 125 |
); |
| 126 |
} |
| 127 |
|