| 1 |
import { ToggleControl } from "@wordpress/components"; |
| 2 |
import "./editor.scss"; |
| 3 |
import { memo } from "@wordpress/element"; |
| 4 |
import { DndTitleIcon } from "../../icons/icons"; |
| 5 |
import { priceLink } from "../../blocks/shared/helpFn"; |
| 6 |
|
| 7 |
const Toggle = ({ |
| 8 |
label = "", |
| 9 |
attributes, |
| 10 |
pro = false, |
| 11 |
setAttributes = () => {}, |
| 12 |
attributesKey = "", |
| 13 |
onChange = false, |
| 14 |
updated = false, |
| 15 |
helpText = false, |
| 16 |
}) => { |
| 17 |
return ( |
| 18 |
<> |
| 19 |
<div className={`sp-smart-post-toggle sp-smart-post-component-mb ${updated ? "updated-toggle" : ""} ${pro ? "sp-smart-pro-toggle" : ""}`}> |
| 20 |
{(updated || pro) && ( |
| 21 |
<> |
| 22 |
{updated && <div className="sp-smart-post-toggle-left"> |
| 23 |
<DndTitleIcon /> |
| 24 |
<span className="sp-smart-post-component-title">{label}</span> |
| 25 |
</div>} |
| 26 |
{pro && <> <span className="sp-smart-pro-label"> {label} </span> <a target="_blank" href={priceLink} className="sp-smart-pro-text"> (Pro) </a></>} |
| 27 |
</> |
| 28 |
)} |
| 29 |
<ToggleControl |
| 30 |
label={!(updated || pro) ? label : ""} |
| 31 |
checked={attributes} |
| 32 |
onChange={pro ? () => {} : (newField) => |
| 33 |
onChange |
| 34 |
? onChange(!newField) |
| 35 |
: setAttributes({ |
| 36 |
[attributesKey]: !attributes, |
| 37 |
}) |
| 38 |
} |
| 39 |
// help={helpText} |
| 40 |
__nextHasNoMarginBottom={true} |
| 41 |
/> |
| 42 |
</div> |
| 43 |
{helpText && <span className="components-toggle-control__help"> {helpText} </span>} |
| 44 |
</> |
| 45 |
); |
| 46 |
}; |
| 47 |
|
| 48 |
export default memo(Toggle); |
| 49 |
|