UNPKG

4.16 kBJavaScriptView Raw
1'use client';
2
3import _extends from "@babel/runtime/helpers/esm/extends";
4import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5const _excluded = ["children", "value", "defaultValue", "orientation", "direction", "onChange", "selectionFollowsFocus", "slotProps", "slots"];
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import { useSlotProps } from '../utils';
9import { unstable_composeClasses as composeClasses } from '../composeClasses';
10import { getTabsUtilityClass } from './tabsClasses';
11import { useTabs } from '../useTabs';
12import { TabsProvider } from '../useTabs/TabsProvider';
13import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
14import { jsx as _jsx } from "react/jsx-runtime";
15const useUtilityClasses = ownerState => {
16 const {
17 orientation
18 } = ownerState;
19 const slots = {
20 root: ['root', orientation]
21 };
22 return composeClasses(slots, useClassNamesOverride(getTabsUtilityClass));
23};
24
25/**
26 *
27 * Demos:
28 *
29 * - [Tabs](https://mui.com/base-ui/react-tabs/)
30 *
31 * API:
32 *
33 * - [Tabs API](https://mui.com/base-ui/react-tabs/components-api/#tabs)
34 */
35const Tabs = /*#__PURE__*/React.forwardRef(function Tabs(props, forwardedRef) {
36 const {
37 children,
38 orientation = 'horizontal',
39 direction = 'ltr',
40 slotProps = {},
41 slots = {}
42 } = props,
43 other = _objectWithoutPropertiesLoose(props, _excluded);
44 const ownerState = _extends({}, props, {
45 orientation,
46 direction
47 });
48 const {
49 contextValue
50 } = useTabs(ownerState);
51 const classes = useUtilityClasses(ownerState);
52 const TabsRoot = slots.root ?? 'div';
53 const tabsRootProps = useSlotProps({
54 elementType: TabsRoot,
55 externalSlotProps: slotProps.root,
56 externalForwardedProps: other,
57 additionalProps: {
58 ref: forwardedRef
59 },
60 ownerState,
61 className: classes.root
62 });
63 return /*#__PURE__*/_jsx(TabsRoot, _extends({}, tabsRootProps, {
64 children: /*#__PURE__*/_jsx(TabsProvider, {
65 value: contextValue,
66 children: children
67 })
68 }));
69});
70process.env.NODE_ENV !== "production" ? Tabs.propTypes /* remove-proptypes */ = {
71 // ┌────────────────────────────── Warning ──────────────────────────────┐
72 // │ These PropTypes are generated from the TypeScript type definitions. │
73 // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
74 // └─────────────────────────────────────────────────────────────────────┘
75 /**
76 * The content of the component.
77 */
78 children: PropTypes.node,
79 /**
80 * @ignore
81 */
82 className: PropTypes.string,
83 /**
84 * The default value. Use when the component is not controlled.
85 */
86 defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
87 /**
88 * The direction of the text.
89 * @default 'ltr'
90 */
91 direction: PropTypes.oneOf(['ltr', 'rtl']),
92 /**
93 * Callback invoked when new value is being set.
94 */
95 onChange: PropTypes.func,
96 /**
97 * The component orientation (layout flow direction).
98 * @default 'horizontal'
99 */
100 orientation: PropTypes.oneOf(['horizontal', 'vertical']),
101 /**
102 * If `true` the selected tab changes on focus. Otherwise it only
103 * changes on activation.
104 */
105 selectionFollowsFocus: PropTypes.bool,
106 /**
107 * The props used for each slot inside the Tabs.
108 * @default {}
109 */
110 slotProps: PropTypes.shape({
111 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
112 }),
113 /**
114 * The components used for each slot inside the Tabs.
115 * Either a string to use a HTML element or a component.
116 * @default {}
117 */
118 slots: PropTypes.shape({
119 root: PropTypes.elementType
120 }),
121 /**
122 * The value of the currently selected `Tab`.
123 * If you don't want any selected `Tab`, you can set this prop to `null`.
124 */
125 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
126} : void 0;
127export { Tabs };
\No newline at end of file