Raw
1 "use client"
2
3 import {
4 CheckCircleSolid,
5 CircleDottedLine,
6 CircleHalfSolid,
7 } from "@medusajs/icons"
8 import { Tabs as RadixTabs } from "radix-ui"
9 import * as React from "react"
10
11 import { ProgressStatus } from "@/types"
12 import { clx } from "@/utils/clx"
13
14 /**
15 * This component is based on the [Radix UI Tabs](https://radix-ui.com/primitives/docs/components/tabs) primitves.
16 *
17 */
18 const ProgressTabsRoot = (props: RadixTabs.TabsProps) => {
19 return <RadixTabs.Root {...props} />
20 }
21 ProgressTabsRoot.displayName = "ProgressTabs"
22
23 interface IndicatorProps
24 extends Omit<React.ComponentPropsWithoutRef<"span">, "children"> {
25 /**
26 * The current status.
27 */
28 status?: ProgressStatus
29 }
30
31 const ProgressIndicator = ({ status, className, ...props }: IndicatorProps) => {
32 const Icon = React.useMemo(() => {
33 switch (status) {
34 case "not-started":
35 return CircleDottedLine
36 case "in-progress":
37 return CircleHalfSolid
38 case "completed":
39 return CheckCircleSolid
40 default:
41 return CircleDottedLine
42 }
43 }, [status])
44
45 return (
46 <span
47 className={clx(
48 "text-ui-fg-muted group-data-[state=active]/trigger:text-ui-fg-interactive",
49 className
50 )}
51 {...props}
52 >
53 <Icon />
54 </span>
55 )
56 }
57 ProgressIndicator.displayName = "ProgressTabs.ProgressIndicator"
58
59 interface ProgressTabsTriggerProps
60 extends Omit<
61 React.ComponentPropsWithoutRef<typeof RadixTabs.Trigger>,
62 "asChild"
63 > {
64 status?: ProgressStatus
65 }
66
67 const ProgressTabsTrigger = React.forwardRef<
68 React.ElementRef<typeof RadixTabs.Trigger>,
69 ProgressTabsTriggerProps
70 >(
71 (
72 {
73 className,
74 children,
75 status = "not-started",
76 ...props
77 }: ProgressTabsTriggerProps,
78 ref
79 ) => (
80 <RadixTabs.Trigger
81 ref={ref}
82 className={clx(
83 "txt-compact-small-plus transition-fg text-ui-fg-muted bg-ui-bg-subtle border-r-ui-border-base inline-flex h-[52px] w-full max-w-[200px] flex-1 items-center gap-x-2 border-r px-4 text-left outline-none",
84 "group/trigger overflow-hidden text-ellipsis whitespace-nowrap",
85 "disabled:bg-ui-bg-disabled disabled:text-ui-fg-muted",
86 "hover:bg-ui-bg-subtle-hover",
87 "focus-visible:bg-ui-bg-base focus:z-[1]",
88 "data-[state=active]:text-ui-fg-base data-[state=active]:bg-ui-bg-base",
89 className
90 )}
91 {...props}
92 >
93 <ProgressIndicator status={status} />
94 {children}
95 </RadixTabs.Trigger>
96 )
97 )
98 ProgressTabsTrigger.displayName = "ProgressTabs.Trigger"
99
100 const ProgressTabsList = React.forwardRef<
101 React.ElementRef<typeof RadixTabs.List>,
102 React.ComponentPropsWithoutRef<typeof RadixTabs.List>
103 >(({ className, ...props }, ref) => (
104 <RadixTabs.List
105 ref={ref}
106 className={clx("flex items-center", className)}
107 {...props}
108 />
109 ))
110 ProgressTabsList.displayName = "ProgressTabs.List"
111
112 const ProgressTabsContent = React.forwardRef<
113 React.ElementRef<typeof RadixTabs.Content>,
114 React.ComponentPropsWithoutRef<typeof RadixTabs.Content>
115 >(({ className, ...props }, ref) => {
116 return (
117 <RadixTabs.Content
118 ref={ref}
119 className={clx("outline-none", className)}
120 {...props}
121 />
122 )
123 })
124 ProgressTabsContent.displayName = "ProgressTabs.Content"
125
126 const ProgressTabs = Object.assign(ProgressTabsRoot, {
127 Trigger: ProgressTabsTrigger,
128 List: ProgressTabsList,
129 Content: ProgressTabsContent,
130 })
131
132 export { ProgressTabs }