2019-07-03 13:23:53 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import styled from 'styled-components';
|
2019-12-05 11:14:04 +00:00
|
|
|
import Text from "../text";
|
2019-07-03 13:23:53 +00:00
|
|
|
|
|
|
|
const StyledBadge = styled.div`
|
|
|
|
background-color: ${props => props.backgroundColor};
|
2019-07-03 13:36:23 +00:00
|
|
|
border-radius: ${props => props.borderRadius};
|
|
|
|
padding: ${props => props.padding};
|
|
|
|
max-width: ${props => props.maxWidth};
|
2019-07-03 13:23:53 +00:00
|
|
|
text-align: center;
|
|
|
|
cursor: pointer;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2019-07-31 18:04:34 +00:00
|
|
|
display: ${props => props.number > 0 ? 'inline-block' : 'none'};
|
2019-07-04 15:56:12 +00:00
|
|
|
user-select: none;
|
2019-12-05 11:14:04 +00:00
|
|
|
line-height: 1.5;
|
2019-07-03 13:23:53 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Badge = props => {
|
2019-07-24 17:39:19 +00:00
|
|
|
//console.log("Badge render");
|
2019-07-31 18:04:34 +00:00
|
|
|
|
|
|
|
const onClick = e => {
|
2019-07-05 12:14:18 +00:00
|
|
|
if (props.onClick) {
|
|
|
|
e.stopPropagation();
|
|
|
|
props.onClick(e);
|
|
|
|
}
|
2019-07-31 18:04:34 +00:00
|
|
|
};
|
2019-12-05 11:14:04 +00:00
|
|
|
|
|
|
|
const { fontSize, color, fontWeight } = props;
|
|
|
|
return (
|
|
|
|
<StyledBadge {...props} onClick={onClick}>
|
|
|
|
<Text fontWeight={fontWeight} color={color} fontSize={fontSize}>
|
|
|
|
{props.number}
|
|
|
|
</Text>
|
|
|
|
</StyledBadge>
|
|
|
|
);
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.propTypes = {
|
|
|
|
number: PropTypes.number,
|
|
|
|
backgroundColor: PropTypes.string,
|
|
|
|
color: PropTypes.string,
|
2019-12-05 11:14:04 +00:00
|
|
|
fontSize: PropTypes.number,
|
2019-07-03 13:23:53 +00:00
|
|
|
fontWeight: PropTypes.number,
|
2019-07-03 13:36:23 +00:00
|
|
|
borderRadius: PropTypes.string,
|
|
|
|
padding: PropTypes.string,
|
|
|
|
maxWidth: PropTypes.string,
|
2019-11-26 09:09:39 +00:00
|
|
|
onClick: PropTypes.func,
|
|
|
|
className: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.defaultProps = {
|
|
|
|
number: 0,
|
|
|
|
backgroundColor: '#ED7309',
|
|
|
|
color: '#FFFFFF',
|
2019-12-05 11:14:04 +00:00
|
|
|
fontSize: 11,
|
2019-07-03 13:36:23 +00:00
|
|
|
fontWeight: 800,
|
|
|
|
borderRadius: '11px',
|
|
|
|
padding: '0 5px',
|
|
|
|
maxWidth: '50px'
|
2019-07-03 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Badge;
|