@wordpress/block-library
Version:
Block library for the WordPress editor.
47 lines (46 loc) • 1.46 kB
JavaScript
// packages/block-library/src/tabs/tab-toolbar-controls.js
import { __ } from "@wordpress/i18n";
import {
BlockControls,
store as blockEditorStore
} from "@wordpress/block-editor";
import { ToolbarGroup, ToolbarButton } from "@wordpress/components";
import { useSelect } from "@wordpress/data";
import useTabActions from "./use-tab-actions.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
function TabToolbarControls({ tabsClientId }) {
const { insertTab, removeTab } = useTabActions(tabsClientId);
const isRemoveDisabled = useSelect(
(select) => {
if (!tabsClientId) {
return true;
}
const tabPanels = select(blockEditorStore).getBlocks(tabsClientId).find((block) => block.name === "core/tab-panels");
return (tabPanels?.innerBlocks.length ?? 0) <= 1;
},
[tabsClientId]
);
return /* @__PURE__ */ jsx(BlockControls, { group: "other", children: /* @__PURE__ */ jsxs(ToolbarGroup, { children: [
/* @__PURE__ */ jsx(
ToolbarButton,
{
className: "components-toolbar__control",
onClick: () => insertTab(),
text: __("Add tab")
}
),
/* @__PURE__ */ jsx(
ToolbarButton,
{
className: "components-toolbar__control",
onClick: () => removeTab(),
text: __("Remove tab"),
disabled: isRemoveDisabled
}
)
] }) });
}
export {
TabToolbarControls as default
};
//# sourceMappingURL=tab-toolbar-controls.mjs.map