FrontPastel/node_modules/@mui/base/Tab/Tab.js

125 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-04-17 13:55:11 +00:00
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["action", "children", "disabled", "onChange", "onClick", "onFocus", "slotProps", "slots", "value"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { unstable_composeClasses as composeClasses } from '../composeClasses';
import { getTabUtilityClass } from './tabClasses';
import { useTab } from '../useTab';
import { useSlotProps } from '../utils';
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
selected,
disabled
} = ownerState;
const slots = {
root: ['root', selected && 'selected', disabled && 'disabled']
};
return composeClasses(slots, useClassNamesOverride(getTabUtilityClass));
};
/**
*
* Demos:
*
* - [Tabs](https://mui.com/base-ui/react-tabs/)
*
* API:
*
* - [Tab API](https://mui.com/base-ui/react-tabs/components-api/#tab)
*/
const Tab = /*#__PURE__*/React.forwardRef(function Tab(props, forwardedRef) {
var _slots$root;
const {
children,
disabled = false,
slotProps = {},
slots = {},
value
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const tabRef = React.useRef();
const handleRef = useForkRef(tabRef, forwardedRef);
const {
active,
highlighted,
selected,
getRootProps
} = useTab(_extends({}, props, {
rootRef: handleRef,
value
}));
const ownerState = _extends({}, props, {
active,
disabled,
highlighted,
selected
});
const classes = useUtilityClasses(ownerState);
const TabRoot = (_slots$root = slots.root) != null ? _slots$root : 'button';
const tabRootProps = useSlotProps({
elementType: TabRoot,
getSlotProps: getRootProps,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
additionalProps: {
ref: forwardedRef
},
ownerState,
className: classes.root
});
return /*#__PURE__*/_jsx(TabRoot, _extends({}, tabRootProps, {
children: children
}));
});
process.env.NODE_ENV !== "production" ? Tab.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* A ref for imperative actions. It currently only supports `focusVisible()` action.
*/
action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
current: PropTypes.shape({
focusVisible: PropTypes.func.isRequired
})
})]),
/**
* @ignore
*/
children: PropTypes.node,
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* Callback invoked when new value is being set.
*/
onChange: PropTypes.func,
/**
* The props used for each slot inside the Tab.
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside the Tab.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType
}),
/**
* You can provide your own value. Otherwise, it falls back to the child position index.
*/
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
} : void 0;
export { Tab };