DocSpace-client/web/ASC.Web.Components/src/components/badge/index.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-07-03 13:23:53 +00:00
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components';
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;
line-height: 1.5;
2019-07-03 13:23:53 +00:00
`;
const Badge = props => {
//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
};
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,
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,
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',
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;