UNPKG

7.37 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _utils = require("@material-ui/utils");
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _colorManipulator = require("../styles/colorManipulator");
27
28var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
29
30var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
31
32var styles = function styles(theme) {
33 return {
34 /* Styles applied to the root element. */
35 root: {
36 textAlign: 'center',
37 flex: '0 0 auto',
38 fontSize: theme.typography.pxToRem(24),
39 padding: 12,
40 borderRadius: '50%',
41 overflow: 'visible',
42 // Explicitly set the default value to solve a bug on IE 11.
43 color: theme.palette.action.active,
44 transition: theme.transitions.create('background-color', {
45 duration: theme.transitions.duration.shortest
46 }),
47 '&:hover': {
48 backgroundColor: (0, _colorManipulator.fade)(theme.palette.action.active, theme.palette.action.hoverOpacity),
49 // Reset on touch devices, it doesn't add specificity
50 '@media (hover: none)': {
51 backgroundColor: 'transparent'
52 }
53 },
54 '&$disabled': {
55 backgroundColor: 'transparent',
56 color: theme.palette.action.disabled
57 }
58 },
59
60 /* Styles applied to the root element if `edge="start"`. */
61 edgeStart: {
62 marginLeft: -12,
63 '$sizeSmall&': {
64 marginLeft: -3
65 }
66 },
67
68 /* Styles applied to the root element if `edge="end"`. */
69 edgeEnd: {
70 marginRight: -12,
71 '$sizeSmall&': {
72 marginRight: -3
73 }
74 },
75
76 /* Styles applied to the root element if `color="inherit"`. */
77 colorInherit: {
78 color: 'inherit'
79 },
80
81 /* Styles applied to the root element if `color="primary"`. */
82 colorPrimary: {
83 color: theme.palette.primary.main,
84 '&:hover': {
85 backgroundColor: (0, _colorManipulator.fade)(theme.palette.primary.main, theme.palette.action.hoverOpacity),
86 // Reset on touch devices, it doesn't add specificity
87 '@media (hover: none)': {
88 backgroundColor: 'transparent'
89 }
90 }
91 },
92
93 /* Styles applied to the root element if `color="secondary"`. */
94 colorSecondary: {
95 color: theme.palette.secondary.main,
96 '&:hover': {
97 backgroundColor: (0, _colorManipulator.fade)(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
98 // Reset on touch devices, it doesn't add specificity
99 '@media (hover: none)': {
100 backgroundColor: 'transparent'
101 }
102 }
103 },
104
105 /* Pseudo-class applied to the root element if `disabled={true}`. */
106 disabled: {},
107
108 /* Styles applied to the root element if `size="small"`. */
109 sizeSmall: {
110 padding: 3,
111 fontSize: theme.typography.pxToRem(18)
112 },
113
114 /* Styles applied to the children container element. */
115 label: {
116 width: '100%',
117 display: 'flex',
118 alignItems: 'inherit',
119 justifyContent: 'inherit'
120 }
121 };
122};
123/**
124 * Refer to the [Icons](/components/icons/) section of the documentation
125 * regarding the available icon options.
126 */
127
128
129exports.styles = styles;
130var IconButton = /*#__PURE__*/React.forwardRef(function IconButton(props, ref) {
131 var _props$edge = props.edge,
132 edge = _props$edge === void 0 ? false : _props$edge,
133 children = props.children,
134 classes = props.classes,
135 className = props.className,
136 _props$color = props.color,
137 color = _props$color === void 0 ? 'default' : _props$color,
138 _props$disabled = props.disabled,
139 disabled = _props$disabled === void 0 ? false : _props$disabled,
140 _props$disableFocusRi = props.disableFocusRipple,
141 disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi,
142 _props$size = props.size,
143 size = _props$size === void 0 ? 'medium' : _props$size,
144 other = (0, _objectWithoutProperties2.default)(props, ["edge", "children", "classes", "className", "color", "disabled", "disableFocusRipple", "size"]);
145 return /*#__PURE__*/React.createElement(_ButtonBase.default, (0, _extends2.default)({
146 className: (0, _clsx.default)(classes.root, className, color !== 'default' && classes["color".concat((0, _capitalize.default)(color))], disabled && classes.disabled, size === "small" && classes["size".concat((0, _capitalize.default)(size))], {
147 'start': classes.edgeStart,
148 'end': classes.edgeEnd
149 }[edge]),
150 centerRipple: true,
151 focusRipple: !disableFocusRipple,
152 disabled: disabled,
153 ref: ref
154 }, other), /*#__PURE__*/React.createElement("span", {
155 className: classes.label
156 }, children));
157});
158process.env.NODE_ENV !== "production" ? IconButton.propTypes = {
159 /**
160 * The icon element.
161 */
162 children: (0, _utils.chainPropTypes)(_propTypes.default.node, function (props) {
163 var found = React.Children.toArray(props.children).some(function (child) {
164 return /*#__PURE__*/React.isValidElement(child) && child.props.onClick;
165 });
166
167 if (found) {
168 return new Error(['Material-UI: You are providing an onClick event listener ' + 'to a child of a button element.', 'Firefox will never trigger the event.', 'You should move the onClick listener to the parent button element.', 'https://github.com/mui-org/material-ui/issues/13957'].join('\n'));
169 }
170
171 return null;
172 }),
173
174 /**
175 * Override or extend the styles applied to the component.
176 * See [CSS API](#css) below for more details.
177 */
178 classes: _propTypes.default.object.isRequired,
179
180 /**
181 * @ignore
182 */
183 className: _propTypes.default.string,
184
185 /**
186 * The color of the component. It supports those theme colors that make sense for this component.
187 */
188 color: _propTypes.default.oneOf(['default', 'inherit', 'primary', 'secondary']),
189
190 /**
191 * If `true`, the button will be disabled.
192 */
193 disabled: _propTypes.default.bool,
194
195 /**
196 * If `true`, the keyboard focus ripple will be disabled.
197 */
198 disableFocusRipple: _propTypes.default.bool,
199
200 /**
201 * If `true`, the ripple effect will be disabled.
202 */
203 disableRipple: _propTypes.default.bool,
204
205 /**
206 * If given, uses a negative margin to counteract the padding on one
207 * side (this is often helpful for aligning the left or right
208 * side of the icon with content above or below, without ruining the border
209 * size and shape).
210 */
211 edge: _propTypes.default.oneOf(['start', 'end', false]),
212
213 /**
214 * The size of the button.
215 * `small` is equivalent to the dense button styling.
216 */
217 size: _propTypes.default.oneOf(['small', 'medium'])
218} : void 0;
219
220var _default = (0, _withStyles.default)(styles, {
221 name: 'MuiIconButton'
222})(IconButton);
223
224exports.default = _default;
\No newline at end of file