Skip to content

Commit

Permalink
🐬 Add badge component (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
nezouse authored Mar 1, 2024
1 parent 69d34a2 commit ad55d1a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/images/categoryIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion app/waves/[waveId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { notFound } from "next/navigation";
import { getWaveWithApplications } from "@/drizzle/queries/waves";

import { formatDate } from "@/lib/dates";
import { CategoryBadge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardTitle } from "@/components/ui/card";
import {
Expand Down Expand Up @@ -72,7 +73,9 @@ export default async function Wave({ params }: { params: { waveId: string } }) {
<TableCell>Entity name</TableCell>
<TableCell>{formatDate(project.createdAt)}</TableCell>
<TableCell>1,025,000.00 WLD</TableCell>
<TableCell>Category</TableCell>
<TableCell>
<CategoryBadge>Category</CategoryBadge>
</TableCell>
</TableLinkRow>
))}
</TableBody>
Expand Down
47 changes: 47 additions & 0 deletions components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { type HTMLAttributes } from "react";
import Image from "next/image";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/cn";
import categoryIcon from "@/app/images/categoryIcon.svg";

const badgeVariants = cva(
"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",
{
variants: {
variant: {
default:
"border-transparent bg-green-300 text-primary hover:bg-green-300/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
},
);

export interface BadgeProps
extends HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
);
}

function CategoryBadge({ children, ...props }: BadgeProps) {
return (
<Badge {...props}>
<Image src={categoryIcon} alt="" className="mr-2" />
{children}
</Badge>
);
}

export { Badge, CategoryBadge, badgeVariants };

0 comments on commit ad55d1a

Please sign in to comment.