UNPKG

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