import { ButtonGroup, Button } from "@wordpress/components"; import "./editor.scss"; import { useDeviceType } from "../../controls/controls"; import Responsive from "../responsive/responsive"; const SpButtonGroup = ({ attributes, attributesKey, setAttributes, label, items, border = false, flexStyle = false, onClick = false, }) => { // Device type const deviceType = useDeviceType(); // Update button group value const setButtonGroup = (newValue) => { if (attributes?.device) { setAttributes({ [attributesKey]: { ...attributes.device, [deviceType]: newValue, }, }); } else { setAttributes({ [attributesKey]: newValue }); } }; // Get the active value const activeValue = attributes?.device ? attributes.device?.[deviceType] : attributes; // Handle button click const handleClick = (value) => { if (onClick) { onClick(value); } else { setButtonGroup(value); } }; return ( {label && (
{label} {attributes?.device && }
)}
{items?.map((item, i) => ( ))}
); }; export default SpButtonGroup;