diff options
Diffstat (limited to 'src/components/ui/badge')
-rw-r--r-- | src/components/ui/badge/ProBadge.tsx | 64 | ||||
-rw-r--r-- | src/components/ui/badge/index.tsx | 71 |
2 files changed, 135 insertions, 0 deletions
diff --git a/src/components/ui/badge/ProBadge.tsx b/src/components/ui/badge/ProBadge.tsx new file mode 100644 index 000000000..cb6bc4c98 --- /dev/null +++ b/src/components/ui/badge/ProBadge.tsx | |||
@@ -0,0 +1,64 @@ | |||
1 | import { mdiStar } from '@mdi/js'; | ||
2 | import classnames from 'classnames'; | ||
3 | import { Component } from 'react'; | ||
4 | import injectStyle from 'react-jss'; | ||
5 | |||
6 | import { Theme } from '@meetfranz/theme'; | ||
7 | import { Icon } from '../icon'; | ||
8 | import { Badge } from './index'; | ||
9 | import { IWithStyle } from '../typings/generic'; | ||
10 | |||
11 | interface IProps extends IWithStyle { | ||
12 | badgeClasses?: string; | ||
13 | iconClasses?: string; | ||
14 | inverted?: boolean; | ||
15 | className?: string; | ||
16 | } | ||
17 | |||
18 | const styles = (theme: Theme) => ({ | ||
19 | badge: { | ||
20 | height: 'auto', | ||
21 | padding: [4, 6, 2, 7], | ||
22 | borderRadius: theme.borderRadiusSmall, | ||
23 | }, | ||
24 | invertedBadge: { | ||
25 | background: theme.styleTypes.primary.contrast, | ||
26 | color: theme.styleTypes.primary.accent, | ||
27 | }, | ||
28 | icon: { | ||
29 | fill: theme.styleTypes.primary.contrast, | ||
30 | }, | ||
31 | invertedIcon: { | ||
32 | fill: theme.styleTypes.primary.accent, | ||
33 | }, | ||
34 | }); | ||
35 | |||
36 | class ProBadgeComponent extends Component<IProps> { | ||
37 | render() { | ||
38 | const { classes, badgeClasses, iconClasses, inverted, className } = | ||
39 | this.props; | ||
40 | |||
41 | return ( | ||
42 | <Badge | ||
43 | type="primary" | ||
44 | className={classnames([ | ||
45 | classes.badge, | ||
46 | inverted && classes.invertedBadge, | ||
47 | badgeClasses, | ||
48 | className, | ||
49 | ])} | ||
50 | > | ||
51 | <Icon | ||
52 | icon={mdiStar} | ||
53 | className={classnames([ | ||
54 | classes.icon, | ||
55 | inverted && classes.invertedIcon, | ||
56 | iconClasses, | ||
57 | ])} | ||
58 | /> | ||
59 | </Badge> | ||
60 | ); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | export const ProBadge = injectStyle(styles)(ProBadgeComponent); | ||
diff --git a/src/components/ui/badge/index.tsx b/src/components/ui/badge/index.tsx new file mode 100644 index 000000000..6495036ff --- /dev/null +++ b/src/components/ui/badge/index.tsx | |||
@@ -0,0 +1,71 @@ | |||
1 | import classnames from 'classnames'; | ||
2 | import { Component, ReactNode } from 'react'; | ||
3 | import injectStyle from 'react-jss'; | ||
4 | |||
5 | import { Theme } from '@meetfranz/theme'; | ||
6 | import { IWithStyle } from '../typings/generic'; | ||
7 | |||
8 | interface IProps extends IWithStyle { | ||
9 | type: string; | ||
10 | className?: string; | ||
11 | children: ReactNode; | ||
12 | } | ||
13 | |||
14 | const badgeStyles = (theme: Theme) => { | ||
15 | const styles = {}; | ||
16 | Object.keys(theme.styleTypes).map(style => { | ||
17 | Object.assign(styles, { | ||
18 | [style]: { | ||
19 | background: theme.styleTypes[style].accent, | ||
20 | color: theme.styleTypes[style].contrast, | ||
21 | border: theme.styleTypes[style].border, | ||
22 | }, | ||
23 | }); | ||
24 | }); | ||
25 | |||
26 | return styles; | ||
27 | }; | ||
28 | |||
29 | const styles = (theme: Theme) => ({ | ||
30 | badge: { | ||
31 | display: 'inline-block', | ||
32 | padding: [3, 8, 4], | ||
33 | fontSize: theme.badgeFontSize, | ||
34 | borderRadius: theme.badgeBorderRadius, | ||
35 | margin: [0, 4], | ||
36 | |||
37 | '&:first-child': { | ||
38 | marginLeft: 0, | ||
39 | }, | ||
40 | |||
41 | '&:last-child': { | ||
42 | marginRight: 0, | ||
43 | }, | ||
44 | }, | ||
45 | ...badgeStyles(theme), | ||
46 | }); | ||
47 | |||
48 | class BadgeComponent extends Component<IProps> { | ||
49 | public static defaultProps = { | ||
50 | type: 'primary', | ||
51 | }; | ||
52 | |||
53 | render() { | ||
54 | const { classes, children, type, className } = this.props; | ||
55 | |||
56 | return ( | ||
57 | <div | ||
58 | className={classnames({ | ||
59 | [classes.badge]: true, | ||
60 | [classes[type]]: true, | ||
61 | [`${className}`]: className, | ||
62 | })} | ||
63 | data-type="franz-badge" | ||
64 | > | ||
65 | {children} | ||
66 | </div> | ||
67 | ); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | export const Badge = injectStyle(styles)(BadgeComponent); | ||