UNPKG

5.47 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _utils = require("@mui/utils");
13var _composeClasses = _interopRequireDefault(require("../composeClasses"));
14var _tabClasses = require("./tabClasses");
15var _useTab = _interopRequireDefault(require("../useTab"));
16var _utils2 = require("../utils");
17var _ClassNameConfigurator = require("../utils/ClassNameConfigurator");
18var _jsxRuntime = require("react/jsx-runtime");
19const _excluded = ["action", "children", "value", "disabled", "onChange", "onClick", "onFocus", "slotProps", "slots"];
20function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22const useUtilityClasses = ownerState => {
23 const {
24 selected,
25 disabled
26 } = ownerState;
27 const slots = {
28 root: ['root', selected && 'selected', disabled && 'disabled']
29 };
30 return (0, _composeClasses.default)(slots, (0, _ClassNameConfigurator.useClassNamesOverride)(_tabClasses.getTabUtilityClass));
31};
32/**
33 *
34 * Demos:
35 *
36 * - [Tabs](https://mui.com/base/react-tabs/)
37 *
38 * API:
39 *
40 * - [Tab API](https://mui.com/base/react-tabs/components-api/#tab)
41 */
42const Tab = /*#__PURE__*/React.forwardRef(function Tab(props, forwardedRef) {
43 var _slots$root;
44 const {
45 children,
46 disabled = false,
47 slotProps = {},
48 slots = {}
49 } = props,
50 other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
51 const tabRef = React.useRef();
52 const handleRef = (0, _utils.unstable_useForkRef)(tabRef, forwardedRef);
53 const {
54 active,
55 highlighted,
56 selected,
57 getRootProps
58 } = (0, _useTab.default)((0, _extends2.default)({}, props, {
59 rootRef: handleRef
60 }));
61 const ownerState = (0, _extends2.default)({}, props, {
62 active,
63 disabled,
64 highlighted,
65 selected
66 });
67 const classes = useUtilityClasses(ownerState);
68 const TabRoot = (_slots$root = slots.root) != null ? _slots$root : 'button';
69 const tabRootProps = (0, _utils2.useSlotProps)({
70 elementType: TabRoot,
71 getSlotProps: getRootProps,
72 externalSlotProps: slotProps.root,
73 externalForwardedProps: other,
74 additionalProps: {
75 ref: forwardedRef
76 },
77 ownerState,
78 className: classes.root
79 });
80 return /*#__PURE__*/(0, _jsxRuntime.jsx)(TabRoot, (0, _extends2.default)({}, tabRootProps, {
81 children: children
82 }));
83});
84process.env.NODE_ENV !== "production" ? Tab.propTypes /* remove-proptypes */ = {
85 // ----------------------------- Warning --------------------------------
86 // | These PropTypes are generated from the TypeScript type definitions |
87 // | To update them edit TypeScript types and run "yarn proptypes" |
88 // ----------------------------------------------------------------------
89 /**
90 * A ref for imperative actions. It currently only supports `focusVisible()` action.
91 */
92 action: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
93 current: _propTypes.default.shape({
94 focusVisible: _propTypes.default.func.isRequired
95 })
96 })]),
97 /**
98 * @ignore
99 */
100 children: _propTypes.default.node,
101 /**
102 * If `true`, the component is disabled.
103 * @default false
104 */
105 disabled: _propTypes.default.bool,
106 /**
107 * Callback invoked when new value is being set.
108 */
109 onChange: _propTypes.default.func,
110 /**
111 * The props used for each slot inside the Tab.
112 * @default {}
113 */
114 slotProps: _propTypes.default.shape({
115 root: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object])
116 }),
117 /**
118 * The components used for each slot inside the Tab.
119 * Either a string to use a HTML element or a component.
120 * @default {}
121 */
122 slots: _propTypes.default.shape({
123 root: _propTypes.default.elementType
124 }),
125 /**
126 * You can provide your own value. Otherwise, it falls back to the child position index.
127 */
128 value: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
129} : void 0;
130var _default = Tab;
131exports.default = _default;
\No newline at end of file