UNPKG

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