const { registerBlockType } = wp.blocks;
const { __ } = wp.i18n;
const { PanelBody, ColorPicker } = wp.components;
const { InspectorControls, useBlockProps, InnerBlocks } =
wp.blockEditor || wp.editor;
import "./style.css";
// Parent Tabs block
registerBlockType("ai-builder/aibui-tabs", {
title: __("Tabs (AI Builder)", "ai-builder"),
icon: "index-card",
category: "widgets",
supports: { align: ["wide", "full"], html: false },
attributes: {
activeColor: { type: "string", default: "#4f46e5" },
},
edit: (props) => {
const { attributes, setAttributes } = props;
const { activeColor } = attributes;
function hexToRgba(hex, alpha) {
const match = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
hex || "#4f46e5"
);
if (!match) return `rgba(79,70,229,${alpha})`;
const r = parseInt(match[1], 16);
const g = parseInt(match[2], 16);
const b = parseInt(match[3], 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
const blockProps = useBlockProps({
className: "aibui-tabs",
style: {
"--aibui-active": activeColor,
"--aibui-active-shadow": hexToRgba(activeColor, 0.15),
},
});
const TEMPLATE = [
["ai-builder/aibui-tab", { title: "Tab 1" }],
["ai-builder/aibui-tab", { title: "Tab 2" }],
];
return (
<>
{__("Active tab color", "ai-builder")}