1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
import classnames from 'classnames';
import { Component, ReactNode } from 'react';
import injectStyle, { WithStylesProps } from 'react-jss';
import { Theme } from '../../../themes';
const badgeStyles = (theme: Theme) => {
const styles = {};
Object.keys(theme.styleTypes).map(style =>
Object.assign(styles, {
[style]: {
background: theme.styleTypes[style].accent,
color: theme.styleTypes[style].contrast,
border: theme.styleTypes[style].border,
},
}),
);
return styles;
};
const styles = (theme: Theme) => ({
badge: {
display: 'inline-block',
padding: [3, 8, 4],
fontSize: theme.badgeFontSize,
borderRadius: theme.badgeBorderRadius,
margin: [0, 4],
'&:first-child': {
marginLeft: 0,
},
'&:last-child': {
marginRight: 0,
},
},
...badgeStyles(theme),
});
interface IProps extends WithStylesProps<typeof styles> {
type: string;
className?: string;
children: ReactNode;
}
class BadgeComponent extends Component<IProps> {
public static defaultProps = {
type: 'primary',
};
render() {
const { classes, children, type, className } = this.props;
return (
<div
className={classnames({
[classes.badge]: true,
[classes[type]]: true,
[`${className}`]: className,
})}
data-type="franz-badge"
>
{children}
</div>
);
}
}
export default injectStyle(styles, { injectTheme: true })(BadgeComponent);
|