UNPKG

5.15 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import capitalize from '../utils/capitalize';
8export const styles = theme => ({
9 /* Styles applied to the root element. */
10 root: {
11 userSelect: 'none',
12 width: '1em',
13 height: '1em',
14 display: 'inline-block',
15 fill: 'currentColor',
16 flexShrink: 0,
17 fontSize: theme.typography.pxToRem(24),
18 transition: theme.transitions.create('fill', {
19 duration: theme.transitions.duration.shorter
20 })
21 },
22
23 /* Styles applied to the root element if `color="primary"`. */
24 colorPrimary: {
25 color: theme.palette.primary.main
26 },
27
28 /* Styles applied to the root element if `color="secondary"`. */
29 colorSecondary: {
30 color: theme.palette.secondary.main
31 },
32
33 /* Styles applied to the root element if `color="action"`. */
34 colorAction: {
35 color: theme.palette.action.active
36 },
37
38 /* Styles applied to the root element if `color="error"`. */
39 colorError: {
40 color: theme.palette.error.main
41 },
42
43 /* Styles applied to the root element if `color="disabled"`. */
44 colorDisabled: {
45 color: theme.palette.action.disabled
46 },
47
48 /* Styles applied to the root element if `fontSize="inherit"`. */
49 fontSizeInherit: {
50 fontSize: 'inherit'
51 },
52
53 /* Styles applied to the root element if `fontSize="small"`. */
54 fontSizeSmall: {
55 fontSize: theme.typography.pxToRem(20)
56 },
57
58 /* Styles applied to the root element if `fontSize="large"`. */
59 fontSizeLarge: {
60 fontSize: theme.typography.pxToRem(35)
61 }
62});
63const SvgIcon = /*#__PURE__*/React.forwardRef(function SvgIcon(props, ref) {
64 const {
65 children,
66 classes,
67 className,
68 color = 'inherit',
69 component: Component = 'svg',
70 fontSize = 'default',
71 htmlColor,
72 titleAccess,
73 viewBox = '0 0 24 24'
74 } = props,
75 other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "color", "component", "fontSize", "htmlColor", "titleAccess", "viewBox"]);
76
77 return /*#__PURE__*/React.createElement(Component, _extends({
78 className: clsx(classes.root, className, color !== 'inherit' && classes[`color${capitalize(color)}`], fontSize !== 'default' && classes[`fontSize${capitalize(fontSize)}`]),
79 focusable: "false",
80 viewBox: viewBox,
81 color: htmlColor,
82 "aria-hidden": titleAccess ? undefined : true,
83 role: titleAccess ? 'img' : undefined,
84 ref: ref
85 }, other), children, titleAccess ? /*#__PURE__*/React.createElement("title", null, titleAccess) : null);
86});
87process.env.NODE_ENV !== "production" ? SvgIcon.propTypes = {
88 // ----------------------------- Warning --------------------------------
89 // | These PropTypes are generated from the TypeScript type definitions |
90 // | To update them edit the d.ts file and run "yarn proptypes" |
91 // ----------------------------------------------------------------------
92
93 /**
94 * Node passed into the SVG element.
95 */
96 children: PropTypes.node,
97
98 /**
99 * Override or extend the styles applied to the component.
100 * See [CSS API](#css) below for more details.
101 */
102 classes: PropTypes.object,
103
104 /**
105 * @ignore
106 */
107 className: PropTypes.string,
108
109 /**
110 * The color of the component. It supports those theme colors that make sense for this component.
111 * You can use the `htmlColor` prop to apply a color attribute to the SVG element.
112 */
113 color: PropTypes.oneOf(['action', 'disabled', 'error', 'inherit', 'primary', 'secondary']),
114
115 /**
116 * The component used for the root node.
117 * Either a string to use a HTML element or a component.
118 */
119 component: PropTypes
120 /* @typescript-to-proptypes-ignore */
121 .elementType,
122
123 /**
124 * The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
125 */
126 fontSize: PropTypes.oneOf(['default', 'inherit', 'large', 'small']),
127
128 /**
129 * Applies a color attribute to the SVG element.
130 */
131 htmlColor: PropTypes.string,
132
133 /**
134 * The shape-rendering attribute. The behavior of the different options is described on the
135 * [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/shape-rendering).
136 * If you are having issues with blurry icons you should investigate this property.
137 */
138 shapeRendering: PropTypes.string,
139
140 /**
141 * Provides a human-readable title for the element that contains it.
142 * https://www.w3.org/TR/SVG-access/#Equivalent
143 */
144 titleAccess: PropTypes.string,
145
146 /**
147 * Allows you to redefine what the coordinates without units mean inside an SVG element.
148 * For example, if the SVG element is 500 (width) by 200 (height),
149 * and you pass viewBox="0 0 50 20",
150 * this means that the coordinates inside the SVG will go from the top left corner (0,0)
151 * to bottom right (50,20) and each unit will be worth 10px.
152 */
153 viewBox: PropTypes.string
154} : void 0;
155SvgIcon.muiName = 'SvgIcon';
156export default withStyles(styles, {
157 name: 'MuiSvgIcon'
158})(SvgIcon);
\No newline at end of file