UNPKG

3.73 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import { chainPropTypes } from '@material-ui/utils';
7import withStyles from '../styles/withStyles';
8import capitalize from '../utils/capitalize';
9export const styles = theme => ({
10 /* Styles applied to the root element. */
11 root: {
12 userSelect: 'none',
13 fontSize: theme.typography.pxToRem(24),
14 width: '1em',
15 height: '1em',
16 // Chrome fix for https://bugs.chromium.org/p/chromium/issues/detail?id=820541
17 // To remove at some point.
18 overflow: 'hidden',
19 flexShrink: 0
20 },
21
22 /* Styles applied to the root element if `color="primary"`. */
23 colorPrimary: {
24 color: theme.palette.primary.main
25 },
26
27 /* Styles applied to the root element if `color="secondary"`. */
28 colorSecondary: {
29 color: theme.palette.secondary.main
30 },
31
32 /* Styles applied to the root element if `color="action"`. */
33 colorAction: {
34 color: theme.palette.action.active
35 },
36
37 /* Styles applied to the root element if `color="error"`. */
38 colorError: {
39 color: theme.palette.error.main
40 },
41
42 /* Styles applied to the root element if `color="disabled"`. */
43 colorDisabled: {
44 color: theme.palette.action.disabled
45 },
46
47 /* Styles applied to the root element if `fontSize="inherit"`. */
48 fontSizeInherit: {
49 fontSize: 'inherit'
50 },
51
52 /* Styles applied to the root element if `fontSize="small"`. */
53 fontSizeSmall: {
54 fontSize: theme.typography.pxToRem(20)
55 },
56
57 /* Styles applied to the root element if `fontSize="large"`. */
58 fontSizeLarge: {
59 fontSize: theme.typography.pxToRem(36)
60 }
61});
62const Icon = /*#__PURE__*/React.forwardRef(function Icon(props, ref) {
63 const {
64 classes,
65 className,
66 color = 'inherit',
67 component: Component = 'span',
68 fontSize = 'medium'
69 } = props,
70 other = _objectWithoutPropertiesLoose(props, ["classes", "className", "color", "component", "fontSize"]);
71
72 return /*#__PURE__*/React.createElement(Component, _extends({
73 className: clsx('material-icons', classes.root, className, color !== 'inherit' && classes[`color${capitalize(color)}`], fontSize !== 'default' && fontSize !== 'medium' && classes[`fontSize${capitalize(fontSize)}`]),
74 "aria-hidden": true,
75 ref: ref
76 }, other));
77});
78process.env.NODE_ENV !== "production" ? Icon.propTypes = {
79 /**
80 * The name of the icon font ligature.
81 */
82 children: PropTypes.node,
83
84 /**
85 * Override or extend the styles applied to the component.
86 * See [CSS API](#css) below for more details.
87 */
88 classes: PropTypes.object.isRequired,
89
90 /**
91 * @ignore
92 */
93 className: PropTypes.string,
94
95 /**
96 * The color of the component. It supports those theme colors that make sense for this component.
97 */
98 color: PropTypes.oneOf(['inherit', 'primary', 'secondary', 'action', 'error', 'disabled']),
99
100 /**
101 * The component used for the root node.
102 * Either a string to use a HTML element or a component.
103 */
104 component: PropTypes
105 /* @typescript-to-proptypes-ignore */
106 .elementType,
107
108 /**
109 * The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
110 */
111 fontSize: chainPropTypes(PropTypes.oneOf(['default', 'inherit', 'large', 'medium', 'small']), props => {
112 const {
113 fontSize
114 } = props;
115
116 if (fontSize === 'default') {
117 throw new Error('Material-UI: `fontSize="default"` is deprecated. Use `fontSize="medium"` instead.');
118 }
119
120 return null;
121 })
122} : void 0;
123Icon.muiName = 'Icon';
124export default withStyles(styles, {
125 name: 'MuiIcon'
126})(Icon);
\No newline at end of file