UNPKG

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