UNPKG

3.77 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 const {
35 children,
36 orientation = 'horizontal',
37 direction = 'ltr',
38 slotProps = {},
39 slots = {}
40 } = props,
41 other = _objectWithoutPropertiesLoose(props, _excluded);
42 const {
43 contextValue
44 } = useTabs(props);
45 const ownerState = _extends({}, props, {
46 orientation,
47 direction
48 });
49 const classes = useUtilityClasses(ownerState);
50 const TabsRoot = slots.root ?? 'div';
51 const tabsRootProps = useSlotProps({
52 elementType: TabsRoot,
53 externalSlotProps: slotProps.root,
54 externalForwardedProps: other,
55 additionalProps: {
56 ref: forwardedRef
57 },
58 ownerState,
59 className: classes.root
60 });
61 return /*#__PURE__*/_jsx(TabsRoot, _extends({}, tabsRootProps, {
62 children: /*#__PURE__*/_jsx(TabsProvider, {
63 value: contextValue,
64 children: children
65 })
66 }));
67});
68process.env.NODE_ENV !== "production" ? Tabs.propTypes /* remove-proptypes */ = {
69 // ----------------------------- Warning --------------------------------
70 // | These PropTypes are generated from the TypeScript type definitions |
71 // | To update them edit TypeScript types and run "yarn proptypes" |
72 // ----------------------------------------------------------------------
73 /**
74 * The content of the component.
75 */
76 children: PropTypes.node,
77 /**
78 * The default value. Use when the component is not controlled.
79 */
80 defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
81 /**
82 * The direction of the text.
83 * @default 'ltr'
84 */
85 direction: PropTypes.oneOf(['ltr', 'rtl']),
86 /**
87 * Callback invoked when new value is being set.
88 */
89 onChange: PropTypes.func,
90 /**
91 * The component orientation (layout flow direction).
92 * @default 'horizontal'
93 */
94 orientation: PropTypes.oneOf(['horizontal', 'vertical']),
95 /**
96 * If `true` the selected tab changes on focus. Otherwise it only
97 * changes on activation.
98 */
99 selectionFollowsFocus: PropTypes.bool,
100 /**
101 * The props used for each slot inside the Tabs.
102 * @default {}
103 */
104 slotProps: PropTypes.shape({
105 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
106 }),
107 /**
108 * The components used for each slot inside the Tabs.
109 * Either a string to use a HTML element or a component.
110 * @default {}
111 */
112 slots: PropTypes.shape({
113 root: PropTypes.elementType
114 }),
115 /**
116 * The value of the currently selected `Tab`.
117 * If you don't want any selected `Tab`, you can set this prop to `null`.
118 */
119 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
120} : void 0;
121export default Tabs;
\No newline at end of file