UNPKG

3.51 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import { getMenuItemUtilityClass } from './menuItemClasses';
6import useMenuItem from '../useMenuItem';
7import composeClasses from '../composeClasses';
8import useSlotProps from '../utils/useSlotProps';
9import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
10import { jsx as _jsx } from "react/jsx-runtime";
11function useUtilityClasses(ownerState) {
12 var disabled = ownerState.disabled,
13 focusVisible = ownerState.focusVisible;
14 var slots = {
15 root: ['root', disabled && 'disabled', focusVisible && 'focusVisible']
16 };
17 return composeClasses(slots, useClassNamesOverride(getMenuItemUtilityClass));
18}
19
20/**
21 *
22 * Demos:
23 *
24 * - [Menu](https://mui.com/base/react-menu/)
25 *
26 * API:
27 *
28 * - [MenuItem API](https://mui.com/base/react-menu/components-api/#menu-item)
29 */
30var MenuItem = /*#__PURE__*/React.forwardRef(function MenuItem(props, forwardedRef) {
31 var _slots$root;
32 var children = props.children,
33 _props$disabled = props.disabled,
34 disabledProp = _props$disabled === void 0 ? false : _props$disabled,
35 label = props.label,
36 _props$slotProps = props.slotProps,
37 slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
38 _props$slots = props.slots,
39 slots = _props$slots === void 0 ? {} : _props$slots,
40 other = _objectWithoutProperties(props, ["children", "disabled", "label", "slotProps", "slots"]);
41 var _useMenuItem = useMenuItem({
42 disabled: disabledProp,
43 rootRef: forwardedRef,
44 label: label
45 }),
46 getRootProps = _useMenuItem.getRootProps,
47 disabled = _useMenuItem.disabled,
48 focusVisible = _useMenuItem.focusVisible,
49 highlighted = _useMenuItem.highlighted;
50 var ownerState = _extends({}, props, {
51 disabled: disabled,
52 focusVisible: focusVisible,
53 highlighted: highlighted
54 });
55 var classes = useUtilityClasses(ownerState);
56 var Root = (_slots$root = slots.root) != null ? _slots$root : 'li';
57 var rootProps = useSlotProps({
58 elementType: Root,
59 getSlotProps: getRootProps,
60 externalSlotProps: slotProps.root,
61 externalForwardedProps: other,
62 className: classes.root,
63 ownerState: ownerState
64 });
65 return /*#__PURE__*/_jsx(Root, _extends({}, rootProps, {
66 children: children
67 }));
68});
69process.env.NODE_ENV !== "production" ? MenuItem.propTypes /* remove-proptypes */ = {
70 // ----------------------------- Warning --------------------------------
71 // | These PropTypes are generated from the TypeScript type definitions |
72 // | To update them edit TypeScript types and run "yarn proptypes" |
73 // ----------------------------------------------------------------------
74 /**
75 * @ignore
76 */
77 children: PropTypes.node,
78 /**
79 * @ignore
80 */
81 disabled: PropTypes.bool,
82 /**
83 * A text representation of the menu item's content.
84 * Used for keyboard text navigation matching.
85 */
86 label: PropTypes.string,
87 /**
88 * The props used for each slot inside the MenuItem.
89 * @default {}
90 */
91 slotProps: PropTypes.shape({
92 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
93 }),
94 /**
95 * The components used for each slot inside the MenuItem.
96 * Either a string to use a HTML element or a component.
97 * @default {}
98 */
99 slots: PropTypes.shape({
100 root: PropTypes.elementType
101 })
102} : void 0;
103export default MenuItem;
\No newline at end of file