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