@wordpress/block-library
Version:
Block library for the WordPress editor.
66 lines (65 loc) • 3.09 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let __use_tab_actions_js = require("./use-tab-actions.cjs");
__use_tab_actions_js = __toESM(__use_tab_actions_js);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/tabs/tab-toolbar-controls.jsx
/**
* "Add tab" and "Remove tab" buttons in the block toolbar for the tabs block.
* Inserts or removes a core/tab-panel. The tab-list items attribute is kept
* in sync automatically via useTabListItemsSync.
*
* @param {Object} props
* @param {string} props.tabsClientId The client ID of the parent tabs block.
* @return {React.JSX.Element} The toolbar control element.
*/
function TabToolbarControls({ tabsClientId }) {
const { insertTab, removeTab } = (0, __use_tab_actions_js.default)(tabsClientId);
const isRemoveDisabled = (0, _wordpress_data.useSelect)((select) => {
if (!tabsClientId) return true;
return (select(_wordpress_block_editor.store).getBlocks(tabsClientId).find((block) => block.name === "core/tab-panels")?.innerBlocks.length ?? 0) <= 1;
}, [tabsClientId]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "other",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.ToolbarGroup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
className: "components-toolbar__control",
onClick: () => insertTab(),
text: (0, _wordpress_i18n.__)("Add tab")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
className: "components-toolbar__control",
onClick: () => removeTab(),
text: (0, _wordpress_i18n.__)("Remove tab"),
disabled: isRemoveDisabled
})] })
});
}
exports.default = TabToolbarControls;
//# sourceMappingURL=tab-toolbar-controls.cjs.map