@yamada-ui/tabs
Version:
Yamada UI tabs component
96 lines (93 loc) • 3.65 kB
JavaScript
"use client"
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/tab-panel.tsx
var tab_panel_exports = {};
__export(tab_panel_exports, {
TabPanel: () => TabPanel
});
module.exports = __toCommonJS(tab_panel_exports);
var import_core = require("@yamada-ui/core");
var import_use_disclosure = require("@yamada-ui/use-disclosure");
var import_utils2 = require("@yamada-ui/utils");
var import_react = require("react");
// src/tabs-context.tsx
var import_use_descendant = require("@yamada-ui/use-descendant");
var import_utils = require("@yamada-ui/utils");
var {
DescendantsContextProvider: TabDescendantsContextProvider,
useDescendant: useTabDescendant,
useDescendants: useTabDescendants,
useDescendantsContext: useTabDescendantsContext
} = (0, import_use_descendant.createDescendant)();
var {
DescendantsContextProvider: TabPanelDescendantsContextProvider,
useDescendant: useTabPanelDescendant,
useDescendants: useTabPanelDescendants,
useDescendantsContext: useTabPanelDescendantsContext
} = (0, import_use_descendant.createDescendant)();
var [TabsProvider, useTabsContext] = (0, import_utils.createContext)({
name: "TabsContext",
errorMessage: `useTabsContext returned is 'undefined'. Seems you forgot to wrap the components in "<Tabs />"`
});
var [TabPanelProvider, useTabPanelContext] = (0, import_utils.createContext)({});
// src/tab-panel.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var TabPanel = (0, import_core.forwardRef)(
({ id, className, children, ...rest }, ref) => {
var _a;
const uuid = (0, import_react.useId)();
const { lazy: enabled, lazyBehavior: mode, styles } = useTabsContext();
const { index, selected } = useTabPanelContext();
const { register } = useTabPanelDescendant();
const { descendants } = useTabDescendant();
const hasBeenSelected = (0, import_react.useRef)(false);
const tabId = (_a = descendants.value(index)) == null ? void 0 : _a.node.id;
if (selected) hasBeenSelected.current = true;
const shouldRenderChildren = (0, import_use_disclosure.useLazyDisclosure)({
enabled,
isSelected: selected,
mode,
wasSelected: hasBeenSelected.current
});
const css = { ...styles.tabPanel };
id != null ? id : id = uuid;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_core.ui.div,
{
id,
ref: (0, import_utils2.mergeRefs)(register, ref),
className: (0, import_utils2.cx)("ui-tabs__panel", className),
"aria-labelledby": tabId,
role: "tabpanel",
__css: css,
...rest,
hidden: !selected,
children: shouldRenderChildren ? children : null
}
);
}
);
TabPanel.displayName = "TabPanel";
TabPanel.__ui__ = "TabPanel";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TabPanel
});
//# sourceMappingURL=tab-panel.js.map