Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

Auth.tsx

57 lines1.7 KB

1export function Auth({
2 actionText,
3 onSubmit,
4 status,
5 afterSubmit,
6}: {
7 actionText: string
8 onSubmit: (e: React.FormEvent<HTMLFormElement>) => void
9 status: 'pending' | 'idle' | 'success' | 'error'
10 afterSubmit?: React.ReactNode
11}) {
12 return (
13 <div className="fixed inset-0 bg-white dark:bg-black flex items-start justify-center p-8">
14 <div className="bg-white dark:bg-gray-900 p-8 rounded-lg shadow-lg">
15 <h1 className="text-2xl font-bold mb-4">{actionText}</h1>
16 <form
17 onSubmit={(e) => {
18 e.preventDefault()
19 onSubmit(e)
20 }}
21 className="space-y-4"
22 >
23 <div>
24 <label htmlFor="email" className="block text-xs">
25 Username
26 </label>
27 <input
28 type="email"
29 name="email"
30 id="email"
31 className="px-2 py-1 w-full rounded-sm border border-gray-500/20 bg-white dark:bg-gray-800"
32 />
33 </div>
34 <div>
35 <label htmlFor="password" className="block text-xs">
36 Password
37 </label>
38 <input
39 type="password"
40 name="password"
41 id="password"
42 className="px-2 py-1 w-full rounded-sm border border-gray-500/20 bg-white dark:bg-gray-800"
43 />
44 </div>
45 <button
46 type="submit"
47 className="w-full bg-cyan-600 text-white rounded-sm py-2 font-black uppercase"
48 disabled={status === 'pending'}
49 >
50 {status === 'pending' ? '...' : actionText}
51 </button>
52 {afterSubmit ? afterSubmit : null}
53 </form>
54 </div>
55 </div>
56 )