aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/badge
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2021-10-15 15:25:41 +0530
committerLibravatar GitHub <noreply@github.com>2021-10-15 15:25:41 +0530
commit0ad7444fb1dc2cdb82830df4ef241d75a6bfd82d (patch)
tree5a994fb8e0620aa5d2542ddd9c8561ef9861a9b5 /src/components/ui/badge
parentchore: refresh lock file to fix vulnerabilities (#2075) (diff)
downloadferdium-app-0ad7444fb1dc2cdb82830df4ef241d75a6bfd82d.tar.gz
ferdium-app-0ad7444fb1dc2cdb82830df4ef241d75a6bfd82d.tar.zst
ferdium-app-0ad7444fb1dc2cdb82830df4ef241d75a6bfd82d.zip
chore: move 'packages/ui' into 'src' (no longer an injected package) (#2077)
Diffstat (limited to 'src/components/ui/badge')
-rw-r--r--src/components/ui/badge/ProBadge.tsx64
-rw-r--r--src/components/ui/badge/index.tsx71
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 @@
1import { mdiStar } from '@mdi/js';
2import classnames from 'classnames';
3import { Component } from 'react';
4import injectStyle from 'react-jss';
5
6import { Theme } from '@meetfranz/theme';
7import { Icon } from '../icon';
8import { Badge } from './index';
9import { IWithStyle } from '../typings/generic';
10
11interface IProps extends IWithStyle {
12 badgeClasses?: string;
13 iconClasses?: string;
14 inverted?: boolean;
15 className?: string;
16}
17
18const 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
36class 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
64export 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 @@
1import classnames from 'classnames';
2import { Component, ReactNode } from 'react';
3import injectStyle from 'react-jss';
4
5import { Theme } from '@meetfranz/theme';
6import { IWithStyle } from '../typings/generic';
7
8interface IProps extends IWithStyle {
9 type: string;
10 className?: string;
11 children: ReactNode;
12}
13
14const 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
29const 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
48class 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
71export const Badge = injectStyle(styles)(BadgeComponent);