Skip to content

Instantly share code, notes, and snippets.

@manuelgeek
Last active May 20, 2024 20:14
Show Gist options
  • Save manuelgeek/3c66baa7635e622b00dab2483105c06e to your computer and use it in GitHub Desktop.
Save manuelgeek/3c66baa7635e622b00dab2483105c06e to your computer and use it in GitHub Desktop.
components
Form
Form.tsx
Form.hook.tsx
index.tsx
Form.helpers.tsx
Form.types.tsx
Components
Steps
Step1.tsx
Steps2
index.tsx
Steps2.tsx
Items
items.tsx
Items.hook.tsx
Items.tsx
Modal
Modal.tsx
Modal.hook.tsx
Step3.tsx
SideStep.tsx
Form.hook.tsx
- defaultValues = {name, email, password, number, ...}
- onSubmit()
- setFormData
- formData
- loading
Form.tsx
const [formData, defaultValue, loading, setFormData] = useAbcForm()
const [step, setStep] = useState(1)
<>
<SideStep step />
<>
Method 1:
switch(step){
case 1: <Step1 setForm, step, setStep />
case 2: <Step2 setForData />
case 3: <Step3 onSubmit />
case 4: <Submit onSubmit />
}
Method 2:
{step ===1 && <Step1 />}
{step ===2 && <Step2 />}
{step ===3 && <Step3 />}
</Step1>
</>
Step1.tsx
const {setFormData, defaultValues, setStep} = props
const form = useForm()
const [isModalOpen, setModalOpen] = useSate(false)
<>
<Form form={form}, defaultValues >
<Input rule='required'/>
<Input rule='required'/>
<Input rule='required'/>
<Input rule='required'/>
<Items>
<List></List>
{isModalOpen && <Modal steFormData, setModalOpen>}
</Items>
<Button onClick={() => {
form.validate().then(() => {
setFormValue(form)
setStep(2)
})
}}>Next</Button>
</Form>
</>
Modal.tsx
const {setFomrData} = props
const form = useForm()
<>
<Form form={form}, defaultValues >
<Input rule='required'/>
<Input rule='required'/>
<Input rule='required'/>
<Input rule='required'/>
<Button onClick={() => {
if(!form.Items.length){
// add modal items
return
}
form.validate().then(() => {
setFormValue(form)
setModalOpen(false)
})
}}>Next</Button>
</Form>
</>
defaultValues = {
name: '',
email: '',
items: [
{
id: 1,
name: ''
}
],
password: '',
amount: ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment