1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import { alpha } from '@mui/system/colorManipulator';
|
8 | import { styled } from "../zero-styled/index.js";
|
9 | import memoTheme from "../utils/memoTheme.js";
|
10 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
11 | import rootShouldForwardProp from "../styles/rootShouldForwardProp.js";
|
12 | import ButtonBase from "../ButtonBase/index.js";
|
13 | import useEnhancedEffect from "../utils/useEnhancedEffect.js";
|
14 | import useForkRef from "../utils/useForkRef.js";
|
15 | import ListContext from "../List/ListContext.js";
|
16 | import listItemButtonClasses, { getListItemButtonUtilityClass } from "./listItemButtonClasses.js";
|
17 | import { jsx as _jsx } from "react/jsx-runtime";
|
18 | export const overridesResolver = (props, styles) => {
|
19 | const {
|
20 | ownerState
|
21 | } = props;
|
22 | return [styles.root, ownerState.dense && styles.dense, ownerState.alignItems === 'flex-start' && styles.alignItemsFlexStart, ownerState.divider && styles.divider, !ownerState.disableGutters && styles.gutters];
|
23 | };
|
24 | const useUtilityClasses = ownerState => {
|
25 | const {
|
26 | alignItems,
|
27 | classes,
|
28 | dense,
|
29 | disabled,
|
30 | disableGutters,
|
31 | divider,
|
32 | selected
|
33 | } = ownerState;
|
34 | const slots = {
|
35 | root: ['root', dense && 'dense', !disableGutters && 'gutters', divider && 'divider', disabled && 'disabled', alignItems === 'flex-start' && 'alignItemsFlexStart', selected && 'selected']
|
36 | };
|
37 | const composedClasses = composeClasses(slots, getListItemButtonUtilityClass, classes);
|
38 | return {
|
39 | ...classes,
|
40 | ...composedClasses
|
41 | };
|
42 | };
|
43 | const ListItemButtonRoot = styled(ButtonBase, {
|
44 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
45 | name: 'MuiListItemButton',
|
46 | slot: 'Root',
|
47 | overridesResolver
|
48 | })(memoTheme(({
|
49 | theme
|
50 | }) => ({
|
51 | display: 'flex',
|
52 | flexGrow: 1,
|
53 | justifyContent: 'flex-start',
|
54 | alignItems: 'center',
|
55 | position: 'relative',
|
56 | textDecoration: 'none',
|
57 | minWidth: 0,
|
58 | boxSizing: 'border-box',
|
59 | textAlign: 'left',
|
60 | paddingTop: 8,
|
61 | paddingBottom: 8,
|
62 | transition: theme.transitions.create('background-color', {
|
63 | duration: theme.transitions.duration.shortest
|
64 | }),
|
65 | '&:hover': {
|
66 | textDecoration: 'none',
|
67 | backgroundColor: (theme.vars || theme).palette.action.hover,
|
68 |
|
69 | '@media (hover: none)': {
|
70 | backgroundColor: 'transparent'
|
71 | }
|
72 | },
|
73 | [`&.${listItemButtonClasses.selected}`]: {
|
74 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
|
75 | [`&.${listItemButtonClasses.focusVisible}`]: {
|
76 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.focusOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
|
77 | }
|
78 | },
|
79 | [`&.${listItemButtonClasses.selected}:hover`]: {
|
80 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
|
81 |
|
82 | '@media (hover: none)': {
|
83 | backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity)
|
84 | }
|
85 | },
|
86 | [`&.${listItemButtonClasses.focusVisible}`]: {
|
87 | backgroundColor: (theme.vars || theme).palette.action.focus
|
88 | },
|
89 | [`&.${listItemButtonClasses.disabled}`]: {
|
90 | opacity: (theme.vars || theme).palette.action.disabledOpacity
|
91 | },
|
92 | variants: [{
|
93 | props: ({
|
94 | ownerState
|
95 | }) => ownerState.divider,
|
96 | style: {
|
97 | borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`,
|
98 | backgroundClip: 'padding-box'
|
99 | }
|
100 | }, {
|
101 | props: {
|
102 | alignItems: 'flex-start'
|
103 | },
|
104 | style: {
|
105 | alignItems: 'flex-start'
|
106 | }
|
107 | }, {
|
108 | props: ({
|
109 | ownerState
|
110 | }) => !ownerState.disableGutters,
|
111 | style: {
|
112 | paddingLeft: 16,
|
113 | paddingRight: 16
|
114 | }
|
115 | }, {
|
116 | props: ({
|
117 | ownerState
|
118 | }) => ownerState.dense,
|
119 | style: {
|
120 | paddingTop: 4,
|
121 | paddingBottom: 4
|
122 | }
|
123 | }]
|
124 | })));
|
125 | const ListItemButton = React.forwardRef(function ListItemButton(inProps, ref) {
|
126 | const props = useDefaultProps({
|
127 | props: inProps,
|
128 | name: 'MuiListItemButton'
|
129 | });
|
130 | const {
|
131 | alignItems = 'center',
|
132 | autoFocus = false,
|
133 | component = 'div',
|
134 | children,
|
135 | dense = false,
|
136 | disableGutters = false,
|
137 | divider = false,
|
138 | focusVisibleClassName,
|
139 | selected = false,
|
140 | className,
|
141 | ...other
|
142 | } = props;
|
143 | const context = React.useContext(ListContext);
|
144 | const childContext = React.useMemo(() => ({
|
145 | dense: dense || context.dense || false,
|
146 | alignItems,
|
147 | disableGutters
|
148 | }), [alignItems, context.dense, dense, disableGutters]);
|
149 | const listItemRef = React.useRef(null);
|
150 | useEnhancedEffect(() => {
|
151 | if (autoFocus) {
|
152 | if (listItemRef.current) {
|
153 | listItemRef.current.focus();
|
154 | } else if (process.env.NODE_ENV !== 'production') {
|
155 | console.error('MUI: Unable to set focus to a ListItemButton whose component has not been rendered.');
|
156 | }
|
157 | }
|
158 | }, [autoFocus]);
|
159 | const ownerState = {
|
160 | ...props,
|
161 | alignItems,
|
162 | dense: childContext.dense,
|
163 | disableGutters,
|
164 | divider,
|
165 | selected
|
166 | };
|
167 | const classes = useUtilityClasses(ownerState);
|
168 | const handleRef = useForkRef(listItemRef, ref);
|
169 | return _jsx(ListContext.Provider, {
|
170 | value: childContext,
|
171 | children: _jsx(ListItemButtonRoot, {
|
172 | ref: handleRef,
|
173 | href: other.href || other.to
|
174 |
|
175 | ,
|
176 | component: (other.href || other.to) && component === 'div' ? 'button' : component,
|
177 | focusVisibleClassName: clsx(classes.focusVisible, focusVisibleClassName),
|
178 | ownerState: ownerState,
|
179 | className: clsx(classes.root, className),
|
180 | ...other,
|
181 | classes: classes,
|
182 | children: children
|
183 | })
|
184 | });
|
185 | });
|
186 | process.env.NODE_ENV !== "production" ? ListItemButton.propTypes = {
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 | alignItems: PropTypes.oneOf(['center', 'flex-start']),
|
196 | |
197 |
|
198 |
|
199 |
|
200 |
|
201 | autoFocus: PropTypes.bool,
|
202 | |
203 |
|
204 |
|
205 |
|
206 | children: PropTypes.node,
|
207 | |
208 |
|
209 |
|
210 | classes: PropTypes.object,
|
211 | |
212 |
|
213 |
|
214 | className: PropTypes.string,
|
215 | |
216 |
|
217 |
|
218 |
|
219 | component: PropTypes.elementType,
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 | dense: PropTypes.bool,
|
226 | |
227 |
|
228 |
|
229 |
|
230 | disabled: PropTypes.bool,
|
231 | |
232 |
|
233 |
|
234 |
|
235 | disableGutters: PropTypes.bool,
|
236 | |
237 |
|
238 |
|
239 |
|
240 | divider: PropTypes.bool,
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | focusVisibleClassName: PropTypes.string,
|
250 | |
251 |
|
252 |
|
253 | href: PropTypes.string,
|
254 | |
255 |
|
256 |
|
257 |
|
258 | selected: PropTypes.bool,
|
259 | |
260 |
|
261 |
|
262 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
263 | } : void 0;
|
264 | export default ListItemButton; |
\ | No newline at end of file |