| 1 |
import { memo } from "@wordpress/element"; |
| 2 |
import { RightSymbolIcon } from "../../icons/icons"; |
| 3 |
import "./editor.scss"; |
| 4 |
import ProBtn from "../proBtn/proBtn"; |
| 5 |
|
| 6 |
const Layout = ({ layout, handleActive, activeLayout, displayActive, proBtnClass = ""}) => { |
| 7 |
const { icon, value, label, type, demoLink } = layout; |
| 8 |
|
| 9 |
return ( |
| 10 |
<div |
| 11 |
onClick={ type !== "pro" ? () => handleActive(value) : null } |
| 12 |
className={`sp-smart-post-layout-card ${type === "pro" ? "sp-smart-pro-layout" : ""} ${value === activeLayout ? "active" : "inactive"}`} |
| 13 |
> |
| 14 |
{value === activeLayout && displayActive && ( |
| 15 |
<span className="active-symbol"> |
| 16 |
<RightSymbolIcon /> |
| 17 |
</span> |
| 18 |
)} |
| 19 |
{type !== "pro" && <div className="sp-smart-layout-img"> |
| 20 |
{icon} |
| 21 |
</div>} |
| 22 |
{type === "pro" && <a href={demoLink} rel="noreferrer" target="_blank" className="sp-smart-layout-img"> |
| 23 |
{icon} |
| 24 |
<ProBtn proBtnClass={proBtnClass} demoLink={demoLink} /> |
| 25 |
</a>} |
| 26 |
{label && <p className="sp-smart-post-layout-title">{label}</p>} |
| 27 |
</div> |
| 28 |
); |
| 29 |
}; |
| 30 |
|
| 31 |
const Layouts = ({ |
| 32 |
attributes, |
| 33 |
setAttributes, |
| 34 |
attributesKey, |
| 35 |
displayActive = false, |
| 36 |
label = "", |
| 37 |
proBtnClass = "", |
| 38 |
showDemoTitle = false, |
| 39 |
grid = 2, |
| 40 |
items, |
| 41 |
onChange = false, |
| 42 |
}) => { |
| 43 |
const handleActive = (value) => { |
| 44 |
if (value === attributes) { |
| 45 |
return; |
| 46 |
} |
| 47 |
if (onChange) { |
| 48 |
onChange(value); |
| 49 |
} |
| 50 |
setAttributes({ [attributesKey]: value }); |
| 51 |
}; |
| 52 |
|
| 53 |
return ( |
| 54 |
<div className="sp-smart-post-layout-picker sp-smart-post-panel-pb"> |
| 55 |
{label && <p className="sp-smart-post-component-title">{label}</p>} |
| 56 |
<div className={`sp-smart-post-layouts grid-${grid}`}> |
| 57 |
{items?.map((layout, index) => ( |
| 58 |
<Layout |
| 59 |
key={index} |
| 60 |
layout={layout} |
| 61 |
displayActive={displayActive} |
| 62 |
handleActive={handleActive} |
| 63 |
proBtnClass={proBtnClass} |
| 64 |
showDemoTitle={showDemoTitle} |
| 65 |
activeLayout={attributes} |
| 66 |
/> |
| 67 |
))} |
| 68 |
</div> |
| 69 |
</div> |
| 70 |
); |
| 71 |
}; |
| 72 |
|
| 73 |
export default memo(Layouts); |
| 74 |
|