UNPKG

@wordpress/components

Version:
101 lines (100 loc) • 4.32 kB
"use strict"; 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 _ariakit_react = require("@ariakit/react"); _ariakit_react = __toESM(_ariakit_react); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_element = require("@wordpress/element"); let _wordpress_i18n = require("@wordpress/i18n"); let __context_ts = require("./context.cjs"); let __tab_tsx = require("./tab.cjs"); let __tablist_tsx = require("./tablist.cjs"); let __tabpanel_tsx = require("./tabpanel.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/components/src/tabs/index.tsx function externalToInternalTabId(externalId, instanceId) { return externalId && `${instanceId}-${externalId}`; } function internalToExternalTabId(internalId, instanceId) { return typeof internalId === "string" ? internalId.replace(`${instanceId}-`, "") : internalId; } /** * Tabs is a collection of React components that combine to render * an [ARIA-compliant tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/). * * Tabs organizes content across different screens, data sets, and interactions. * It has two sections: a list of tabs, and the view to show when a tab is chosen. * * `Tabs` itself is a wrapper component and context provider. * It is responsible for managing the state of the tabs, and rendering one instance of the `Tabs.TabList` component and one or more instances of the `Tab.TabPanel` component. */ const Tabs = Object.assign(function TabsRoot({ selectOnMove = true, defaultTabId, orientation = "horizontal", onSelect, children, selectedTabId, activeTabId, defaultActiveTabId, onActiveTabIdChange }) { const instanceId = (0, _wordpress_compose.useInstanceId)(TabsRoot, "tabs"); const store = _ariakit_react.useTabStore({ selectOnMove, orientation, defaultSelectedId: externalToInternalTabId(defaultTabId, instanceId), setSelectedId: (newSelectedId) => { onSelect?.(internalToExternalTabId(newSelectedId, instanceId)); }, selectedId: externalToInternalTabId(selectedTabId, instanceId), defaultActiveId: externalToInternalTabId(defaultActiveTabId, instanceId), setActiveId: (newActiveId) => { onActiveTabIdChange?.(internalToExternalTabId(newActiveId, instanceId)); }, activeId: externalToInternalTabId(activeTabId, instanceId), rtl: (0, _wordpress_i18n.isRTL)() }); const contextValue = (0, _wordpress_element.useMemo)(() => ({ store, instanceId }), [store, instanceId]); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__context_ts.TabsContext.Provider, { value: contextValue, children }); }, { /** * Renders a single tab. * * The currently active tab receives default styling that can be * overridden with CSS targeting `[aria-selected="true"]`. */ Tab: Object.assign(__tab_tsx.Tab, { displayName: "Tabs.Tab" }), /** * A wrapper component for the `Tab` components. * * It is responsible for rendering the list of tabs. */ TabList: Object.assign(__tablist_tsx.TabList, { displayName: "Tabs.TabList" }), /** * Renders the content to display for a single tab once that tab is selected. */ TabPanel: Object.assign(__tabpanel_tsx.TabPanel, { displayName: "Tabs.TabPanel" }), Context: Object.assign(__context_ts.TabsContext, { displayName: "Tabs.Context" }) }); exports.Tabs = Tabs; //# sourceMappingURL=index.cjs.map