badge colour variants
This commit is contained in:
@@ -49,6 +49,18 @@
|
|||||||
--approach-correct-bg: #f0fdf4;
|
--approach-correct-bg: #f0fdf4;
|
||||||
--approach-correct-border: #bbf7d0;
|
--approach-correct-border: #bbf7d0;
|
||||||
--approach-correct-fg: #16a34a;
|
--approach-correct-fg: #16a34a;
|
||||||
|
|
||||||
|
/* Badge colors - Category (teal) */
|
||||||
|
--badge-category: #0d9488;
|
||||||
|
--badge-category-bg: #ccfbf1;
|
||||||
|
|
||||||
|
/* Badge colors - Pattern (indigo) */
|
||||||
|
--badge-pattern: #4f46e5;
|
||||||
|
--badge-pattern-bg: #e0e7ff;
|
||||||
|
|
||||||
|
/* Badge colors - Optimal (green) */
|
||||||
|
--badge-optimal: #16a34a;
|
||||||
|
--badge-optimal-bg: #dcfce7;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
@@ -101,6 +113,18 @@
|
|||||||
--approach-correct-bg: rgba(22, 163, 74, 0.15);
|
--approach-correct-bg: rgba(22, 163, 74, 0.15);
|
||||||
--approach-correct-border: rgba(22, 163, 74, 0.4);
|
--approach-correct-border: rgba(22, 163, 74, 0.4);
|
||||||
--approach-correct-fg: #4ade80;
|
--approach-correct-fg: #4ade80;
|
||||||
|
|
||||||
|
/* Badge colors - Category (teal, dark mode) */
|
||||||
|
--badge-category: #2dd4bf;
|
||||||
|
--badge-category-bg: rgba(20, 184, 166, 0.2);
|
||||||
|
|
||||||
|
/* Badge colors - Pattern (indigo, dark mode) */
|
||||||
|
--badge-pattern: #a5b4fc;
|
||||||
|
--badge-pattern-bg: rgba(99, 102, 241, 0.2);
|
||||||
|
|
||||||
|
/* Badge colors - Optimal (green, dark mode) */
|
||||||
|
--badge-optimal: #4ade80;
|
||||||
|
--badge-optimal-bg: rgba(34, 197, 94, 0.2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { CodeBlock } from "@/components/ui/code-block";
|
|||||||
import { Markdown } from "@/components/ui/markdown";
|
import { Markdown } from "@/components/ui/markdown";
|
||||||
import { Callout, ApproachBox } from "@/components/ui/callout";
|
import { Callout, ApproachBox } from "@/components/ui/callout";
|
||||||
import { Collapsible } from "@/components/ui/collapsible";
|
import { Collapsible } from "@/components/ui/collapsible";
|
||||||
import { getDifficultyColor, getDifficultyLabel, capitalize } from "@/lib/utils";
|
import { getDifficultyVariant, getDifficultyLabel, capitalize } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
FileText,
|
FileText,
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
@@ -40,7 +40,7 @@ export default async function QuestionDetailPage({
|
|||||||
<div className="flex items-start justify-between gap-4 mb-4">
|
<div className="flex items-start justify-between gap-4 mb-4">
|
||||||
<h1 className="text-3xl font-bold">{question.title}</h1>
|
<h1 className="text-3xl font-bold">{question.title}</h1>
|
||||||
<Badge
|
<Badge
|
||||||
className={getDifficultyColor(question.difficulty)}
|
variant={getDifficultyVariant(question.difficulty)}
|
||||||
aria-label={getDifficultyLabel(question.difficulty)}
|
aria-label={getDifficultyLabel(question.difficulty)}
|
||||||
>
|
>
|
||||||
{capitalize(question.difficulty)}
|
{capitalize(question.difficulty)}
|
||||||
@@ -50,12 +50,12 @@ export default async function QuestionDetailPage({
|
|||||||
<div className="flex flex-wrap gap-2 mb-4">
|
<div className="flex flex-wrap gap-2 mb-4">
|
||||||
{question.categories.map((cat) => (
|
{question.categories.map((cat) => (
|
||||||
<Link key={cat.id} href={`/questions?category=${cat.slug}`}>
|
<Link key={cat.id} href={`/questions?category=${cat.slug}`}>
|
||||||
<Badge variant="outline">{cat.name}</Badge>
|
<Badge variant="category">{cat.name}</Badge>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
{question.patterns.map((pat) => (
|
{question.patterns.map((pat) => (
|
||||||
<Link key={pat.id} href={`/patterns/${pat.slug}`}>
|
<Link key={pat.id} href={`/patterns/${pat.slug}`}>
|
||||||
<Badge>{pat.name}</Badge>
|
<Badge variant="pattern">{pat.name}</Badge>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -239,9 +239,7 @@ export default async function QuestionDetailPage({
|
|||||||
<div key={solution.id}>
|
<div key={solution.id}>
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<h4 className="font-medium">{solution.approach_name}</h4>
|
<h4 className="font-medium">{solution.approach_name}</h4>
|
||||||
<Badge className="bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400">
|
<Badge variant="optimal">Optimal</Badge>
|
||||||
Optimal
|
|
||||||
</Badge>
|
|
||||||
</div>
|
</div>
|
||||||
{solution.explanation && (
|
{solution.explanation && (
|
||||||
<div className="text-sm text-[var(--muted-foreground)] mb-3 prose-content">
|
<div className="text-sm text-[var(--muted-foreground)] mb-3 prose-content">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { getDifficultyColor, capitalize } from "@/lib/utils";
|
import { getDifficultyVariant, getDifficultyLabel, capitalize } from "@/lib/utils";
|
||||||
import type { QuestionListItem } from "@/types";
|
import type { QuestionListItem } from "@/types";
|
||||||
|
|
||||||
interface QuestionCardProps {
|
interface QuestionCardProps {
|
||||||
@@ -15,25 +15,32 @@ export function QuestionCard({ question }: QuestionCardProps) {
|
|||||||
>
|
>
|
||||||
<div className="flex items-start justify-between gap-4 mb-3">
|
<div className="flex items-start justify-between gap-4 mb-3">
|
||||||
<h3 className="font-semibold">{question.title}</h3>
|
<h3 className="font-semibold">{question.title}</h3>
|
||||||
<Badge className={getDifficultyColor(question.difficulty)}>
|
<Badge
|
||||||
|
variant={getDifficultyVariant(question.difficulty)}
|
||||||
|
aria-label={getDifficultyLabel(question.difficulty)}
|
||||||
|
>
|
||||||
{capitalize(question.difficulty)}
|
{capitalize(question.difficulty)}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-wrap gap-2 mb-3">
|
<div className="flex flex-wrap gap-2 mb-3">
|
||||||
{question.categories.map((cat) => (
|
{question.categories.map((cat) => (
|
||||||
<Badge key={cat.id} variant="outline">
|
<Badge key={cat.id} variant="category">
|
||||||
{cat.name}
|
{cat.name}
|
||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-4 text-sm text-[var(--muted-foreground)]">
|
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||||
|
{question.patterns.map((p) => (
|
||||||
|
<Badge key={p.id} variant="pattern">
|
||||||
|
{p.name}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
{question.leetcode_id && (
|
{question.leetcode_id && (
|
||||||
<span>LeetCode #{question.leetcode_id}</span>
|
<span className="text-[var(--muted-foreground)]">
|
||||||
)}
|
LeetCode #{question.leetcode_id}
|
||||||
{question.patterns.length > 0 && (
|
</span>
|
||||||
<span>{question.patterns.map((p) => p.name).join(", ")}</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,26 +1,50 @@
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
type BadgeVariant =
|
||||||
|
| "default"
|
||||||
|
| "outline"
|
||||||
|
| "difficulty-easy"
|
||||||
|
| "difficulty-medium"
|
||||||
|
| "difficulty-hard"
|
||||||
|
| "category"
|
||||||
|
| "pattern"
|
||||||
|
| "optimal";
|
||||||
|
|
||||||
interface BadgeProps {
|
interface BadgeProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
variant?: "default" | "outline";
|
variant?: BadgeVariant;
|
||||||
|
"aria-label"?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const variantClasses: Record<BadgeVariant, string> = {
|
||||||
|
default: "bg-[var(--secondary)] text-[var(--secondary-foreground)]",
|
||||||
|
outline: "border border-[var(--border)] text-[var(--muted-foreground)]",
|
||||||
|
"difficulty-easy":
|
||||||
|
"text-[var(--difficulty-easy)] bg-[var(--difficulty-easy-bg)]",
|
||||||
|
"difficulty-medium":
|
||||||
|
"text-[var(--difficulty-medium)] bg-[var(--difficulty-medium-bg)]",
|
||||||
|
"difficulty-hard":
|
||||||
|
"text-[var(--difficulty-hard)] bg-[var(--difficulty-hard-bg)]",
|
||||||
|
category: "text-[var(--badge-category)] bg-[var(--badge-category-bg)]",
|
||||||
|
pattern: "text-[var(--badge-pattern)] bg-[var(--badge-pattern-bg)]",
|
||||||
|
optimal: "text-[var(--badge-optimal)] bg-[var(--badge-optimal-bg)]",
|
||||||
|
};
|
||||||
|
|
||||||
export function Badge({
|
export function Badge({
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
variant = "default",
|
variant = "default",
|
||||||
|
"aria-label": ariaLabel,
|
||||||
}: BadgeProps) {
|
}: BadgeProps) {
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",
|
"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",
|
||||||
variant === "default" &&
|
variantClasses[variant],
|
||||||
"bg-[var(--secondary)] text-[var(--secondary-foreground)]",
|
|
||||||
variant === "outline" &&
|
|
||||||
"border border-[var(--border)] text-[var(--muted-foreground)]",
|
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
aria-label={ariaLabel}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { cn, getDifficultyColor, getDifficultyLabel, capitalize } from "./utils";
|
import { cn, getDifficultyVariant, getDifficultyLabel, capitalize } from "./utils";
|
||||||
|
|
||||||
describe("cn", () => {
|
describe("cn", () => {
|
||||||
it("joins multiple class names", () => {
|
it("joins multiple class names", () => {
|
||||||
@@ -15,20 +15,17 @@ describe("cn", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getDifficultyColor", () => {
|
describe("getDifficultyVariant", () => {
|
||||||
it("returns easy difficulty CSS variable classes", () => {
|
it("returns difficulty-easy variant for easy", () => {
|
||||||
const result = getDifficultyColor("easy");
|
expect(getDifficultyVariant("easy")).toBe("difficulty-easy");
|
||||||
expect(result).toContain("--difficulty-easy");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns medium difficulty CSS variable classes", () => {
|
it("returns difficulty-medium variant for medium", () => {
|
||||||
const result = getDifficultyColor("medium");
|
expect(getDifficultyVariant("medium")).toBe("difficulty-medium");
|
||||||
expect(result).toContain("--difficulty-medium");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns hard difficulty CSS variable classes", () => {
|
it("returns difficulty-hard variant for hard", () => {
|
||||||
const result = getDifficultyColor("hard");
|
expect(getDifficultyVariant("hard")).toBe("difficulty-hard");
|
||||||
expect(result).toContain("--difficulty-hard");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ export function cn(...classes: (string | undefined | false)[]): string {
|
|||||||
return classes.filter(Boolean).join(" ");
|
return classes.filter(Boolean).join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDifficultyColor(difficulty: Difficulty): string {
|
export function getDifficultyVariant(
|
||||||
|
difficulty: Difficulty
|
||||||
|
): "difficulty-easy" | "difficulty-medium" | "difficulty-hard" {
|
||||||
switch (difficulty) {
|
switch (difficulty) {
|
||||||
case "easy":
|
case "easy":
|
||||||
return "text-[var(--difficulty-easy)] bg-[var(--difficulty-easy-bg)]";
|
return "difficulty-easy";
|
||||||
case "medium":
|
case "medium":
|
||||||
return "text-[var(--difficulty-medium)] bg-[var(--difficulty-medium-bg)]";
|
return "difficulty-medium";
|
||||||
case "hard":
|
case "hard":
|
||||||
return "text-[var(--difficulty-hard)] bg-[var(--difficulty-hard-bg)]";
|
return "difficulty-hard";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user