UNPKG

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