1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["children", "disabled", "label", "slots", "slotProps", "focusableWhenDisabled"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { useSlotProps } from '../utils';
|
9 | import { useMenuButton } from '../useMenuButton';
|
10 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
11 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
12 | import { getMenuButtonUtilityClass } from './menuButtonClasses';
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 | const useUtilityClasses = ownerState => {
|
15 | const {
|
16 | active,
|
17 | disabled,
|
18 | open
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', disabled && 'disabled', active && 'active', open && 'expanded']
|
22 | };
|
23 | return composeClasses(slots, useClassNamesOverride(getMenuButtonUtilityClass));
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | const MenuButton = React.forwardRef(function MenuButton(props, forwardedRef) {
|
37 | const {
|
38 | children,
|
39 | disabled = false,
|
40 | slots = {},
|
41 | slotProps = {},
|
42 | focusableWhenDisabled = false
|
43 | } = props,
|
44 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
45 | const {
|
46 | getRootProps,
|
47 | open,
|
48 | active
|
49 | } = useMenuButton({
|
50 | disabled,
|
51 | focusableWhenDisabled,
|
52 | rootRef: forwardedRef
|
53 | });
|
54 | const ownerState = _extends({}, props, {
|
55 | open,
|
56 | active,
|
57 | disabled,
|
58 | focusableWhenDisabled
|
59 | });
|
60 | const classes = useUtilityClasses(ownerState);
|
61 | const Root = slots.root || 'button';
|
62 | const rootProps = useSlotProps({
|
63 | elementType: Root,
|
64 | getSlotProps: getRootProps,
|
65 | externalForwardedProps: other,
|
66 | externalSlotProps: slotProps.root,
|
67 | additionalProps: {
|
68 | ref: forwardedRef,
|
69 | type: 'button'
|
70 | },
|
71 | ownerState,
|
72 | className: classes.root
|
73 | });
|
74 | return _jsx(Root, _extends({}, rootProps, {
|
75 | children: children
|
76 | }));
|
77 | });
|
78 | process.env.NODE_ENV !== "production" ? MenuButton.propTypes = {
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | |
84 |
|
85 |
|
86 | children: PropTypes.node,
|
87 | |
88 |
|
89 |
|
90 | className: PropTypes.string,
|
91 | |
92 |
|
93 |
|
94 |
|
95 | disabled: PropTypes.bool,
|
96 | |
97 |
|
98 |
|
99 |
|
100 | focusableWhenDisabled: PropTypes.bool,
|
101 | |
102 |
|
103 |
|
104 | label: PropTypes.string,
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | slotProps: PropTypes.shape({
|
111 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
112 | }),
|
113 | |
114 |
|
115 |
|
116 |
|
117 | slots: PropTypes.shape({
|
118 | root: PropTypes.elementType
|
119 | })
|
120 | } : void 0;
|
121 | export { MenuButton }; |
\ | No newline at end of file |