1
1
"use client" ;
2
2
3
3
import { Inputs } from "@/app/promptInput/page" ;
4
- import { motion } from "motion/react" ;
5
-
6
- import Link from "next/link" ;
7
4
import { FormEvent } from "react" ;
5
+ import NavigationButtons from "../navigationButtons/NavigationButtons" ;
6
+ import AnimationContainer from "../animationContainer/AnimationContainer" ;
8
7
9
8
interface FormProps {
10
9
inputs : Inputs [ ] ;
@@ -29,115 +28,36 @@ export default function Form({ inputs, handleNext, handleBack }: FormProps) {
29
28
handleBack ( ) ;
30
29
}
31
30
32
- const variants = {
33
- hidden : { opacity : 0 , y : 50 , scale : 0.95 , rotateX : - 10 } ,
34
- visible : {
35
- opacity : 1 ,
36
- y : 0 ,
37
- scale : 1 ,
38
- rotateX : 0 ,
39
- transition : { duration : 0.8 , ease : "easeOut" , delay : 0.2 } ,
40
- } ,
41
- } ;
42
-
43
- function NextButton ( { input, idx } : { input : Inputs ; idx : number } ) {
44
- return (
45
- < button
46
- className = "w-1/4 mt-4 flex justify-end bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
47
- type = "button"
48
- onClick = { ( ) => scrollToNextComponent ( input , idx ) }
49
- >
50
- Next
51
- </ button >
52
- ) ;
53
- }
54
-
55
- function BackButton ( { input, idx } : { input : Inputs ; idx : number } ) {
56
- return (
57
- < button
58
- className = { `${
59
- idx === 0 ? "hidden" : "visible"
60
- } w-1/4 flex justify-start bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-4`}
61
- type = "button"
62
- onClick = { ( ) => scrollToPrevComponent ( input , idx ) }
63
- >
64
- Back
65
- </ button >
66
- ) ;
67
- }
68
-
69
- function ReviewButton ( ) {
70
- return (
71
- < Link
72
- href = "review"
73
- className = "flex w-full justify-end p-4 m-2 h-12 text-black underline"
74
- >
75
- ReView
76
- </ Link >
77
- ) ;
78
- }
79
-
80
31
function handleSubmit ( event : FormEvent < HTMLFormElement > ) {
81
32
event . preventDefault ( ) ;
82
33
}
83
34
84
- const FIRST_INPUT_INDEX = 0 ;
85
- const LAST_INPUT_INDEX = inputs . length - 1 ;
86
-
87
35
return (
88
36
< form
89
37
onSubmit = { handleSubmit }
90
38
className = "flex flex-col w-full p-10 items-center"
91
39
>
92
- { /* inputs components */ }
40
+ { /* Form Sections */ }
93
41
{ inputs . map ( ( input , idx ) => (
94
- < motion . div
95
- key = { input . title }
96
- initial = "hidden"
97
- whileInView = "visible"
98
- viewport = { { once : false , amount : 0.5 } }
99
- variants = { variants }
100
- className = "w-full"
101
- >
102
- < section
103
- className = { `${
104
- idx === FIRST_INPUT_INDEX ? "h-[90vh]" : "h-[100vh]"
105
- } w-full flex flex-col justify-center`}
106
- ref = { input . inputRef }
107
- >
108
- < div className = "flex flex-col items-center text-black" >
109
- < label className = "bg-white m-2" > { input . title } </ label >
110
- < input
111
- type = "text"
112
- required
113
- name = { input . title }
114
- className = "p-4 bg-[#CAD2C5] w-1/2 flex"
115
- placeholder = { input . title }
116
- />
117
- { /* Buttons */ }
118
-
119
- { idx === FIRST_INPUT_INDEX ? (
120
- < div className = "w-1/2 flex justify-end" >
121
- { " " }
122
- < NextButton idx = { idx } input = { input } />
123
- </ div >
124
- ) : idx === LAST_INPUT_INDEX ? (
125
- < div className = " w-1/2" >
126
- < BackButton idx = { idx } input = { input } /> < ReviewButton /> { " " }
127
- </ div >
128
- ) : (
129
- < div className = "w-1/2 flex justify-evenly" >
130
- < div className = " w-full flex " >
131
- < BackButton idx = { idx } input = { input } />
132
- </ div >
133
- < div className = "flex justify-end w-full" >
134
- < NextButton idx = { idx } input = { input } />
135
- </ div >
136
- </ div >
137
- ) }
138
- </ div >
139
- </ section >
140
- </ motion . div >
42
+ < AnimationContainer key = { input . title } input = { input } idx = { idx } >
43
+ < div className = "flex flex-col items-center text-black" >
44
+ < label className = "bg-white m-2" > { input . title } </ label >
45
+ < input
46
+ type = "text"
47
+ required
48
+ name = { input . title }
49
+ className = "p-4 bg-[#CAD2C5] w-1/2 flex"
50
+ placeholder = { input . title }
51
+ />
52
+ { /* Buttons */ }
53
+ < NavigationButtons
54
+ idx = { idx }
55
+ scrollToNextComponent = { scrollToNextComponent }
56
+ scrollToPrevComponent = { scrollToPrevComponent }
57
+ input = { input }
58
+ />
59
+ </ div >
60
+ </ AnimationContainer >
141
61
) ) }
142
62
</ form >
143
63
) ;
0 commit comments