1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import { alpha } from '@mui/system/colorManipulator';
|
9 | import { styled } from "../zero-styled/index.js";
|
10 | import memoTheme from "../utils/memoTheme.js";
|
11 | import createSimplePaletteValueFilter from "../utils/createSimplePaletteValueFilter.js";
|
12 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
13 | import ButtonBase from "../ButtonBase/index.js";
|
14 | import capitalize from "../utils/capitalize.js";
|
15 | import iconButtonClasses, { getIconButtonUtilityClass } from "./iconButtonClasses.js";
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | classes,
|
20 | disabled,
|
21 | color,
|
22 | edge,
|
23 | size
|
24 | } = ownerState;
|
25 | const slots = {
|
26 | root: ['root', disabled && 'disabled', color !== 'default' && `color${capitalize(color)}`, edge && `edge${capitalize(edge)}`, `size${capitalize(size)}`]
|
27 | };
|
28 | return composeClasses(slots, getIconButtonUtilityClass, classes);
|
29 | };
|
30 | const IconButtonRoot = styled(ButtonBase, {
|
31 | name: 'MuiIconButton',
|
32 | slot: 'Root',
|
33 | overridesResolver: (props, styles) => {
|
34 | const {
|
35 | ownerState
|
36 | } = props;
|
37 | return [styles.root, ownerState.color !== 'default' && styles[`color${capitalize(ownerState.color)}`], ownerState.edge && styles[`edge${capitalize(ownerState.edge)}`], styles[`size${capitalize(ownerState.size)}`]];
|
38 | }
|
39 | })(memoTheme(({
|
40 | theme
|
41 | }) => ({
|
42 | textAlign: 'center',
|
43 | flex: '0 0 auto',
|
44 | fontSize: theme.typography.pxToRem(24),
|
45 | padding: 8,
|
46 | borderRadius: '50%',
|
47 | color: (theme.vars || theme).palette.action.active,
|
48 | transition: theme.transitions.create('background-color', {
|
49 | duration: theme.transitions.duration.shortest
|
50 | }),
|
51 | variants: [{
|
52 | props: props => !props.disableRipple,
|
53 | style: {
|
54 | '--IconButton-hoverBg': theme.vars ? `rgba(${theme.vars.palette.action.activeChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha(theme.palette.action.active, theme.palette.action.hoverOpacity),
|
55 | '&:hover': {
|
56 | backgroundColor: 'var(--IconButton-hoverBg)',
|
57 |
|
58 | '@media (hover: none)': {
|
59 | backgroundColor: 'transparent'
|
60 | }
|
61 | }
|
62 | }
|
63 | }, {
|
64 | props: {
|
65 | edge: 'start'
|
66 | },
|
67 | style: {
|
68 | marginLeft: -12
|
69 | }
|
70 | }, {
|
71 | props: {
|
72 | edge: 'start',
|
73 | size: 'small'
|
74 | },
|
75 | style: {
|
76 | marginLeft: -3
|
77 | }
|
78 | }, {
|
79 | props: {
|
80 | edge: 'end'
|
81 | },
|
82 | style: {
|
83 | marginRight: -12
|
84 | }
|
85 | }, {
|
86 | props: {
|
87 | edge: 'end',
|
88 | size: 'small'
|
89 | },
|
90 | style: {
|
91 | marginRight: -3
|
92 | }
|
93 | }]
|
94 | })), memoTheme(({
|
95 | theme
|
96 | }) => ({
|
97 | variants: [{
|
98 | props: {
|
99 | color: 'inherit'
|
100 | },
|
101 | style: {
|
102 | color: 'inherit'
|
103 | }
|
104 | }, ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter())
|
105 | .map(([color]) => ({
|
106 | props: {
|
107 | color
|
108 | },
|
109 | style: {
|
110 | color: (theme.vars || theme).palette[color].main
|
111 | }
|
112 | })), ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter())
|
113 | .map(([color]) => ({
|
114 | props: {
|
115 | color
|
116 | },
|
117 | style: {
|
118 | '--IconButton-hoverBg': theme.vars ? `rgba(${(theme.vars || theme).palette[color].mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : alpha((theme.vars || theme).palette[color].main, theme.palette.action.hoverOpacity)
|
119 | }
|
120 | })), {
|
121 | props: {
|
122 | size: 'small'
|
123 | },
|
124 | style: {
|
125 | padding: 5,
|
126 | fontSize: theme.typography.pxToRem(18)
|
127 | }
|
128 | }, {
|
129 | props: {
|
130 | size: 'large'
|
131 | },
|
132 | style: {
|
133 | padding: 12,
|
134 | fontSize: theme.typography.pxToRem(28)
|
135 | }
|
136 | }],
|
137 | [`&.${iconButtonClasses.disabled}`]: {
|
138 | backgroundColor: 'transparent',
|
139 | color: (theme.vars || theme).palette.action.disabled
|
140 | }
|
141 | })));
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | const IconButton = React.forwardRef(function IconButton(inProps, ref) {
|
148 | const props = useDefaultProps({
|
149 | props: inProps,
|
150 | name: 'MuiIconButton'
|
151 | });
|
152 | const {
|
153 | edge = false,
|
154 | children,
|
155 | className,
|
156 | color = 'default',
|
157 | disabled = false,
|
158 | disableFocusRipple = false,
|
159 | size = 'medium',
|
160 | ...other
|
161 | } = props;
|
162 | const ownerState = {
|
163 | ...props,
|
164 | edge,
|
165 | color,
|
166 | disabled,
|
167 | disableFocusRipple,
|
168 | size
|
169 | };
|
170 | const classes = useUtilityClasses(ownerState);
|
171 | return _jsx(IconButtonRoot, {
|
172 | className: clsx(classes.root, className),
|
173 | centerRipple: true,
|
174 | focusRipple: !disableFocusRipple,
|
175 | disabled: disabled,
|
176 | ref: ref,
|
177 | ...other,
|
178 | ownerState: ownerState,
|
179 | children: children
|
180 | });
|
181 | });
|
182 | process.env.NODE_ENV !== "production" ? IconButton.propTypes = {
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | |
188 |
|
189 |
|
190 | children: chainPropTypes(PropTypes.node, props => {
|
191 | const found = React.Children.toArray(props.children).some(child => React.isValidElement(child) && child.props.onClick);
|
192 | if (found) {
|
193 | return new Error(['MUI: You are providing an onClick event listener to a child of a button element.', 'Prefer applying it to the IconButton directly.', 'This guarantees that the whole <button> will be responsive to click events.'].join('\n'));
|
194 | }
|
195 | return null;
|
196 | }),
|
197 | |
198 |
|
199 |
|
200 | classes: PropTypes.object,
|
201 | |
202 |
|
203 |
|
204 | className: PropTypes.string,
|
205 | |
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | color: PropTypes .oneOfType([PropTypes.oneOf(['inherit', 'default', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
|
212 | |
213 |
|
214 |
|
215 |
|
216 | disabled: PropTypes.bool,
|
217 | |
218 |
|
219 |
|
220 |
|
221 | disableFocusRipple: PropTypes.bool,
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | disableRipple: PropTypes.bool,
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | edge: PropTypes.oneOf(['end', 'start', false]),
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 | size: PropTypes .oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
244 | |
245 |
|
246 |
|
247 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
248 | } : void 0;
|
249 | export default IconButton; |
\ | No newline at end of file |