@yamada-ui/tabs
Version:
Yamada UI tabs component
114 lines (111 loc) • 4.3 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-list.tsx
var tab_list_exports = {};
__export(tab_list_exports, {
TabList: () => TabList
});
module.exports = __toCommonJS(tab_list_exports);
var import_core = require("@yamada-ui/core");
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-list.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var TabList = (0, import_core.forwardRef)(
({ className, ...rest }, ref) => {
const { focusedIndex, orientation, styles, tabListProps } = useTabsContext();
const descendants = useTabDescendantsContext();
const isVertical = orientation === "vertical";
const onNext = (0, import_react.useCallback)(() => {
const next = descendants.enabledNextValue(focusedIndex);
if (next) next.node.focus();
}, [descendants, focusedIndex]);
const onPrev = (0, import_react.useCallback)(() => {
const prev = descendants.enabledPrevValue(focusedIndex);
if (prev) prev.node.focus();
}, [descendants, focusedIndex]);
const onFirst = (0, import_react.useCallback)(() => {
const first = descendants.enabledFirstValue();
if (first) first.node.focus();
}, [descendants]);
const onLast = (0, import_react.useCallback)(() => {
const last = descendants.enabledLastValue();
if (last) last.node.focus();
}, [descendants]);
const onKeyDown = (0, import_react.useCallback)(
(ev) => {
const actions = {
ArrowDown: () => isVertical ? onNext() : {},
ArrowLeft: () => !isVertical ? onPrev() : {},
ArrowRight: () => !isVertical ? onNext() : {},
ArrowUp: () => isVertical ? onPrev() : {},
End: onLast,
Home: onFirst
};
const action = actions[ev.key];
if (!action) return;
ev.preventDefault();
action(ev);
},
[onFirst, onLast, isVertical, onPrev, onNext]
);
const css = { display: "flex", ...styles.tabList };
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_core.ui.div,
{
ref,
className: (0, import_utils2.cx)("ui-tabs__list", className),
"aria-orientation": orientation,
role: "tablist",
__css: css,
...tabListProps,
...rest,
onKeyDown: (0, import_utils2.handlerAll)(rest.onKeyDown, onKeyDown)
}
);
}
);
TabList.displayName = "TabList";
TabList.__ui__ = "TabList";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TabList
});
//# sourceMappingURL=tab-list.js.map