Skip to content

Commit

Permalink
Add badge to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
GittavanderPol committed Aug 17, 2024
1 parent 53fbcb3 commit 0cd8de6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
36 changes: 36 additions & 0 deletions app/frontend/components/ui/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from "react";
import { type VariantProps, cva } from "class-variance-authority";

import { cn } from "@/utils/ui";

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-primary text-primary-foreground hover:bg-primary/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 React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

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

export { Badge, badgeVariants };
14 changes: 14 additions & 0 deletions app/frontend/pages/companies/show.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BriefcaseBusiness } from "lucide-react";

import ExternalLink from "@/components/external_link";
import { Badge } from "@/components/ui/badge";
import { Separator } from "@/components/ui/separator";

import type { Company } from "@/types/company";
Expand All @@ -23,6 +24,19 @@ function Show({ company }: Props) {
</ExternalLink>
)}
</div>
<div className="flex space-x-2">
{company.technologies.map((technology) => (
<Badge
key={technology.id}
style={{
backgroundColor: technology.backgroundColor,
color: technology.textColor,
}}
>
{technology.name}
</Badge>
))}
</div>
<Separator className="my-4" />
<p>{company.description}</p>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/types/company.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Technology } from "./technology";

export interface Company {
id: number;
name: string;
website?: string;
careersPage?: string;
description?: string;
technologies: Technology[];
}
6 changes: 6 additions & 0 deletions app/frontend/types/technology.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Technology {
id: number;
name: string;
backgroundColor?: string;
textColor?: string;
}
8 changes: 0 additions & 8 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def perform
destroy_data!
seed_technologies
seed_companies
seed_company_technologies
end

def destroy_data!
Expand Down Expand Up @@ -44,13 +43,6 @@ def seed_companies
end
end

def seed_company_technologies
CompanyTechnology.create!(company: @company_1, technology: @ruby)
CompanyTechnology.create!(company: @company_1, technology: @rails)
CompanyTechnology.create!(company: @company_2, technology: @ruby)
CompanyTechnology.create!(company: @company_2, technology: @rails)
end

private

def create_records(model, count, &block)
Expand Down

0 comments on commit 0cd8de6

Please sign in to comment.