UNPKG

8.79 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5import _extends from "@babel/runtime/helpers/esm/extends";
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import clsx from 'clsx';
9import chainPropTypes from '@mui/utils/chainPropTypes';
10import composeClasses from '@mui/utils/composeClasses';
11import { alpha } from '@mui/system/colorManipulator';
12import styled from '../styles/styled';
13import { useDefaultProps } from '../DefaultPropsProvider';
14import ButtonBase from '../ButtonBase';
15import capitalize from '../utils/capitalize';
16import iconButtonClasses, { getIconButtonUtilityClass } from './iconButtonClasses';
17import { jsx as _jsx } from "react/jsx-runtime";
18var 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};
29var 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 // Explicitly set the default value to solve a bug on IE11.
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 // Reset on touch devices, it doesn't add specificity
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 // Reset on touch devices, it doesn't add specificity
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 * Refer to the [Icons](/material-ui/icons/) section of the documentation
96 * regarding the available icon options.
97 */
98var IconButton = /*#__PURE__*/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 /*#__PURE__*/_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});
135process.env.NODE_ENV !== "production" ? IconButton.propTypes /* remove-proptypes */ = {
136 // ┌────────────────────────────── Warning ──────────────────────────────┐
137 // │ These PropTypes are generated from the TypeScript type definitions. │
138 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
139 // └─────────────────────────────────────────────────────────────────────┘
140 /**
141 * The icon to display.
142 */
143 children: chainPropTypes(PropTypes.node, function (props) {
144 var found = React.Children.toArray(props.children).some(function (child) {
145 return /*#__PURE__*/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 * Override or extend the styles applied to the component.
154 */
155 classes: PropTypes.object,
156 /**
157 * @ignore
158 */
159 className: PropTypes.string,
160 /**
161 * The color of the component.
162 * It supports both default and custom theme colors, which can be added as shown in the
163 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
164 * @default 'default'
165 */
166 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['inherit', 'default', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
167 /**
168 * If `true`, the component is disabled.
169 * @default false
170 */
171 disabled: PropTypes.bool,
172 /**
173 * If `true`, the keyboard focus ripple is disabled.
174 * @default false
175 */
176 disableFocusRipple: PropTypes.bool,
177 /**
178 * If `true`, the ripple effect is disabled.
179 *
180 * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
181 * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
182 * @default false
183 */
184 disableRipple: PropTypes.bool,
185 /**
186 * If given, uses a negative margin to counteract the padding on one
187 * side (this is often helpful for aligning the left or right
188 * side of the icon with content above or below, without ruining the border
189 * size and shape).
190 * @default false
191 */
192 edge: PropTypes.oneOf(['end', 'start', false]),
193 /**
194 * The size of the component.
195 * `small` is equivalent to the dense button styling.
196 * @default 'medium'
197 */
198 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
199 /**
200 * The system prop that allows defining system overrides as well as additional CSS styles.
201 */
202 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
203} : void 0;
204export default IconButton;
\No newline at end of file