| 1 |
import "./editor.scss"; |
| 2 |
|
| 3 |
const ButtonSet = ({ label = "", attributes, attributesKey, setAttributes, columns = 4, items, onChange = false }) => { |
| 4 |
const handleClick = (value) => { |
| 5 |
if (value === attributes) { |
| 6 |
return; |
| 7 |
} |
| 8 |
if (onChange) { |
| 9 |
onChange(value); |
| 10 |
} else { |
| 11 |
setAttributes({ [attributesKey]: value }); |
| 12 |
} |
| 13 |
}; |
| 14 |
return ( |
| 15 |
<div className="sp-smart-post-button-set sp-smart-post-component-mb"> |
| 16 |
{label && ( |
| 17 |
<div className="sp-smart-post-component-top sp-smart-post-component-title"> |
| 18 |
<span>{label}</span> |
| 19 |
</div> |
| 20 |
)} |
| 21 |
<div className={`sp-smart-post-button-set-list sp-col-${columns}`}> |
| 22 |
{items?.map((item, index) => ( |
| 23 |
<span |
| 24 |
key={index} |
| 25 |
className={`sp-smart-post-button-set-item${attributes === item.value ? " active" : ""}`} |
| 26 |
value={item.value} |
| 27 |
onClick={() => handleClick(item.value)} |
| 28 |
> |
| 29 |
<span className="sp-item-set-btn">{item.label}</span> |
| 30 |
{item.tooltip && <p>{item.tooltip}</p>} |
| 31 |
</span> |
| 32 |
))} |
| 33 |
</div> |
| 34 |
</div> |
| 35 |
); |
| 36 |
}; |
| 37 |
export default ButtonSet; |
| 38 |
|