| 1 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 2 |
import { arrowIcons } from "../../controls/constants"; |
| 3 |
import classNames from "classnames"; |
| 4 |
|
| 5 |
const ButtonSave = ({ attributes }) => { |
| 6 |
const { |
| 7 |
uniqueId, |
| 8 |
buttonLabel, |
| 9 |
iconSource, |
| 10 |
buttonStyle, |
| 11 |
hoverEffects, |
| 12 |
buttonLink, |
| 13 |
openNewTab, |
| 14 |
enableIcon, |
| 15 |
additionalCssClass, |
| 16 |
buttonLabelEnable, |
| 17 |
buttonLabelGlobalTypography, |
| 18 |
} = attributes; |
| 19 |
|
| 20 |
const blockProps = useBlockProps.save({ |
| 21 |
className: additionalCssClass, |
| 22 |
}); |
| 23 |
|
| 24 |
const BtnIcon = arrowIcons[iconSource]; |
| 25 |
|
| 26 |
return ( |
| 27 |
<div {...blockProps}> |
| 28 |
<div |
| 29 |
className={classNames( |
| 30 |
"sp-smart-post-wrapper", |
| 31 |
"sp-smart-post-button-editor-page", |
| 32 |
"sp-smart-post-button-wrapper" |
| 33 |
)} |
| 34 |
id={uniqueId} |
| 35 |
> |
| 36 |
<a |
| 37 |
href={buttonLink} |
| 38 |
target={openNewTab ? "_blank" : undefined} |
| 39 |
className={`sp-smart-post-btn btn-${buttonStyle} ${hoverEffects}`} |
| 40 |
rel="noreferrer" |
| 41 |
> |
| 42 |
<div className="button-label"> |
| 43 |
<div className="front"> |
| 44 |
{enableIcon && ( |
| 45 |
<span |
| 46 |
className="icon" |
| 47 |
aria-label="button arrow icon" |
| 48 |
style={{ |
| 49 |
lineHeight: "1", |
| 50 |
}} |
| 51 |
> |
| 52 |
<i aria-hidden="true"> |
| 53 |
<BtnIcon /> |
| 54 |
</i> |
| 55 |
</span> |
| 56 |
)} |
| 57 |
{buttonLabelEnable && ( |
| 58 |
<span |
| 59 |
className={classNames( |
| 60 |
"sp-rich-text", |
| 61 |
"sp-btn-label", |
| 62 |
buttonLabelGlobalTypography?.class ? buttonLabelGlobalTypography.class : "" |
| 63 |
)} |
| 64 |
> |
| 65 |
{buttonLabel} |
| 66 |
</span> |
| 67 |
)} |
| 68 |
</div> |
| 69 |
|
| 70 |
{hoverEffects === "flip" && ( |
| 71 |
<div className="back"> |
| 72 |
{iconSource && ( |
| 73 |
<span className="icon" aria-label="flip on hover button arrow icon"> |
| 74 |
<i className={`sp-icon-${iconSource}`} aria-hidden="true"> |
| 75 |
<BtnIcon /> |
| 76 |
</i> |
| 77 |
</span> |
| 78 |
)} |
| 79 |
{buttonLabelEnable && ( |
| 80 |
<span |
| 81 |
className={classNames( |
| 82 |
"sp-rich-text", |
| 83 |
"sp-btn-label", |
| 84 |
buttonLabelGlobalTypography?.class ? buttonLabelGlobalTypography.class : "" |
| 85 |
)} |
| 86 |
> |
| 87 |
{buttonLabel} |
| 88 |
</span> |
| 89 |
)} |
| 90 |
</div> |
| 91 |
)} |
| 92 |
</div> |
| 93 |
</a> |
| 94 |
</div> |
| 95 |
</div> |
| 96 |
); |
| 97 |
}; |
| 98 |
|
| 99 |
export default ButtonSave; |
| 100 |
|