UNPKG

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