UNPKG

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