-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextended-form.tsx
282 lines (273 loc) · 8.54 KB
/
extended-form.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
'use client'
import {
BlocksIcon,
BoxIcon,
BoxesIcon,
CloudIcon,
Code2Icon,
CodeIcon,
GlobeIcon,
LayersIcon,
PencilIcon,
ServerIcon,
} from 'lucide-react'
import { useRef, useState } from 'react'
import { toast } from 'sonner'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import MultiStepForm, { type FormStep } from '@/components/ui/multi-step-form'
import { Switch } from '@/components/ui/switch'
const formSteps: FormStep[] = [
{
level: 1,
id: 'project-type',
title: 'Select Your Project Type',
description: 'What type of project are you working on?',
items: [
{
id: 'custom',
title: 'Custom',
description: 'This is a Card with no image or icon',
validNextSteps: ['nextjs', 'astro', 'remix', 'next-commerce'],
},
{
id: 'webapp',
title: 'Web Application',
description: 'This is a Card with only icon',
icon: CodeIcon,
validNextSteps: ['nextjs', 'remix'],
},
{
id: 'website',
title: 'Website',
description: 'Card with icon & image',
image:
'https://images.unsplash.com/photo-1460925895917-afdab827c52f?q=80&w=2426&auto=format&fit=crop',
icon: GlobeIcon,
validNextSteps: ['nextjs', 'astro'],
},
{
id: 'ecommerce',
title: 'E-commerce',
description: 'This is a Card with only image',
image:
'https://images.unsplash.com/photo-1472851294608-062f824d29cc?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['shopify', 'next-commerce'],
},
{
id: 'blog',
title: 'Blog',
description: 'Another Sample',
icon: PencilIcon,
image:
'https://images.unsplash.com/photo-1499750310107-5fef28a66643?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['nextjs', 'astro'],
},
],
},
{
level: 2,
id: 'framework',
title: 'Choose Framework',
description: 'Select the framework that fits your project best',
items: [
{
id: 'nextjs',
title: 'Next.js',
description:
'React framework with server-side rendering and static generation',
icon: BlocksIcon,
image:
'https://images.unsplash.com/photo-1618761714954-0b8cd0026356?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['vercel', 'netlify'],
},
{
id: 'astro',
title: 'Astro',
description:
'Static site builder with excellent performance and flexibility',
icon: LayersIcon,
image:
'https://images.unsplash.com/photo-1635070041078-e363dbe005cb?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['netlify', 'cloudflare'],
},
{
id: 'remix',
title: 'Remix',
description:
'Full-stack web framework with excellent data loading and mutations',
icon: BoxesIcon,
image:
'https://images.unsplash.com/photo-1633356122544-f134324a6cee?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['fly', 'railway'],
},
{
id: 'shopify',
title: 'Shopify',
description: 'Complete e-commerce solution with customizable themes',
icon: BoxesIcon,
image:
'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['shopify-hosting'],
},
{
id: 'next-commerce',
title: 'Next.js Commerce',
description: 'Complete e-commerce solution with Next.js and Vercel',
icon: BlocksIcon,
image:
'https://images.unsplash.com/photo-1618761714954-0b8cd0026356?q=80&w=2370&auto=format&fit=crop',
validNextSteps: ['vercel'],
},
],
},
{
level: 3,
id: 'deployment',
title: 'Pick Your Deployment',
description: 'Select the deployment platform that fits your needs best',
items: [
{
id: 'vercel',
title: 'Vercel',
description: 'Zero-configuration deployment platform built for Next.js',
icon: CloudIcon,
image:
'https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2372&auto=format&fit=crop',
},
{
id: 'netlify',
title: 'Netlify',
description: 'Popular platform for automated deployment and hosting',
icon: ServerIcon,
image:
'https://images.unsplash.com/photo-1558494949-ef010cbdcc31?q=80&w=2372&auto=format&fit=crop',
},
{
id: 'cloudflare',
title: 'Cloudflare Pages',
description: 'Global edge network with unlimited bandwidth',
icon: BoxIcon,
image:
'https://images.unsplash.com/photo-1544197150-b99a580bb7a8?q=80&w=2370&auto=format&fit=crop',
},
{
id: 'fly',
title: 'Fly.io',
description: 'Global application platform with edge capabilities',
icon: CloudIcon,
image:
'https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2372&auto=format&fit=crop',
},
{
id: 'railway',
title: 'Railway',
description: 'Developer platform for deploying any type of application',
icon: BoxIcon,
image:
'https://images.unsplash.com/photo-1544197150-b99a580bb7a8?q=80&w=2370&auto=format&fit=crop',
},
{
id: 'shopify-hosting',
title: 'Shopify Hosting',
description: 'Built-in hosting solution for Shopify stores',
icon: CloudIcon,
image:
'https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2372&auto=format&fit=crop',
},
],
},
]
export default function ExtendedForm() {
const [isCompact, setIsCompact] = useState(false)
const formRef = useRef<HTMLFormElement>(null)
const handleComplete = (selections: Record<string | number, string>) => {
if (formRef.current) {
const isValid = formRef.current.checkValidity()
if (!isValid) {
formRef.current.reportValidity()
return false
}
}
const selectedItems = {
...formSteps
.map((step, index) => {
const selectedItem = step.items.find(
(item) => item.id === selections[index]
)
return {
[step.id]: selectedItem?.id,
}
})
.reduce((acc, curr) => ({ ...acc, ...curr }), {}),
// Add form inputs if they exist
...(selections.name ? { name: selections.name } : {}),
...(selections.email ? { email: selections.email } : {}),
}
toast('Form completed!', {
description: (
<pre className="mt-2 p-4 bg-muted rounded-lg overflow-auto">
<code className="text-sm">
{JSON.stringify(selectedItems, null, 2)}
</code>
</pre>
),
})
return true
}
return (
<MultiStepForm
title={
<div className="flex items-center justify-between w-full flex-col space-y-4">
<div className="flex items-center gap-2">
<Code2Icon className="h-6 w-6" />
<span className="font-semibold">Next Vista</span>
</div>
<div className="flex items-center space-x-2">
<Label className="text-sm font-medium">Default</Label>
<Switch
id="compact-mode"
checked={isCompact}
onCheckedChange={setIsCompact}
/>
<Label className="text-sm font-medium">Compact</Label>
</div>
</div>
}
formSteps={formSteps}
onComplete={handleComplete}
variant={isCompact ? 'compact' : 'default'}
imageClassName="grayscale hover:grayscale-0"
cardClassName="pb-2"
finalStep={
<div className="flex items-center gap-2">
<span className="font-semibold">Thank you for trying</span>
<Code2Icon className="h-5 w-5" />
<span className="font-semibold">Next-Stepper</span>
</div>
}
>
<form ref={formRef} className="space-y-4 p-4 border rounded-lg">
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<Input
id="name"
name="name"
required={true}
placeholder="Enter your name"
/>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
name="email"
type="email"
required={true}
placeholder="Enter your email"
/>
</div>
</form>
</MultiStepForm>
)
}