UNPKG

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