Skip to content

Commit 0c92cae

Browse files
committed
refactor(BadgeGroup): use badge component
1 parent 81c5e15 commit 0c92cae

5 files changed

Lines changed: 87 additions & 26 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@reference "../../styles/index.css";
2+
3+
.badge {
4+
@apply rounded-full
5+
border
6+
px-2.5
7+
py-0.5
8+
text-center
9+
text-white;
10+
11+
&.default {
12+
@apply border-green-200
13+
bg-green-600
14+
dark:border-green-600;
15+
}
16+
17+
&.error {
18+
@apply border-danger-200
19+
bg-danger-600
20+
dark:border-danger-600;
21+
}
22+
23+
&.warning {
24+
@apply border-warning-200
25+
bg-warning-600
26+
dark:border-warning-600;
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2+
3+
import Badge from '@node-core/ui-components/Common/Badge';
4+
5+
type Story = StoryObj<typeof Badge>;
6+
type Meta = MetaObj<typeof Badge>;
7+
8+
export const Default: Story = {
9+
args: {
10+
kind: 'default',
11+
},
12+
};
13+
14+
export const Error: Story = {
15+
args: {
16+
kind: 'error',
17+
},
18+
};
19+
20+
export const Warning: Story = {
21+
args: {
22+
kind: 'warning',
23+
},
24+
};
25+
26+
export default { component: Badge, args: { children: 'Badge' } } as Meta;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import classNames from 'classnames';
2+
import type { FC, HTMLAttributes, PropsWithChildren } from 'react';
3+
4+
import styles from './index.module.css';
5+
6+
type BadgeProps = HTMLAttributes<HTMLSpanElement> & {
7+
kind?: 'default' | 'warning' | 'error';
8+
};
9+
10+
const Badge: FC<PropsWithChildren<BadgeProps>> = ({
11+
kind = 'default',
12+
className,
13+
children,
14+
...props
15+
}) => {
16+
return (
17+
<span
18+
className={classNames(styles.badge, styles[kind], className)}
19+
{...props}
20+
>
21+
{children}
22+
</span>
23+
);
24+
};
25+
26+
export default Badge;

packages/ui-components/Common/BadgeGroup/index.module.css

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@
1717
}
1818

1919
.badge {
20-
@apply mr-2
21-
rounded-full
22-
border
23-
px-2.5
24-
py-0.5
25-
text-center
26-
text-white;
20+
@apply mr-2;
2721
}
2822

2923
.message {
@@ -41,12 +35,6 @@
4135
dark:text-green-300;
4236
}
4337

44-
.badge {
45-
@apply border-green-200
46-
bg-green-600
47-
dark:border-green-600;
48-
}
49-
5038
.message {
5139
@apply text-green-700
5240
dark:text-green-300;
@@ -64,12 +52,6 @@
6452
dark:text-danger-300;
6553
}
6654

67-
.badge {
68-
@apply border-danger-200
69-
bg-danger-600
70-
dark:border-danger-600;
71-
}
72-
7355
.message {
7456
@apply text-danger-700
7557
dark:text-danger-300;
@@ -87,12 +69,6 @@
8769
dark:text-warning-300;
8870
}
8971

90-
.badge {
91-
@apply border-warning-200
92-
bg-warning-600
93-
dark:border-warning-600;
94-
}
95-
9672
.message {
9773
@apply text-warning-700
9874
dark:text-warning-300;

packages/ui-components/Common/BadgeGroup/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ArrowRightIcon from '@heroicons/react/24/solid/ArrowRightIcon';
22
import type { ComponentProps, FC, PropsWithChildren } from 'react';
33

4+
import Badge from '@node-core/ui-components/Common/Badge';
45
import type { LinkLike } from '@node-core/ui-components/types';
56

67
import styles from './index.module.css';
@@ -19,7 +20,11 @@ const BadgeGroup: FC<PropsWithChildren<BadgeGroupProps>> = ({
1920
...args
2021
}) => (
2122
<Component className={`${styles.wrapper} ${styles[kind]}`} {...args}>
22-
{badgeText && <span className={styles.badge}>{badgeText}</span>}
23+
{badgeText && (
24+
<Badge kind={kind} className={styles.badge}>
25+
{badgeText}
26+
</Badge>
27+
)}
2328
<span className={styles.message}>{children}</span>
2429
{args.href && <ArrowRightIcon className={styles.icon} />}
2530
</Component>

0 commit comments

Comments
 (0)