Add isImage prop in RawIcon

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2021-12-30 12:44:14 +05:30
parent d3dcb320f4
commit c2402ddb72
3 changed files with 21 additions and 7 deletions

View file

@ -10,7 +10,7 @@ import Text from '../text/Text';
const IconButton = React.forwardRef(({
variant, size, type,
tooltip, tooltipPlacement, src,
onClick, tabIndex, disabled,
onClick, tabIndex, disabled, isImage,
}, ref) => {
const btn = (
<button
@ -23,7 +23,7 @@ const IconButton = React.forwardRef(({
tabIndex={tabIndex}
disabled={disabled}
>
<RawIcon size={size} src={src} />
<RawIcon size={size} src={src} isImage={isImage} />
</button>
);
if (tooltip === null) return btn;
@ -46,6 +46,7 @@ IconButton.defaultProps = {
onClick: null,
tabIndex: 0,
disabled: false,
isImage: false,
};
IconButton.propTypes = {
@ -58,6 +59,7 @@ IconButton.propTypes = {
onClick: PropTypes.func,
tabIndex: PropTypes.number,
disabled: PropTypes.bool,
isImage: PropTypes.bool,
};
export default IconButton;

View file

@ -2,24 +2,33 @@ import React from 'react';
import PropTypes from 'prop-types';
import './RawIcon.scss';
function RawIcon({ color, size, src }) {
const style = {
WebkitMaskImage: `url(${src})`,
maskImage: `url(${src})`,
};
function RawIcon({
color, size, src, isImage,
}) {
const style = {};
if (color !== null) style.backgroundColor = color;
if (isImage) {
style.backgroundColor = 'transparent';
style.backgroundImage = `url(${src})`;
} else {
style.WebkitMaskImage = `url(${src})`;
style.maskImage = `url(${src})`;
}
return <span className={`ic-raw ic-raw-${size}`} style={style}> </span>;
}
RawIcon.defaultProps = {
color: null,
size: 'normal',
isImage: false,
};
RawIcon.propTypes = {
color: PropTypes.string,
size: PropTypes.oneOf(['large', 'normal', 'small', 'extra-small']),
src: PropTypes.string.isRequired,
isImage: PropTypes.bool,
};
export default RawIcon;

View file

@ -10,6 +10,9 @@
-webkit-mask-size: cover;
mask-size: cover;
background-color: var(--ic-surface-normal);
background-size: cover;
background-repeat: no-repeat;
}
.ic-raw-large {
@include icSize(var(--ic-large));