2022-09-20 19:15:14 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
|
|
|
|
import {
|
|
|
|
SIZES,
|
|
|
|
COLORS,
|
|
|
|
ICON_COLORS,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
2022-12-15 23:46:30 +01:00
|
|
|
import { ICON_SIZES, ICON_NAMES } from './icon.constants';
|
2022-11-23 18:58:43 +01:00
|
|
|
|
2022-09-20 19:15:14 +02:00
|
|
|
export const Icon = ({
|
|
|
|
name,
|
|
|
|
size = SIZES.MD,
|
|
|
|
color = COLORS.INHERIT,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
color={color}
|
2022-11-23 18:58:43 +01:00
|
|
|
className={classnames(className, 'mm-icon', `mm-icon--size-${size}`)}
|
2022-09-20 19:15:14 +02:00
|
|
|
style={{
|
|
|
|
/**
|
|
|
|
* To reduce the possibility of injection attacks
|
|
|
|
* the icon component uses mask-image instead of rendering
|
|
|
|
* the svg directly.
|
|
|
|
*/
|
2023-01-24 18:39:46 +01:00
|
|
|
maskImage: `url('./images/icons/${name}.svg')`,
|
|
|
|
WebkitMaskImage: `url('./images/icons/${name}.svg')`,
|
2022-09-20 19:15:14 +02:00
|
|
|
...style,
|
|
|
|
}}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Icon.propTypes = {
|
|
|
|
/**
|
|
|
|
* The name of the icon to display. Should be one of ICON_NAMES
|
|
|
|
*/
|
2022-12-15 23:46:30 +01:00
|
|
|
name: PropTypes.oneOf(Object.values(ICON_NAMES)).isRequired,
|
2022-09-20 19:15:14 +02:00
|
|
|
/**
|
|
|
|
* The size of the Icon.
|
2023-01-24 18:39:46 +01:00
|
|
|
* Possible values could be SIZES.XS (12px), SIZES.SM (16px), SIZES.MD (20px), SIZES.LG (24px), SIZES.XL (32px),
|
2022-11-23 18:58:43 +01:00
|
|
|
* Default value is SIZES.MD (20px).
|
2022-09-20 19:15:14 +02:00
|
|
|
*/
|
2022-11-23 18:58:43 +01:00
|
|
|
size: PropTypes.oneOf(Object.values(ICON_SIZES)),
|
2022-09-20 19:15:14 +02:00
|
|
|
/**
|
|
|
|
* The color of the icon.
|
|
|
|
* Defaults to COLORS.INHERIT.
|
|
|
|
*/
|
|
|
|
color: PropTypes.oneOf(Object.values(ICON_COLORS)),
|
|
|
|
/**
|
|
|
|
* An additional className to apply to the icon.
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Addition style properties to apply to the icon.
|
|
|
|
* The Icon component uses inline styles to apply the icon's mask-image so be wary of overriding
|
|
|
|
*/
|
2022-10-03 20:00:19 +02:00
|
|
|
style: PropTypes.object,
|
2022-09-20 19:15:14 +02:00
|
|
|
/**
|
|
|
|
* Icon accepts all the props from Box
|
|
|
|
*/
|
|
|
|
...Box.propTypes,
|
|
|
|
};
|