Skip to content

Commit 94de826

Browse files
committed
Added badge component
1 parent dfe5f30 commit 94de826

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/components/MdxComponents.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { QuickLink, QuickLinks } from './mdx/QuickLinks';
1111
import { Tab, Tabs } from './mdx/Tabs';
1212
import { PreCodeBlock } from './PreCodeBlock';
1313
import ResourceEstimator from './resource-estimator/ResourceEstimator';
14+
import { Badge } from './ui/badge';
1415

1516
const MdxComponents = (version?: string) => {
1617
return {
@@ -62,7 +63,8 @@ const MdxComponents = (version?: string) => {
6263
<div {...props} className="table-auto w-full overflow-x-auto">
6364
<table>{props.children}</table>
6465
</div>
65-
)
66+
),
67+
Badge
6668
};
6769
};
6870

src/components/ui/badge.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as React from "react";
2+
import { cva, type VariantProps } from "class-variance-authority";
3+
4+
import { cn } from "@/lib/utils";
5+
6+
const badgeVariants = cva(
7+
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
8+
{
9+
variants: {
10+
variant: {
11+
default:
12+
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
13+
secondary:
14+
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
15+
destructive:
16+
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
17+
outline: "text-foreground",
18+
},
19+
},
20+
defaultVariants: {
21+
variant: "default",
22+
},
23+
}
24+
);
25+
26+
export interface BadgeProps
27+
extends React.HTMLAttributes<HTMLDivElement>,
28+
VariantProps<typeof badgeVariants> {
29+
backgroundColor?: string;
30+
textColor?: string;
31+
textSize?: "text-xs" | "text-sm" | "text-base" | "text-lg" | "text-xl" | "text-2xl";
32+
}
33+
34+
function Badge({
35+
className,
36+
variant,
37+
backgroundColor,
38+
textColor,
39+
textSize = "text-xs",
40+
...props
41+
}: BadgeProps) {
42+
return (
43+
<div
44+
className={cn(
45+
badgeVariants({ variant }),
46+
className,
47+
backgroundColor,
48+
textColor,
49+
textSize
50+
)}
51+
style={{
52+
backgroundColor: backgroundColor,
53+
color: textColor,
54+
}}
55+
{...props}
56+
/>
57+
);
58+
}
59+
60+
export { Badge, badgeVariants };

0 commit comments

Comments
 (0)