Open History to see the last commit
1import { useGT } from "gt-react";
2import { CheckIcon } from "lucide-react";
3import type { ComponentProps, ReactNode } from "react";
4
5import { cn } from "../../lib/utils";
6import { AnimatedHeight } from "../AnimatedHeight";
7import { DialogPopup, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "./dialog";
8import { ScrollArea } from "./scroll-area";
9
10export function WizardPopup({
11 children,
12 size = "default",
13 ...props
14}: Omit<ComponentProps<typeof DialogPopup>, "className" | "style"> & {
15 readonly size?: "default" | "wide";
16}) {
17 return (
18 <DialogPopup {...props} className={size === "wide" ? "max-w-3xl" : "max-w-xl"}>
19 <ScrollArea className="*:data-[slot=scroll-area-scrollbar]:data-[orientation=vertical]:my-4">
20 <div className="flex min-h-0 flex-col">{children}</div>
21 </ScrollArea>
22 </DialogPopup>
23 );
24}
25
26export function WizardHeader({
27 title,
28 description,
29 identity,
30 children,
31}: {
32 readonly title: ReactNode;
33 readonly description?: ReactNode;
34 readonly identity?: ReactNode;
35 readonly children?: ReactNode;
36}) {
37 return (
38 <DialogHeader>
39 <DialogTitle className={identity ? "sr-only" : undefined}>{title}</DialogTitle>
40 {identity}
41 {description ? <DialogDescription>{description}</DialogDescription> : null}
42 {children}
43 </DialogHeader>
44 );
45}
46
47export function WizardFooter({
48 children,
49 leading,
50}: {
51 readonly children: ReactNode;
52 readonly leading?: ReactNode;
53}) {
54 return (
55 <DialogFooter variant="bare" className={leading ? "sm:justify-between" : undefined}>
56 {leading}
57 {leading ? (
58 <div className="flex flex-col-reverse gap-2 sm:flex-row">{children}</div>
59 ) : (
60 children
61 )}
62 </DialogFooter>
63 );
64}
65
66export function WizardSteps({
67 steps,
68 currentStep,
69 summaries,
70 showSummaries = false,
71 onStepChange,
72 isStepDisabled,
73}: {
74 readonly steps: readonly string[];
75 readonly currentStep: number;
76 readonly summaries?: readonly (string | null)[];
77 readonly showSummaries?: boolean;
78 readonly isStepDisabled?: (step: number) => boolean;
79 readonly onStepChange?: (step: number) => void;
80}) {
81 const gt = useGT();
82 const Step = onStepChange ? "button" : "div";
83 return (
84 <ol
85 className="grid auto-cols-fr grid-flow-col gap-1 rounded-xl bg-background p-1 ring-1 ring-black/5 dark:bg-white/4 dark:ring-white/5"
86 role="list"
87 aria-label={gt`Setup progress`}
88 >
89 {steps.map((step, index) => (
90 <li key={step} className="min-w-0">
91 <Step
92 {...(onStepChange
93 ? { type: "button" as const, disabled: isStepDisabled?.(index) }
94 : {})}
95 className={cn(
96 "flex w-full min-w-0 items-center gap-2 rounded-lg px-2.5 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring max-sm:justify-center max-sm:px-2",
97 onStepChange &&
98 "cursor-pointer hover:bg-card disabled:cursor-default disabled:hover:bg-transparent",
99 index === currentStep &&
100 "bg-card text-foreground shadow-xs ring-1 ring-inset ring-black/5 hover:bg-card dark:shadow-none dark:ring-white/5",
101 )}
102 aria-current={index === currentStep ? "step" : undefined}
103 aria-label={
104 index < currentStep && summaries?.[index]
105 ? gt`${{ step }}, step ${{ number: index + 1 }}, ${{ summary: summaries[index] }}`
106 : gt`${{ step }}, step ${{ number: index + 1 }}`
107 }
108 onClick={onStepChange ? () => onStepChange(index) : undefined}
109 >
110 <span
111 className={cn(
112 "grid size-5 shrink-0 place-items-center rounded-full text-sm font-medium ring-1",
113 index < currentStep
114 ? "bg-primary text-primary-foreground ring-primary"
115 : index === currentStep
116 ? "bg-primary/10 text-primary ring-primary/30"
117 : "bg-card text-muted-foreground ring-black/10 dark:bg-white/5 dark:ring-white/10",
118 )}
119 aria-hidden
120 >
121 {index < currentStep ? <CheckIcon className="size-4 shrink-0" /> : index + 1}
122 </span>
123 <span
124 className={cn(
125 "min-w-0 truncate text-sm font-medium max-sm:hidden",
126 index === currentStep ? "text-foreground" : "text-muted-foreground",
127 )}
128 >
129 {step}
130 {showSummaries && index < currentStep && summaries?.[index]
131 ? `: ${summaries[index]}`
132 : null}
133 </span>
134 </Step>
135 </li>
136 ))}
137 </ol>
138 );
139}
140
141export function WizardPanel({
142 children,
143 holdHeight = false,
144 className,
145}: {
146 readonly children: ReactNode;
147 readonly holdHeight?: boolean;
148 readonly className?: string;
149}) {
150 return (
151 <div
152 data-slot="dialog-panel"
153 className={cn(
154 "min-w-0 space-y-4 bg-background/80 px-6 py-5 ring-1 ring-black/5 dark:bg-white/2 dark:ring-white/5",
155 className,
156 )}
157 >
158 <AnimatedHeight holdHeight={holdHeight}>{children}</AnimatedHeight>
159 </div>
160 );
161}