Add isImage prop in RawIcon
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
d3dcb320f4
commit
c2402ddb72
3 changed files with 21 additions and 7 deletions
|
@ -10,7 +10,7 @@ import Text from '../text/Text';
|
||||||
const IconButton = React.forwardRef(({
|
const IconButton = React.forwardRef(({
|
||||||
variant, size, type,
|
variant, size, type,
|
||||||
tooltip, tooltipPlacement, src,
|
tooltip, tooltipPlacement, src,
|
||||||
onClick, tabIndex, disabled,
|
onClick, tabIndex, disabled, isImage,
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const btn = (
|
const btn = (
|
||||||
<button
|
<button
|
||||||
|
@ -23,7 +23,7 @@ const IconButton = React.forwardRef(({
|
||||||
tabIndex={tabIndex}
|
tabIndex={tabIndex}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<RawIcon size={size} src={src} />
|
<RawIcon size={size} src={src} isImage={isImage} />
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
if (tooltip === null) return btn;
|
if (tooltip === null) return btn;
|
||||||
|
@ -46,6 +46,7 @@ IconButton.defaultProps = {
|
||||||
onClick: null,
|
onClick: null,
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
isImage: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
IconButton.propTypes = {
|
IconButton.propTypes = {
|
||||||
|
@ -58,6 +59,7 @@ IconButton.propTypes = {
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
tabIndex: PropTypes.number,
|
tabIndex: PropTypes.number,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
isImage: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default IconButton;
|
export default IconButton;
|
||||||
|
|
|
@ -2,24 +2,33 @@ import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './RawIcon.scss';
|
import './RawIcon.scss';
|
||||||
|
|
||||||
function RawIcon({ color, size, src }) {
|
function RawIcon({
|
||||||
const style = {
|
color, size, src, isImage,
|
||||||
WebkitMaskImage: `url(${src})`,
|
}) {
|
||||||
maskImage: `url(${src})`,
|
const style = {};
|
||||||
};
|
|
||||||
if (color !== null) style.backgroundColor = color;
|
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>;
|
return <span className={`ic-raw ic-raw-${size}`} style={style}> </span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawIcon.defaultProps = {
|
RawIcon.defaultProps = {
|
||||||
color: null,
|
color: null,
|
||||||
size: 'normal',
|
size: 'normal',
|
||||||
|
isImage: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
RawIcon.propTypes = {
|
RawIcon.propTypes = {
|
||||||
color: PropTypes.string,
|
color: PropTypes.string,
|
||||||
size: PropTypes.oneOf(['large', 'normal', 'small', 'extra-small']),
|
size: PropTypes.oneOf(['large', 'normal', 'small', 'extra-small']),
|
||||||
src: PropTypes.string.isRequired,
|
src: PropTypes.string.isRequired,
|
||||||
|
isImage: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RawIcon;
|
export default RawIcon;
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
-webkit-mask-size: cover;
|
-webkit-mask-size: cover;
|
||||||
mask-size: cover;
|
mask-size: cover;
|
||||||
background-color: var(--ic-surface-normal);
|
background-color: var(--ic-surface-normal);
|
||||||
|
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
.ic-raw-large {
|
.ic-raw-large {
|
||||||
@include icSize(var(--ic-large));
|
@include icSize(var(--ic-large));
|
||||||
|
|
Loading…
Reference in a new issue