UNPKG

5.41 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3const _excluded = ["baseClassName", "className", "color", "component", "fontSize"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import styled from '../styles/styled';
9import useThemeProps from '../styles/useThemeProps';
10import capitalize from '../utils/capitalize';
11import { getIconUtilityClass } from './iconClasses';
12import { jsx as _jsx } from "react/jsx-runtime";
13
14const useUtilityClasses = ownerState => {
15 const {
16 color,
17 fontSize,
18 classes
19 } = ownerState;
20 const slots = {
21 root: ['root', color !== 'inherit' && `color${capitalize(color)}`, `fontSize${capitalize(fontSize)}`]
22 };
23 return composeClasses(slots, getIconUtilityClass, classes);
24};
25
26const IconRoot = styled('span', {
27 name: 'MuiIcon',
28 slot: 'Root',
29 overridesResolver: (props, styles) => {
30 const {
31 ownerState
32 } = props;
33 return [styles.root, ownerState.color !== 'inherit' && styles[`color${capitalize(ownerState.color)}`], styles[`fontSize${capitalize(ownerState.fontSize)}`]];
34 }
35})(({
36 theme,
37 ownerState
38}) => ({
39 userSelect: 'none',
40 width: '1em',
41 height: '1em',
42 // Chrome fix for https://bugs.chromium.org/p/chromium/issues/detail?id=820541
43 // To remove at some point.
44 overflow: 'hidden',
45 display: 'inline-block',
46 // allow overflow hidden to take action
47 textAlign: 'center',
48 // support non-square icon
49 flexShrink: 0,
50 fontSize: {
51 inherit: 'inherit',
52 small: theme.typography.pxToRem(20),
53 medium: theme.typography.pxToRem(24),
54 large: theme.typography.pxToRem(36)
55 }[ownerState.fontSize],
56 // TODO v5 deprecate, v6 remove for sx
57 color: {
58 primary: (theme.vars || theme).palette.primary.main,
59 secondary: (theme.vars || theme).palette.secondary.main,
60 info: (theme.vars || theme).palette.info.main,
61 success: (theme.vars || theme).palette.success.main,
62 warning: (theme.vars || theme).palette.warning.main,
63 action: (theme.vars || theme).palette.action.active,
64 error: (theme.vars || theme).palette.error.main,
65 disabled: (theme.vars || theme).palette.action.disabled,
66 inherit: undefined
67 }[ownerState.color]
68}));
69const Icon = /*#__PURE__*/React.forwardRef(function Icon(inProps, ref) {
70 const props = useThemeProps({
71 props: inProps,
72 name: 'MuiIcon'
73 });
74
75 const {
76 baseClassName = 'material-icons',
77 className,
78 color = 'inherit',
79 component: Component = 'span',
80 fontSize = 'medium'
81 } = props,
82 other = _objectWithoutPropertiesLoose(props, _excluded);
83
84 const ownerState = _extends({}, props, {
85 baseClassName,
86 color,
87 component: Component,
88 fontSize
89 });
90
91 const classes = useUtilityClasses(ownerState);
92 return /*#__PURE__*/_jsx(IconRoot, _extends({
93 as: Component,
94 className: clsx(baseClassName, // Prevent the translation of the text content.
95 // The font relies on the exact text content to render the icon.
96 'notranslate', classes.root, className),
97 ownerState: ownerState,
98 "aria-hidden": true,
99 ref: ref
100 }, other));
101});
102process.env.NODE_ENV !== "production" ? Icon.propTypes
103/* remove-proptypes */
104= {
105 // ----------------------------- Warning --------------------------------
106 // | These PropTypes are generated from the TypeScript type definitions |
107 // | To update them edit the d.ts file and run "yarn proptypes" |
108 // ----------------------------------------------------------------------
109
110 /**
111 * The base class applied to the icon. Defaults to 'material-icons', but can be changed to any
112 * other base class that suits the icon font you're using (e.g. material-icons-rounded, fas, etc).
113 * @default 'material-icons'
114 */
115 baseClassName: PropTypes.string,
116
117 /**
118 * The name of the icon font ligature.
119 */
120 children: PropTypes.node,
121
122 /**
123 * Override or extend the styles applied to the component.
124 */
125 classes: PropTypes.object,
126
127 /**
128 * @ignore
129 */
130 className: PropTypes.string,
131
132 /**
133 * The color of the component.
134 * It supports both default and custom theme colors, which can be added as shown in the
135 * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
136 * @default 'inherit'
137 */
138 color: PropTypes
139 /* @typescript-to-proptypes-ignore */
140 .oneOfType([PropTypes.oneOf(['inherit', 'action', 'disabled', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
141
142 /**
143 * The component used for the root node.
144 * Either a string to use a HTML element or a component.
145 */
146 component: PropTypes.elementType,
147
148 /**
149 * The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
150 * @default 'medium'
151 */
152 fontSize: PropTypes
153 /* @typescript-to-proptypes-ignore */
154 .oneOfType([PropTypes.oneOf(['inherit', 'large', 'medium', 'small']), PropTypes.string]),
155
156 /**
157 * The system prop that allows defining system overrides as well as additional CSS styles.
158 */
159 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
160} : void 0;
161Icon.muiName = 'Icon';
162export default Icon;
\No newline at end of file