1 | 'use client';
|
2 |
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
5 | import _extends from "@babel/runtime/helpers/esm/extends";
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import clsx from 'clsx';
|
9 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
10 | import composeClasses from '@mui/utils/composeClasses';
|
11 | import { alpha } from '@mui/system/colorManipulator';
|
12 | import styled from '../styles/styled';
|
13 | import { useDefaultProps } from '../DefaultPropsProvider';
|
14 | import ButtonBase from '../ButtonBase';
|
15 | import capitalize from '../utils/capitalize';
|
16 | import iconButtonClasses, { getIconButtonUtilityClass } from './iconButtonClasses';
|
17 | import { jsx as _jsx } from "react/jsx-runtime";
|
18 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
19 | var classes = ownerState.classes,
|
20 | disabled = ownerState.disabled,
|
21 | color = ownerState.color,
|
22 | edge = ownerState.edge,
|
23 | size = ownerState.size;
|
24 | var slots = {
|
25 | root: ['root', disabled && 'disabled', color !== 'default' && "color".concat(capitalize(color)), edge && "edge".concat(capitalize(edge)), "size".concat(capitalize(size))]
|
26 | };
|
27 | return composeClasses(slots, getIconButtonUtilityClass, classes);
|
28 | };
|
29 | var IconButtonRoot = styled(ButtonBase, {
|
30 | name: 'MuiIconButton',
|
31 | slot: 'Root',
|
32 | overridesResolver: function overridesResolver(props, styles) {
|
33 | var ownerState = props.ownerState;
|
34 | return [styles.root, ownerState.color !== 'default' && styles["color".concat(capitalize(ownerState.color))], ownerState.edge && styles["edge".concat(capitalize(ownerState.edge))], styles["size".concat(capitalize(ownerState.size))]];
|
35 | }
|
36 | })(function (_ref) {
|
37 | var theme = _ref.theme,
|
38 | ownerState = _ref.ownerState;
|
39 | return _extends({
|
40 | textAlign: 'center',
|
41 | flex: '0 0 auto',
|
42 | fontSize: theme.typography.pxToRem(24),
|
43 | padding: 8,
|
44 | borderRadius: '50%',
|
45 | overflow: 'visible',
|
46 |
|
47 | color: (theme.vars || theme).palette.action.active,
|
48 | transition: theme.transitions.create('background-color', {
|
49 | duration: theme.transitions.duration.shortest
|
50 | })
|
51 | }, !ownerState.disableRipple && {
|
52 | '&:hover': {
|
53 | backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.action.activeChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(theme.palette.action.active, theme.palette.action.hoverOpacity),
|
54 |
|
55 | '@media (hover: none)': {
|
56 | backgroundColor: 'transparent'
|
57 | }
|
58 | }
|
59 | }, ownerState.edge === 'start' && {
|
60 | marginLeft: ownerState.size === 'small' ? -3 : -12
|
61 | }, ownerState.edge === 'end' && {
|
62 | marginRight: ownerState.size === 'small' ? -3 : -12
|
63 | });
|
64 | }, function (_ref2) {
|
65 | var _palette;
|
66 | var theme = _ref2.theme,
|
67 | ownerState = _ref2.ownerState;
|
68 | var palette = (_palette = (theme.vars || theme).palette) == null ? void 0 : _palette[ownerState.color];
|
69 | return _extends({}, ownerState.color === 'inherit' && {
|
70 | color: 'inherit'
|
71 | }, ownerState.color !== 'inherit' && ownerState.color !== 'default' && _extends({
|
72 | color: palette == null ? void 0 : palette.main
|
73 | }, !ownerState.disableRipple && {
|
74 | '&:hover': _extends({}, palette && {
|
75 | backgroundColor: theme.vars ? "rgba(".concat(palette.mainChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(palette.main, theme.palette.action.hoverOpacity)
|
76 | }, {
|
77 |
|
78 | '@media (hover: none)': {
|
79 | backgroundColor: 'transparent'
|
80 | }
|
81 | })
|
82 | }), ownerState.size === 'small' && {
|
83 | padding: 5,
|
84 | fontSize: theme.typography.pxToRem(18)
|
85 | }, ownerState.size === 'large' && {
|
86 | padding: 12,
|
87 | fontSize: theme.typography.pxToRem(28)
|
88 | }, _defineProperty({}, "&.".concat(iconButtonClasses.disabled), {
|
89 | backgroundColor: 'transparent',
|
90 | color: (theme.vars || theme).palette.action.disabled
|
91 | }));
|
92 | });
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var IconButton = React.forwardRef(function IconButton(inProps, ref) {
|
99 | var props = useDefaultProps({
|
100 | props: inProps,
|
101 | name: 'MuiIconButton'
|
102 | });
|
103 | var _props$edge = props.edge,
|
104 | edge = _props$edge === void 0 ? false : _props$edge,
|
105 | children = props.children,
|
106 | className = props.className,
|
107 | _props$color = props.color,
|
108 | color = _props$color === void 0 ? 'default' : _props$color,
|
109 | _props$disabled = props.disabled,
|
110 | disabled = _props$disabled === void 0 ? false : _props$disabled,
|
111 | _props$disableFocusRi = props.disableFocusRipple,
|
112 | disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi,
|
113 | _props$size = props.size,
|
114 | size = _props$size === void 0 ? 'medium' : _props$size,
|
115 | other = _objectWithoutProperties(props, ["edge", "children", "className", "color", "disabled", "disableFocusRipple", "size"]);
|
116 | var ownerState = _extends({}, props, {
|
117 | edge: edge,
|
118 | color: color,
|
119 | disabled: disabled,
|
120 | disableFocusRipple: disableFocusRipple,
|
121 | size: size
|
122 | });
|
123 | var classes = useUtilityClasses(ownerState);
|
124 | return _jsx(IconButtonRoot, _extends({
|
125 | className: clsx(classes.root, className),
|
126 | centerRipple: true,
|
127 | focusRipple: !disableFocusRipple,
|
128 | disabled: disabled,
|
129 | ref: ref
|
130 | }, other, {
|
131 | ownerState: ownerState,
|
132 | children: children
|
133 | }));
|
134 | });
|
135 | process.env.NODE_ENV !== "production" ? IconButton.propTypes = {
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | |
141 |
|
142 |
|
143 | children: chainPropTypes(PropTypes.node, function (props) {
|
144 | var found = React.Children.toArray(props.children).some(function (child) {
|
145 | return React.isValidElement(child) && child.props.onClick;
|
146 | });
|
147 | if (found) {
|
148 | 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'));
|
149 | }
|
150 | return null;
|
151 | }),
|
152 | |
153 |
|
154 |
|
155 | classes: PropTypes.object,
|
156 | |
157 |
|
158 |
|
159 | className: PropTypes.string,
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 | color: PropTypes .oneOfType([PropTypes.oneOf(['inherit', 'default', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
|
167 | |
168 |
|
169 |
|
170 |
|
171 | disabled: PropTypes.bool,
|
172 | |
173 |
|
174 |
|
175 |
|
176 | disableFocusRipple: PropTypes.bool,
|
177 | |
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | disableRipple: PropTypes.bool,
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | edge: PropTypes.oneOf(['end', 'start', false]),
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 | size: PropTypes .oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
199 | |
200 |
|
201 |
|
202 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
203 | } : void 0;
|
204 | export default IconButton; |
\ | No newline at end of file |