UNPKG

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