materialuiupgraded
Version:
Material-UI's workspace package
112 lines (104 loc) • 3.15 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalize } from '../utils/helpers';
export const styles = theme => ({
/* Styles applied to the root element. */
root: {
userSelect: 'none',
fontSize: 24,
width: '1em',
height: '1em',
// Chrome fix for https://bugs.chromium.org/p/chromium/issues/detail?id=820541
// To remove at some point.
overflow: 'hidden',
flexShrink: 0,
},
/* Styles applied to the root element if `color="primary"`. */
colorPrimary: {
color: theme.palette.primary.main,
},
/* Styles applied to the root element if `color="secondary"`. */
colorSecondary: {
color: theme.palette.secondary.main,
},
/* Styles applied to the root element if `color="action"`. */
colorAction: {
color: theme.palette.action.active,
},
/* Styles applied to the root element if `color="error"`. */
colorError: {
color: theme.palette.error.main,
},
/* Styles applied to the root element if `color="disabled"`. */
colorDisabled: {
color: theme.palette.action.disabled,
},
fontSizeInherit: {
fontSize: 'inherit',
},
/* Styles applied to the root element if `fontSize="small"`. */
fontSizeSmall: {
fontSize: 20,
},
/* Styles applied to the root element if `fontSize="large"`. */
fontSizeLarge: {
fontSize: 36,
},
});
function Icon(props) {
const { children, classes, className, color, component: Component, fontSize, ...other } = props;
return (
<Component
className={classNames(
'material-icons',
classes.root,
{
[]]: color !== 'inherit',
[]]: fontSize !== 'default',
},
className,
)}
aria-hidden="true"
{...other}
>
{children}
</Component>
);
}
Icon.propTypes = {
/**
* The name of the icon font ligature.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css-api) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['inherit', 'primary', 'secondary', 'action', 'error', 'disabled']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
/**
* The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size.
*/
fontSize: PropTypes.oneOf(['inherit', 'default', 'small', 'large']),
};
Icon.defaultProps = {
color: 'inherit',
component: 'span',
fontSize: 'default',
};
Icon.muiName = 'Icon';
export default withStyles(styles, { name: 'MuiIcon' })(Icon);