UNPKG

3.99 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 const {
37 children,
38 disabled = false,
39 slotProps = {},
40 slots = {},
41 value
42 } = props,
43 other = _objectWithoutPropertiesLoose(props, _excluded);
44 const tabRef = React.useRef();
45 const handleRef = useForkRef(tabRef, forwardedRef);
46 const {
47 active,
48 highlighted,
49 selected,
50 getRootProps
51 } = useTab(_extends({}, props, {
52 rootRef: handleRef,
53 value
54 }));
55 const ownerState = _extends({}, props, {
56 active,
57 disabled,
58 highlighted,
59 selected
60 });
61 const classes = useUtilityClasses(ownerState);
62 const TabRoot = slots.root ?? 'button';
63 const tabRootProps = useSlotProps({
64 elementType: TabRoot,
65 getSlotProps: getRootProps,
66 externalSlotProps: slotProps.root,
67 externalForwardedProps: other,
68 additionalProps: {
69 ref: forwardedRef
70 },
71 ownerState,
72 className: classes.root
73 });
74 return /*#__PURE__*/_jsx(TabRoot, _extends({}, tabRootProps, {
75 children: children
76 }));
77});
78process.env.NODE_ENV !== "production" ? Tab.propTypes /* remove-proptypes */ = {
79 // ┌────────────────────────────── Warning ──────────────────────────────┐
80 // │ These PropTypes are generated from the TypeScript type definitions. │
81 // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
82 // └─────────────────────────────────────────────────────────────────────┘
83 /**
84 * A ref for imperative actions. It currently only supports `focusVisible()` action.
85 */
86 action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
87 current: PropTypes.shape({
88 focusVisible: PropTypes.func.isRequired
89 })
90 })]),
91 /**
92 * @ignore
93 */
94 children: PropTypes.node,
95 /**
96 * If `true`, the component is disabled.
97 * @default false
98 */
99 disabled: PropTypes.bool,
100 /**
101 * Callback invoked when new value is being set.
102 */
103 onChange: PropTypes.func,
104 /**
105 * The props used for each slot inside the Tab.
106 * @default {}
107 */
108 slotProps: PropTypes.shape({
109 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
110 }),
111 /**
112 * The components used for each slot inside the Tab.
113 * Either a string to use a HTML element or a component.
114 * @default {}
115 */
116 slots: PropTypes.shape({
117 root: PropTypes.elementType
118 }),
119 /**
120 * You can provide your own value. Otherwise, it falls back to the child position index.
121 */
122 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
123} : void 0;
124export { Tab };
\No newline at end of file