2020-10-16 13:16:01 +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`
|
2020-10-16 13:16:01 +00:00
|
|
|
display: ${(props) =>
|
|
|
|
props.label.length > 0 || props.label != "0" ? "inline-block" : "none"};
|
2020-01-13 12:34:45 +00:00
|
|
|
border: 1px solid transparent;
|
2020-10-16 13:16:01 +00:00
|
|
|
border-radius: ${(props) => props.borderRadius};
|
2020-01-13 12:34:45 +00:00
|
|
|
width: fit-content;
|
2020-08-14 14:05:47 +00:00
|
|
|
padding: 1px;
|
2020-01-13 12:34:45 +00:00
|
|
|
line-height: 0.8;
|
|
|
|
cursor: pointer;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
:hover {
|
2020-10-16 13:16:01 +00:00
|
|
|
border-color: ${(props) => props.backgroundColor};
|
2020-01-13 12:34:45 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledInner = styled.div`
|
2020-10-16 13:16:01 +00:00
|
|
|
background-color: ${(props) => props.backgroundColor};
|
|
|
|
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;
|
2019-12-05 11:14:04 +00:00
|
|
|
line-height: 1.5;
|
2019-07-03 13:23:53 +00:00
|
|
|
`;
|
|
|
|
|
2020-10-16 13:16:01 +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
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
const onClick = (e) => {
|
2020-01-14 11:55:43 +00:00
|
|
|
if (!props.onClick) return;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
props.onClick(e);
|
2019-07-31 18:04:34 +00:00
|
|
|
};
|
2020-01-13 12:34:45 +00:00
|
|
|
|
2020-01-14 11:55:43 +00:00
|
|
|
const {
|
|
|
|
fontSize,
|
|
|
|
color,
|
|
|
|
fontWeight,
|
|
|
|
backgroundColor,
|
|
|
|
borderRadius,
|
|
|
|
padding,
|
2020-10-16 13:16:01 +00:00
|
|
|
maxWidth,
|
2020-01-14 11:55:43 +00:00
|
|
|
} = props;
|
|
|
|
|
2019-12-05 11:14:04 +00:00
|
|
|
return (
|
2020-10-16 13:16:01 +00:00
|
|
|
<StyledBadge {...props} onClick={onClick}>
|
2020-01-14 11:55:43 +00:00
|
|
|
<StyledInner
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
borderRadius={borderRadius}
|
|
|
|
padding={padding}
|
|
|
|
maxWidth={maxWidth}
|
|
|
|
>
|
2020-10-16 13:16:01 +00:00
|
|
|
<Text fontWeight={fontWeight} color={color} fontSize={fontSize}>
|
2020-01-13 12:34:45 +00:00
|
|
|
{props.label}
|
|
|
|
</Text>
|
|
|
|
</StyledInner>
|
2019-12-05 11:14:04 +00:00
|
|
|
</StyledBadge>
|
|
|
|
);
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.propTypes = {
|
2020-01-13 12:34:45 +00:00
|
|
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2019-07-03 13:23:53 +00:00
|
|
|
backgroundColor: PropTypes.string,
|
|
|
|
color: PropTypes.string,
|
2019-12-10 06:16:26 +00:00
|
|
|
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,
|
2019-11-26 09:09:39 +00:00
|
|
|
onClick: PropTypes.func,
|
|
|
|
className: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.defaultProps = {
|
2020-01-13 12:34:45 +00:00
|
|
|
label: 0,
|
2020-10-16 13:16:01 +00:00
|
|
|
backgroundColor: "#ED7309",
|
|
|
|
color: "#FFFFFF",
|
2019-12-10 06:16:26 +00:00
|
|
|
fontSize: "11px",
|
2019-07-03 13:36:23 +00:00
|
|
|
fontWeight: 800,
|
2020-10-16 13:16:01 +00:00
|
|
|
borderRadius: "11px",
|
|
|
|
padding: "0 5px",
|
|
|
|
maxWidth: "50px",
|
|
|
|
};
|
2019-07-03 13:23:53 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
export default Badge;
|