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

100 lines
2.2 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`
display: ${props => (props.label.length > 0 || props.label != '0') ? 'inline-block' : 'none'};
border: 1px solid transparent;
border-radius: ${props => props.borderRadius};
width: fit-content;
padding: 1px;
line-height: 0.8;
cursor: pointer;
overflow: hidden;
:hover {
border-color: ${props => props.backgroundColor};
}
`;
const StyledInner = styled.div`
2019-07-03 13:23:53 +00:00
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;
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 => {
if (!props.onClick) return;
e.preventDefault();
e.stopPropagation();
props.onClick(e);
2019-07-31 18:04:34 +00:00
};
const {
fontSize,
color,
fontWeight,
backgroundColor,
borderRadius,
padding,
maxWidth
} = props;
return (
<StyledBadge
{...props}
onClick={onClick}
>
<StyledInner
backgroundColor={backgroundColor}
borderRadius={borderRadius}
padding={padding}
maxWidth={maxWidth}
>
<Text
fontWeight={fontWeight}
color={color}
fontSize={fontSize}>
{props.label}
</Text>
</StyledInner>
</StyledBadge>
);
2019-07-03 13:23:53 +00:00
};
Badge.propTypes = {
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2019-07-03 13:23:53 +00:00
backgroundColor: PropTypes.string,
color: PropTypes.string,
fontSize: PropTypes.string,
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 = {
label: 0,
2019-07-03 13:23:53 +00:00
backgroundColor: '#ED7309',
color: '#FFFFFF',
fontSize: "11px",
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;