UNPKG

6.62 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3const _excluded = ["children", "className", "color", "component", "fontSize", "htmlColor", "inheritViewBox", "titleAccess", "viewBox"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import capitalize from '../utils/capitalize';
9import useThemeProps from '../styles/useThemeProps';
10import styled from '../styles/styled';
11import { getSvgIconUtilityClass } from './svgIconClasses';
12import { jsx as _jsx } from "react/jsx-runtime";
13import { jsxs as _jsxs } from "react/jsx-runtime";
14
15const useUtilityClasses = ownerState => {
16 const {
17 color,
18 fontSize,
19 classes
20 } = ownerState;
21 const slots = {
22 root: ['root', color !== 'inherit' && `color${capitalize(color)}`, `fontSize${capitalize(fontSize)}`]
23 };
24 return composeClasses(slots, getSvgIconUtilityClass, classes);
25};
26
27const SvgIconRoot = styled('svg', {
28 name: 'MuiSvgIcon',
29 slot: 'Root',
30 overridesResolver: (props, styles) => {
31 const {
32 ownerState
33 } = props;
34 return [styles.root, ownerState.color !== 'inherit' && styles[`color${capitalize(ownerState.color)}`], styles[`fontSize${capitalize(ownerState.fontSize)}`]];
35 }
36})(({
37 theme,
38 ownerState
39}) => ({
40 userSelect: 'none',
41 width: '1em',
42 height: '1em',
43 display: 'inline-block',
44 fill: 'currentColor',
45 flexShrink: 0,
46 transition: theme.transitions?.create?.('fill', {
47 duration: theme.transitions?.duration?.shorter
48 }),
49 fontSize: {
50 inherit: 'inherit',
51 small: theme.typography?.pxToRem?.(20) || '1.25rem',
52 medium: theme.typography?.pxToRem?.(24) || '1.5rem',
53 large: theme.typography?.pxToRem?.(35) || '2.1875'
54 }[ownerState.fontSize],
55 // TODO v5 deprecate, v6 remove for sx
56 color: (theme.vars || theme).palette?.[ownerState.color]?.main ?? {
57 action: (theme.vars || theme).palette?.action?.active,
58 disabled: (theme.vars || theme).palette?.action?.disabled,
59 inherit: undefined
60 }[ownerState.color]
61}));
62const SvgIcon = /*#__PURE__*/React.forwardRef(function SvgIcon(inProps, ref) {
63 const props = useThemeProps({
64 props: inProps,
65 name: 'MuiSvgIcon'
66 });
67
68 const {
69 children,
70 className,
71 color = 'inherit',
72 component = 'svg',
73 fontSize = 'medium',
74 htmlColor,
75 inheritViewBox = false,
76 titleAccess,
77 viewBox = '0 0 24 24'
78 } = props,
79 other = _objectWithoutPropertiesLoose(props, _excluded);
80
81 const ownerState = _extends({}, props, {
82 color,
83 component,
84 fontSize,
85 instanceFontSize: inProps.fontSize,
86 inheritViewBox,
87 viewBox
88 });
89
90 const more = {};
91
92 if (!inheritViewBox) {
93 more.viewBox = viewBox;
94 }
95
96 const classes = useUtilityClasses(ownerState);
97 return /*#__PURE__*/_jsxs(SvgIconRoot, _extends({
98 as: component,
99 className: clsx(classes.root, className),
100 ownerState: ownerState,
101 focusable: "false",
102 color: htmlColor,
103 "aria-hidden": titleAccess ? undefined : true,
104 role: titleAccess ? 'img' : undefined,
105 ref: ref
106 }, more, other, {
107 children: [children, titleAccess ? /*#__PURE__*/_jsx("title", {
108 children: titleAccess
109 }) : null]
110 }));
111});
112process.env.NODE_ENV !== "production" ? SvgIcon.propTypes
113/* remove-proptypes */
114= {
115 // ----------------------------- Warning --------------------------------
116 // | These PropTypes are generated from the TypeScript type definitions |
117 // | To update them edit the d.ts file and run "yarn proptypes" |
118 // ----------------------------------------------------------------------
119
120 /**
121 * Node passed into the SVG element.
122 */
123 children: PropTypes.node,
124
125 /**
126 * Override or extend the styles applied to the component.
127 */
128 classes: PropTypes.object,
129
130 /**
131 * @ignore
132 */
133 className: PropTypes.string,
134
135 /**
136 * The color of the component.
137 * It supports both default and custom theme colors, which can be added as shown in the
138 * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
139 * You can use the `htmlColor` prop to apply a color attribute to the SVG element.
140 * @default 'inherit'
141 */
142 color: PropTypes
143 /* @typescript-to-proptypes-ignore */
144 .oneOfType([PropTypes.oneOf(['inherit', 'action', 'disabled', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
145
146 /**
147 * The component used for the root node.
148 * Either a string to use a HTML element or a component.
149 */
150 component: PropTypes.elementType,
151
152 /**
153 * The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
154 * @default 'medium'
155 */
156 fontSize: PropTypes
157 /* @typescript-to-proptypes-ignore */
158 .oneOfType([PropTypes.oneOf(['inherit', 'large', 'medium', 'small']), PropTypes.string]),
159
160 /**
161 * Applies a color attribute to the SVG element.
162 */
163 htmlColor: PropTypes.string,
164
165 /**
166 * If `true`, the root node will inherit the custom `component`'s viewBox and the `viewBox`
167 * prop will be ignored.
168 * Useful when you want to reference a custom `component` and have `SvgIcon` pass that
169 * `component`'s viewBox to the root node.
170 * @default false
171 */
172 inheritViewBox: PropTypes.bool,
173
174 /**
175 * The shape-rendering attribute. The behavior of the different options is described on the
176 * [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/shape-rendering).
177 * If you are having issues with blurry icons you should investigate this prop.
178 */
179 shapeRendering: PropTypes.string,
180
181 /**
182 * The system prop that allows defining system overrides as well as additional CSS styles.
183 */
184 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
185
186 /**
187 * Provides a human-readable title for the element that contains it.
188 * https://www.w3.org/TR/SVG-access/#Equivalent
189 */
190 titleAccess: PropTypes.string,
191
192 /**
193 * Allows you to redefine what the coordinates without units mean inside an SVG element.
194 * For example, if the SVG element is 500 (width) by 200 (height),
195 * and you pass viewBox="0 0 50 20",
196 * this means that the coordinates inside the SVG will go from the top left corner (0,0)
197 * to bottom right (50,20) and each unit will be worth 10px.
198 * @default '0 0 24 24'
199 */
200 viewBox: PropTypes.string
201} : void 0;
202SvgIcon.muiName = 'SvgIcon';
203export default SvgIcon;
\No newline at end of file