UNPKG

@wordpress/block-library

Version:
133 lines (131 loc) 5.06 kB
"use strict"; 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 __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-library/src/tab/tabs-list.js var tabs_list_exports = {}; __export(tabs_list_exports, { default: () => TabsList }); module.exports = __toCommonJS(tabs_list_exports); var import_clsx = __toESM(require("clsx")); var import_i18n = require("@wordpress/i18n"); var import_block_editor = require("@wordpress/block-editor"); var import_html_entities = require("@wordpress/html-entities"); var import_element = require("@wordpress/element"); var import_slug_from_label = __toESM(require("./slug-from-label")); var import_jsx_runtime = require("react/jsx-runtime"); function StaticLabel({ label, index }) { if (label) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element.RawHTML, { children: (0, import_html_entities.decodeEntities)(label) }) }); } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: (0, import_i18n.sprintf)( /* translators: %d is the tab index + 1 */ (0, import_i18n.__)("Tab %d"), index + 1 ) }); } function TabsList({ siblingTabs, currentClientId, currentBlockIndex, currentLabel, tabItemColorProps, onSelectTab, onLabelChange, labelRef, focusRef, labelElementRef }) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { role: "tablist", className: "tabs__list", children: siblingTabs.map((tab, index) => { const isCurrentTab = tab.clientId === currentClientId; const isSiblingTabActive = index === currentBlockIndex; const tabAttributes = tab.attributes || {}; const siblingLabel = tabAttributes.label || ""; const siblingAnchor = tabAttributes.anchor || (0, import_slug_from_label.default)(siblingLabel, index); const siblingTabPanelId = siblingAnchor; const siblingTabLabelId = `${siblingTabPanelId}--tab`; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "button", { "aria-controls": siblingTabPanelId, "aria-selected": isSiblingTabActive, id: siblingTabLabelId, role: "tab", className: (0, import_clsx.default)( "tabs__tab-label", tabItemColorProps.className ), style: { ...tabItemColorProps.style }, tabIndex: isSiblingTabActive ? 0 : -1, onClick: (event) => { event.preventDefault(); onSelectTab(tab.clientId); }, onKeyDown: (event) => { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); onSelectTab(tab.clientId); if (isCurrentTab) { const { requestAnimationFrame } = window; focusRef.current = requestAnimationFrame( () => { labelElementRef.current?.focus(); } ); } } }, children: isCurrentTab ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_block_editor.RichText, { ref: labelRef, tagName: "span", withoutInteractiveFormatting: true, placeholder: (0, import_i18n.sprintf)( /* translators: %d is the tab index + 1 */ (0, import_i18n.__)("Tab %d\u2026"), currentBlockIndex + 1 ), value: (0, import_html_entities.decodeEntities)(currentLabel), onChange: onLabelChange } ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)( StaticLabel, { label: siblingLabel, index } ) }, tab.clientId ); }) }); } //# sourceMappingURL=tabs-list.js.map