UNPKG

9.17 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _chainPropTypes = _interopRequireDefault(require("@mui/utils/chainPropTypes"));
14var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15var _colorManipulator = require("@mui/system/colorManipulator");
16var _zeroStyled = require("../zero-styled");
17var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
18var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
19var _DefaultPropsProvider = require("../DefaultPropsProvider");
20var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
21var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
22var _iconButtonClasses = _interopRequireWildcard(require("./iconButtonClasses"));
23var _jsxRuntime = require("react/jsx-runtime");
24const useUtilityClasses = ownerState => {
25 const {
26 classes,
27 disabled,
28 color,
29 edge,
30 size
31 } = ownerState;
32 const slots = {
33 root: ['root', disabled && 'disabled', color !== 'default' && `color${(0, _capitalize.default)(color)}`, edge && `edge${(0, _capitalize.default)(edge)}`, `size${(0, _capitalize.default)(size)}`]
34 };
35 return (0, _composeClasses.default)(slots, _iconButtonClasses.getIconButtonUtilityClass, classes);
36};
37const IconButtonRoot = (0, _zeroStyled.styled)(_ButtonBase.default, {
38 name: 'MuiIconButton',
39 slot: 'Root',
40 overridesResolver: (props, styles) => {
41 const {
42 ownerState
43 } = props;
44 return [styles.root, ownerState.color !== 'default' && styles[`color${(0, _capitalize.default)(ownerState.color)}`], ownerState.edge && styles[`edge${(0, _capitalize.default)(ownerState.edge)}`], styles[`size${(0, _capitalize.default)(ownerState.size)}`]];
45 }
46})((0, _memoTheme.default)(({
47 theme
48}) => ({
49 textAlign: 'center',
50 flex: '0 0 auto',
51 fontSize: theme.typography.pxToRem(24),
52 padding: 8,
53 borderRadius: '50%',
54 color: (theme.vars || theme).palette.action.active,
55 transition: theme.transitions.create('background-color', {
56 duration: theme.transitions.duration.shortest
57 }),
58 variants: [{
59 props: props => !props.disableRipple,
60 style: {
61 '--IconButton-hoverBg': theme.vars ? `rgba(${theme.vars.palette.action.activeChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)(theme.palette.action.active, theme.palette.action.hoverOpacity),
62 '&:hover': {
63 backgroundColor: 'var(--IconButton-hoverBg)',
64 // Reset on touch devices, it doesn't add specificity
65 '@media (hover: none)': {
66 backgroundColor: 'transparent'
67 }
68 }
69 }
70 }, {
71 props: {
72 edge: 'start'
73 },
74 style: {
75 marginLeft: -12
76 }
77 }, {
78 props: {
79 edge: 'start',
80 size: 'small'
81 },
82 style: {
83 marginLeft: -3
84 }
85 }, {
86 props: {
87 edge: 'end'
88 },
89 style: {
90 marginRight: -12
91 }
92 }, {
93 props: {
94 edge: 'end',
95 size: 'small'
96 },
97 style: {
98 marginRight: -3
99 }
100 }]
101})), (0, _memoTheme.default)(({
102 theme
103}) => ({
104 variants: [{
105 props: {
106 color: 'inherit'
107 },
108 style: {
109 color: 'inherit'
110 }
111 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()) // check all the used fields in the style below
112 .map(([color]) => ({
113 props: {
114 color
115 },
116 style: {
117 color: (theme.vars || theme).palette[color].main
118 }
119 })), ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()) // check all the used fields in the style below
120 .map(([color]) => ({
121 props: {
122 color
123 },
124 style: {
125 '--IconButton-hoverBg': theme.vars ? `rgba(${(theme.vars || theme).palette[color].mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _colorManipulator.alpha)((theme.vars || theme).palette[color].main, theme.palette.action.hoverOpacity)
126 }
127 })), {
128 props: {
129 size: 'small'
130 },
131 style: {
132 padding: 5,
133 fontSize: theme.typography.pxToRem(18)
134 }
135 }, {
136 props: {
137 size: 'large'
138 },
139 style: {
140 padding: 12,
141 fontSize: theme.typography.pxToRem(28)
142 }
143 }],
144 [`&.${_iconButtonClasses.default.disabled}`]: {
145 backgroundColor: 'transparent',
146 color: (theme.vars || theme).palette.action.disabled
147 }
148})));
149
150/**
151 * Refer to the [Icons](/material-ui/icons/) section of the documentation
152 * regarding the available icon options.
153 */
154const IconButton = /*#__PURE__*/React.forwardRef(function IconButton(inProps, ref) {
155 const props = (0, _DefaultPropsProvider.useDefaultProps)({
156 props: inProps,
157 name: 'MuiIconButton'
158 });
159 const {
160 edge = false,
161 children,
162 className,
163 color = 'default',
164 disabled = false,
165 disableFocusRipple = false,
166 size = 'medium',
167 ...other
168 } = props;
169 const ownerState = {
170 ...props,
171 edge,
172 color,
173 disabled,
174 disableFocusRipple,
175 size
176 };
177 const classes = useUtilityClasses(ownerState);
178 return /*#__PURE__*/(0, _jsxRuntime.jsx)(IconButtonRoot, {
179 className: (0, _clsx.default)(classes.root, className),
180 centerRipple: true,
181 focusRipple: !disableFocusRipple,
182 disabled: disabled,
183 ref: ref,
184 ...other,
185 ownerState: ownerState,
186 children: children
187 });
188});
189process.env.NODE_ENV !== "production" ? IconButton.propTypes /* remove-proptypes */ = {
190 // ┌────────────────────────────── Warning ──────────────────────────────┐
191 // │ These PropTypes are generated from the TypeScript type definitions. │
192 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
193 // └─────────────────────────────────────────────────────────────────────┘
194 /**
195 * The icon to display.
196 */
197 children: (0, _chainPropTypes.default)(_propTypes.default.node, props => {
198 const found = React.Children.toArray(props.children).some(child => /*#__PURE__*/React.isValidElement(child) && child.props.onClick);
199 if (found) {
200 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'));
201 }
202 return null;
203 }),
204 /**
205 * Override or extend the styles applied to the component.
206 */
207 classes: _propTypes.default.object,
208 /**
209 * @ignore
210 */
211 className: _propTypes.default.string,
212 /**
213 * The color of the component.
214 * It supports both default and custom theme colors, which can be added as shown in the
215 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
216 * @default 'default'
217 */
218 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['inherit', 'default', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), _propTypes.default.string]),
219 /**
220 * If `true`, the component is disabled.
221 * @default false
222 */
223 disabled: _propTypes.default.bool,
224 /**
225 * If `true`, the keyboard focus ripple is disabled.
226 * @default false
227 */
228 disableFocusRipple: _propTypes.default.bool,
229 /**
230 * If `true`, the ripple effect is disabled.
231 *
232 * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
233 * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
234 * @default false
235 */
236 disableRipple: _propTypes.default.bool,
237 /**
238 * If given, uses a negative margin to counteract the padding on one
239 * side (this is often helpful for aligning the left or right
240 * side of the icon with content above or below, without ruining the border
241 * size and shape).
242 * @default false
243 */
244 edge: _propTypes.default.oneOf(['end', 'start', false]),
245 /**
246 * The size of the component.
247 * `small` is equivalent to the dense button styling.
248 * @default 'medium'
249 */
250 size: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['small', 'medium', 'large']), _propTypes.default.string]),
251 /**
252 * The system prop that allows defining system overrides as well as additional CSS styles.
253 */
254 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
255} : void 0;
256var _default = exports.default = IconButton;
\No newline at end of file