2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2020-01-13 12:34:45 +00:00
|
|
|
|
2022-01-24 14:32:34 +00:00
|
|
|
import { StyledBadge, StyledInner, StyledText } from "./styled-badge";
|
2019-07-03 13:23:53 +00:00
|
|
|
|
2022-08-12 15:07:44 +00:00
|
|
|
import { ColorTheme, ThemeType } from "@docspace/common/components/ColorTheme";
|
2022-07-24 18:11:11 +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();
|
|
|
|
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,
|
2021-12-20 12:14:32 +00:00
|
|
|
lineHeight,
|
2022-01-24 11:48:38 +00:00
|
|
|
isHovered,
|
|
|
|
label,
|
2020-01-14 11:55:43 +00:00
|
|
|
} = props;
|
|
|
|
|
2019-12-05 11:14:04 +00:00
|
|
|
return (
|
2022-07-24 18:11:11 +00:00
|
|
|
<ColorTheme
|
|
|
|
{...props}
|
|
|
|
isHovered={isHovered}
|
|
|
|
onClick={onClick}
|
2022-08-31 12:38:39 +00:00
|
|
|
themeId={ThemeType.Badge}
|
2022-07-24 18:11:11 +00:00
|
|
|
>
|
2020-01-14 11:55:43 +00:00
|
|
|
<StyledInner
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
borderRadius={borderRadius}
|
|
|
|
padding={padding}
|
|
|
|
maxWidth={maxWidth}
|
2021-12-20 12:14:32 +00:00
|
|
|
lineHeight={lineHeight}
|
2020-01-14 11:55:43 +00:00
|
|
|
>
|
2022-01-24 14:32:34 +00:00
|
|
|
<StyledText
|
2021-12-20 12:14:32 +00:00
|
|
|
textAlign="center"
|
|
|
|
fontWeight={fontWeight}
|
|
|
|
color={color}
|
|
|
|
fontSize={fontSize}
|
|
|
|
>
|
2022-01-24 11:48:38 +00:00
|
|
|
{label}
|
2022-01-24 14:32:34 +00:00
|
|
|
</StyledText>
|
2020-01-13 12:34:45 +00:00
|
|
|
</StyledInner>
|
2022-07-24 18:11:11 +00:00
|
|
|
</ColorTheme>
|
2019-12-05 11:14:04 +00:00
|
|
|
);
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.propTypes = {
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Value */
|
2020-01-13 12:34:45 +00:00
|
|
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS background-color */
|
2019-07-03 13:23:53 +00:00
|
|
|
backgroundColor: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS color */
|
2019-07-03 13:23:53 +00:00
|
|
|
color: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS font-size */
|
2019-12-10 06:16:26 +00:00
|
|
|
fontSize: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS font-weight */
|
2019-07-03 13:23:53 +00:00
|
|
|
fontWeight: PropTypes.number,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS border-radius */
|
2019-07-03 13:36:23 +00:00
|
|
|
borderRadius: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS padding */
|
2019-07-03 13:36:23 +00:00
|
|
|
padding: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** CSS max-width */
|
2019-07-03 13:36:23 +00:00
|
|
|
maxWidth: PropTypes.string,
|
2021-12-20 12:14:32 +00:00
|
|
|
/** CSS line-height */
|
|
|
|
lineHeight: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** onClick event */
|
2019-11-26 09:09:39 +00:00
|
|
|
onClick: PropTypes.func,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Accepts class */
|
2019-11-26 09:09:39 +00:00
|
|
|
className: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Accepts id */
|
2019-11-26 09:09:39 +00:00
|
|
|
id: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Accepts css style */
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2022-01-24 11:48:38 +00:00
|
|
|
/** Set hovered state and effects of link */
|
|
|
|
isHovered: PropTypes.bool,
|
|
|
|
/** Disabled hover styles */
|
|
|
|
noHover: PropTypes.bool,
|
2019-07-03 13:23:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Badge.defaultProps = {
|
2020-01-13 12:34:45 +00:00
|
|
|
label: 0,
|
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",
|
2021-12-29 15:30:05 +00:00
|
|
|
lineHeight: "1.78",
|
2022-01-24 11:48:38 +00:00
|
|
|
isHovered: false,
|
|
|
|
noHover: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
};
|
2019-07-03 13:23:53 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
export default Badge;
|