@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 165 lines 5.21 KB
Raw
1 import { useGT } from "gt-react";
2 import { CheckIcon } from "lucide-react";
3 import type { ComponentProps, ReactNode } from "react";
4
5 import { cn } from "../../lib/utils";
6 import { AnimatedHeight } from "../AnimatedHeight";
7 import { DialogPopup, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "./dialog";
8 import { ScrollArea } from "./scroll-area";
9
10 export 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
26 export 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
47 export 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
66 export 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}, {summary}", {
106 step,
107 number: index + 1,
108 summary: summaries[index],
109 })
110 : gt("{step}, step {number}", { step, number: index + 1 })
111 }
112 onClick={onStepChange ? () => onStepChange(index) : undefined}
113 >
114 <span
115 className={cn(
116 "grid size-5 shrink-0 place-items-center rounded-full text-sm font-medium ring-1",
117 index < currentStep
118 ? "bg-primary text-primary-foreground ring-primary"
119 : index === currentStep
120 ? "bg-primary/10 text-primary ring-primary/30"
121 : "bg-card text-muted-foreground ring-black/10 dark:bg-white/5 dark:ring-white/10",
122 )}
123 aria-hidden
124 >
125 {index < currentStep ? <CheckIcon className="size-4 shrink-0" /> : index + 1}
126 </span>
127 <span
128 className={cn(
129 "min-w-0 truncate text-sm font-medium max-sm:hidden",
130 index === currentStep ? "text-foreground" : "text-muted-foreground",
131 )}
132 >
133 {step}
134 {showSummaries && index < currentStep && summaries?.[index]
135 ? `: ${summaries[index]}`
136 : null}
137 </span>
138 </Step>
139 </li>
140 ))}
141 </ol>
142 );
143 }
144
145 export function WizardPanel({
146 children,
147 holdHeight = false,
148 className,
149 }: {
150 readonly children: ReactNode;
151 readonly holdHeight?: boolean;
152 readonly className?: string;
153 }) {
154 return (
155 <div
156 data-slot="dialog-panel"
157 className={cn(
158 "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",
159 className,
160 )}
161 >
162 <AnimatedHeight holdHeight={holdHeight}>{children}</AnimatedHeight>
163 </div>
164 );
165 }