@@ -2,18 +2,21 @@ import { PROGRAM_CATEGORIES_MAP } from "@/lib/network/program-categories";
22import { Category } from "@dub/prisma/client" ;
33import { CircleInfo } from "@dub/ui" ;
44import { cn } from "@dub/utils" ;
5+ import Link from "next/link" ;
56
67export const programCategorySurfaceClassName =
78 "inline-flex h-5 max-h-5 min-w-0 items-center gap-1 rounded-full bg-neutral-900/[0.06] px-2 text-xs font-medium text-neutral-900 shadow-[0_0.5px_1px_0_rgba(0,0,0,0.03)] ring-1 ring-inset ring-neutral-900/[0.05] backdrop-blur-[3px] backdrop-saturate-150 transition-[background-color,transform] duration-150 ease-out [@media(hover:hover)]:hover:bg-neutral-900/[0.09] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100 [@media(hover:none)]:hover:bg-neutral-900/[0.06]" ;
89
910export const ProgramCategory = ( {
1011 category,
1112 onClick,
13+ href,
1214 variant = "default" ,
1315 className,
1416} : {
1517 category : Category ;
1618 onClick ?: ( ) => void ;
19+ href ?: string ;
1720 variant ?: "default" | "pill" | "surface" ;
1821 className ?: string ;
1922} ) => {
@@ -23,33 +26,23 @@ export const ProgramCategory = ({
2326 label : category . replaceAll ( "_" , " " ) ,
2427 } ;
2528
26- const As = onClick ? "button" : "div" ;
29+ const sharedClassName = cn (
30+ variant === "surface"
31+ ? programCategorySurfaceClassName
32+ : variant === "pill"
33+ ? "inline-flex min-w-0 items-center gap-1.5 rounded-full bg-neutral-100 px-2 py-0.5 text-xs font-medium text-neutral-600"
34+ : "text-content-default -ml-1 flex h-6 min-w-0 items-center gap-1 rounded-md px-1" ,
35+ ( href || onClick ) &&
36+ ( variant === "pill"
37+ ? "hover:bg-neutral-200/80 active:bg-neutral-200"
38+ : variant === "default"
39+ ? "hover:bg-bg-subtle active:bg-bg-emphasis"
40+ : undefined ) ,
41+ className ,
42+ ) ;
2743
28- return (
29- < As
30- { ...( onClick && {
31- type : "button" ,
32- onClick : ( e ) => {
33- e . preventDefault ( ) ;
34- e . stopPropagation ( ) ;
35- onClick ?.( ) ;
36- } ,
37- } ) }
38- className = { cn (
39- variant === "surface"
40- ? programCategorySurfaceClassName
41- : variant === "pill"
42- ? "inline-flex min-w-0 items-center gap-1.5 rounded-full bg-neutral-100 px-2 py-0.5 text-xs font-medium text-neutral-600"
43- : "text-content-default -ml-1 flex h-6 min-w-0 items-center gap-1 rounded-md px-1" ,
44- onClick &&
45- ( variant === "pill"
46- ? "hover:bg-neutral-200/80 active:bg-neutral-200"
47- : variant === "default"
48- ? "hover:bg-bg-subtle active:bg-bg-emphasis"
49- : undefined ) ,
50- className ,
51- ) }
52- >
44+ const content = (
45+ < >
5346 < Icon
5447 className = { cn (
5548 "shrink-0" ,
@@ -72,6 +65,32 @@ export const ProgramCategory = ({
7265 >
7366 { label }
7467 </ span >
75- </ As >
68+ </ >
7669 ) ;
70+
71+ if ( href ) {
72+ return (
73+ < Link href = { href } className = { sharedClassName } >
74+ { content }
75+ </ Link >
76+ ) ;
77+ }
78+
79+ if ( onClick ) {
80+ return (
81+ < button
82+ type = "button"
83+ onClick = { ( e ) => {
84+ e . preventDefault ( ) ;
85+ e . stopPropagation ( ) ;
86+ onClick ?.( ) ;
87+ } }
88+ className = { sharedClassName }
89+ >
90+ { content }
91+ </ button >
92+ ) ;
93+ }
94+
95+ return < div className = { sharedClassName } > { content } </ div > ;
7796} ;
0 commit comments