UNPKG

4.79 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 _capitalize = _interopRequireDefault(require("../utils/capitalize"));
27
28var styles = function styles(theme) {
29 return {
30 /* Styles applied to the root element. */
31 root: {
32 userSelect: 'none',
33 fontSize: theme.typography.pxToRem(24),
34 width: '1em',
35 height: '1em',
36 // Chrome fix for https://bugs.chromium.org/p/chromium/issues/detail?id=820541
37 // To remove at some point.
38 overflow: 'hidden',
39 flexShrink: 0
40 },
41
42 /* Styles applied to the root element if `color="primary"`. */
43 colorPrimary: {
44 color: theme.palette.primary.main
45 },
46
47 /* Styles applied to the root element if `color="secondary"`. */
48 colorSecondary: {
49 color: theme.palette.secondary.main
50 },
51
52 /* Styles applied to the root element if `color="action"`. */
53 colorAction: {
54 color: theme.palette.action.active
55 },
56
57 /* Styles applied to the root element if `color="error"`. */
58 colorError: {
59 color: theme.palette.error.main
60 },
61
62 /* Styles applied to the root element if `color="disabled"`. */
63 colorDisabled: {
64 color: theme.palette.action.disabled
65 },
66
67 /* Styles applied to the root element if `fontSize="inherit"`. */
68 fontSizeInherit: {
69 fontSize: 'inherit'
70 },
71
72 /* Styles applied to the root element if `fontSize="small"`. */
73 fontSizeSmall: {
74 fontSize: theme.typography.pxToRem(20)
75 },
76
77 /* Styles applied to the root element if `fontSize="large"`. */
78 fontSizeLarge: {
79 fontSize: theme.typography.pxToRem(36)
80 }
81 };
82};
83
84exports.styles = styles;
85var Icon = /*#__PURE__*/React.forwardRef(function Icon(props, ref) {
86 var classes = props.classes,
87 className = props.className,
88 _props$color = props.color,
89 color = _props$color === void 0 ? 'inherit' : _props$color,
90 _props$component = props.component,
91 Component = _props$component === void 0 ? 'span' : _props$component,
92 _props$fontSize = props.fontSize,
93 fontSize = _props$fontSize === void 0 ? 'medium' : _props$fontSize,
94 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "component", "fontSize"]);
95 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
96 className: (0, _clsx.default)('material-icons', classes.root, className, color !== 'inherit' && classes["color".concat((0, _capitalize.default)(color))], fontSize !== 'default' && fontSize !== 'medium' && classes["fontSize".concat((0, _capitalize.default)(fontSize))]),
97 "aria-hidden": true,
98 ref: ref
99 }, other));
100});
101process.env.NODE_ENV !== "production" ? Icon.propTypes = {
102 /**
103 * The name of the icon font ligature.
104 */
105 children: _propTypes.default.node,
106
107 /**
108 * Override or extend the styles applied to the component.
109 * See [CSS API](#css) below for more details.
110 */
111 classes: _propTypes.default.object.isRequired,
112
113 /**
114 * @ignore
115 */
116 className: _propTypes.default.string,
117
118 /**
119 * The color of the component. It supports those theme colors that make sense for this component.
120 */
121 color: _propTypes.default.oneOf(['inherit', 'primary', 'secondary', 'action', 'error', 'disabled']),
122
123 /**
124 * The component used for the root node.
125 * Either a string to use a HTML element or a component.
126 */
127 component: _propTypes.default
128 /* @typescript-to-proptypes-ignore */
129 .elementType,
130
131 /**
132 * The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
133 */
134 fontSize: (0, _utils.chainPropTypes)(_propTypes.default.oneOf(['default', 'inherit', 'large', 'medium', 'small']), function (props) {
135 var fontSize = props.fontSize;
136
137 if (fontSize === 'default') {
138 throw new Error('Material-UI: `fontSize="default"` is deprecated. Use `fontSize="medium"` instead.');
139 }
140
141 return null;
142 })
143} : void 0;
144Icon.muiName = 'Icon';
145
146var _default = (0, _withStyles.default)(styles, {
147 name: 'MuiIcon'
148})(Icon);
149
150exports.default = _default;
\No newline at end of file