@wordpress/block-library
Version:
Block library for the WordPress editor.
54 lines (53 loc) • 2.15 kB
JavaScript
import { __, isRTL } from "@wordpress/i18n";
import { BlockControls, store } from "@wordpress/block-editor";
import { ToolbarButton } from "@wordpress/components";
import { chevronLeft, chevronRight } from "@wordpress/icons";
import { useSelect } from "@wordpress/data";
import useTabActions from "../tabs/use-tab-actions.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/tab-list/tab-movers.jsx
/**
* Block toolbar buttons that reorder the active tab one position before or after.
* Reordering acts on the underlying core/tab-panel blocks; the tab-list labels
* follow their panel automatically via useTabListItemsSync. The buttons are
* disabled at the first/last position.
*
* @param {Object} props
* @param {string} props.tabsClientId The client ID of the parent tabs block.
* @return {React.JSX.Element} The toolbar control element.
*/
function TabMovers({ tabsClientId }) {
const { moveTab } = useTabActions(tabsClientId);
const { tabCount, activeIndex } = useSelect((select) => {
if (!tabsClientId) return {
tabCount: 0,
activeIndex: 0
};
const { getBlocks, getBlockAttributes } = select(store);
const tabsAttributes = getBlockAttributes(tabsClientId);
return {
tabCount: getBlocks(tabsClientId).find((block) => block.name === "core/tab-panels")?.innerBlocks.length ?? 0,
activeIndex: tabsAttributes?.editorActiveTabIndex ?? tabsAttributes?.activeTabIndex ?? 0
};
}, [tabsClientId]);
return /* @__PURE__ */ jsxs(BlockControls, {
group: "parent",
children: [/* @__PURE__ */ jsx(ToolbarButton, {
className: "wp-block-tab-list__mover-button",
icon: isRTL() ? chevronRight : chevronLeft,
label: __("Move tab before"),
onClick: () => moveTab(-1),
disabled: activeIndex <= 0,
accessibleWhenDisabled: true
}), /* @__PURE__ */ jsx(ToolbarButton, {
className: "wp-block-tab-list__mover-button",
icon: isRTL() ? chevronLeft : chevronRight,
label: __("Move tab after"),
onClick: () => moveTab(1),
disabled: activeIndex >= tabCount - 1,
accessibleWhenDisabled: true
})]
});
}
export { TabMovers as default };
//# sourceMappingURL=tab-movers.mjs.map