Skip to content

Commit 49df3d2

Browse files
upgraded to latest ionic react hook form and swiper
1 parent f2cd1e7 commit 49df3d2

File tree

7 files changed

+23876
-11824
lines changed

7 files changed

+23876
-11824
lines changed

package-lock.json

Lines changed: 23787 additions & 11767 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,43 @@
33
"version": "0.0.1",
44
"private": true,
55
"dependencies": {
6-
"@capacitor/core": "2.4.7",
7-
"@hookform/error-message": "0.0.5",
8-
"@ionic/react": "5.4.4",
9-
"@ionic/react-router": "5.4.4",
6+
"@capacitor/app": "1.1.1",
7+
"@capacitor/core": "3.4.3",
8+
"@capacitor/haptics": "1.1.4",
9+
"@capacitor/ios": "3.4.3",
10+
"@capacitor/keyboard": "1.2.2",
11+
"@capacitor/status-bar": "1.0.8",
12+
"@hookform/error-message": "2.0.0",
13+
"@ionic/react": "^6.0.0",
14+
"@ionic/react-router": "^6.0.0",
1015
"@testing-library/jest-dom": "^5.11.9",
1116
"@testing-library/react": "^11.2.5",
1217
"@testing-library/user-event": "^12.6.3",
13-
"@types/jest": "^24.0.25",
14-
"@types/node": "^12.12.24",
15-
"@types/react": "^16.9.17",
16-
"@types/react-dom": "^16.9.4",
17-
"@types/react-router": "^5.1.4",
18-
"@types/react-router-dom": "^5.1.3",
19-
"ionicons": "5.2.3",
20-
"react": "^16.13.0",
21-
"react-dom": "^16.13.0",
22-
"react-hook-form": "^6.15.1",
23-
"react-router": "^5.1.2",
24-
"react-router-dom": "^5.1.2",
25-
"react-scripts": "3.4.0",
26-
"typescript": "3.8.3"
18+
"@types/jest": "^26.0.20",
19+
"@types/node": "^12.19.15",
20+
"@types/react": "^16.14.3",
21+
"@types/react-dom": "^16.9.10",
22+
"@types/react-router": "^5.1.11",
23+
"@types/react-router-dom": "^5.1.7",
24+
"ionicons": "6.0.1",
25+
"react": "^17.0.1",
26+
"react-dom": "^17.0.1",
27+
"react-hook-form": "7.29.0",
28+
"react-router": "^5.2.0",
29+
"react-router-dom": "^5.2.0",
30+
"react-scripts": "^5.0.0",
31+
"swiper": "^8.0.7"
2732
},
2833
"scripts": {
29-
"start": "FAST_REFRESH=false react-scripts start",
34+
"start": "react-scripts start",
3035
"build": "react-scripts build",
31-
"test": "react-scripts test",
36+
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(@ionic/react|@ionic/react-router|@ionic/core|@stencil/core|ionicons)/)'",
3237
"eject": "react-scripts eject"
3338
},
3439
"eslintConfig": {
3540
"extends": [
36-
"react-app"
41+
"react-app",
42+
"react-app/jest"
3743
]
3844
},
3945
"browserslist": {
@@ -49,8 +55,9 @@
4955
]
5056
},
5157
"devDependencies": {
52-
"@capacitor/cli": "2.4.7",
53-
"@ionic/lab": "3.2.10"
58+
"@capacitor/cli": "3.4.3",
59+
"@ionic/cli": "6.19.0",
60+
"@ionic/lab": "3.2.11"
5461
},
5562
"description": "An Ionic project"
5663
}

src/pages/BasicInfo.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { ErrorMessage } from "@hookform/error-message";
44
import React from "react";
55

66
export const BasicInfo: React.FC<any> = ({ next }) => {
7-
const { register, errors } = useFormContext(); // retrieve all hook methods
7+
const {
8+
register,
9+
formState: { errors },
10+
} = useFormContext(); // retrieve all hook methods
811

912
return (
1013
<div className="slide-main ion-padding">
@@ -13,21 +16,19 @@ export const BasicInfo: React.FC<any> = ({ next }) => {
1316
<IonItem lines="none">
1417
<IonInput
1518
autocomplete="new-password"
16-
name="first"
1719
placeholder="First Name"
1820
type="text"
19-
ref={register({ required: "First Name Is Required" })}
21+
{...register("first", { required: "First Name Is Required" })}
2022
></IonInput>
2123
</IonItem>
2224
<ErrorMessage errors={errors} name="first" />
2325

2426
<IonItem lines="none" style={{ marginTop: 8 }}>
2527
<IonInput
2628
autocomplete="new-password"
27-
name="last"
2829
placeholder="Last Name"
2930
type="text"
30-
ref={register({ required: "Last Name Is Required" })}
31+
{...register("last", { required: "Last Name Is Required" })}
3132
></IonInput>
3233
</IonItem>
3334
<ErrorMessage errors={errors} name="last" />

src/pages/ContactInfo.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ import { ErrorMessage } from "@hookform/error-message";
88
import React from "react";
99

1010
const ContactInfo: React.FC<any> = ({ prev }) => {
11-
const { register, errors } = useFormContext(); // retrieve all hook methods
11+
const { register, formState: { errors }, } = useFormContext(); // retrieve all hook methods
1212
return (
1313
<div className="slide-main ion-padding">
1414
<div className="form-content">
1515
<h1>Contact Information</h1>
1616
<IonItem lines="none">
1717
<IonInput
18-
name="email"
1918
placeholder="Email Address"
2019
type="email"
21-
ref={register({ required: "Email Is Required" })}
20+
{...register("email", { required: "Email Is Required" })}
2221
></IonInput>
2322
</IonItem>
2423
<ErrorMessage errors={errors} name="email" />
2524

2625
<IonItem lines="none" style={{ marginTop: 8 }}>
2726
<IonInput
28-
name="phone"
2927
placeholder="Phone Number"
30-
ref={register({ required: "Phone Number Is Required" })}
28+
{...register("phone", { required: "Phone Number Is Required" })}
3129
></IonInput>
3230
</IonItem>
3331
<ErrorMessage errors={errors} name="phone" />

src/pages/Home.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@
1111

1212
.form-footer {
1313
float: right !important;
14+
}
15+
16+
.a-slide {
17+
height: 100%;
18+
background-color: grey;
19+
font-size: 30px;
20+
padding: 16px;
21+
}
22+
23+
.noSwipingClass {
24+
margin: auto;
1425
}

src/pages/Home.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import {
66
IonToolbar,
77
IonSlides,
88
IonSlide,
9+
setupIonicReact,
910
} from "@ionic/react";
1011

1112
// react hook form
1213
import { FormProvider, useForm } from "react-hook-form";
1314

15+
//swiper
16+
import { Swiper, SwiperSlide } from "swiper/react";
17+
// Import Swiper styles
18+
import 'swiper/css';
1419

1520
import React, { useEffect, useRef, useState } from "react";
1621

@@ -19,35 +24,36 @@ import BasicInfo from "./BasicInfo";
1924
import PasswordInfo from "./PasswordInfo";
2025
import ContactInfo from "./ContactInfo";
2126

27+
setupIonicReact();
28+
2229
const slideOpts = {
2330
initialSlide: 0,
2431
speed: 400,
2532
};
2633

2734
const Home: React.FC = () => {
28-
const mySlides = useRef<any>(null);
35+
const [mySlides, setMySlides] = useState<any>(null)
2936
const [formData, setFormData] = useState<any>();
3037

3138
const methods = useForm();
3239
const { handleSubmit, trigger } = methods;
3340

34-
3541
useEffect(() => {
36-
mySlides.current.lockSwipes(true);
42+
// mySlides?.lockSwipes(true);
3743
});
3844

3945
const next = async (fields: any) => {
4046
const result = await trigger(fields);
4147
if (!result) return;
42-
await mySlides.current.lockSwipes(false);
43-
await mySlides.current.slideNext();
44-
await mySlides.current.lockSwipes(true);
48+
// await mySlides?.lockSwipes(false);
49+
await mySlides?.slideNext();
50+
// await mySlides?.lockSwipes(true);
4551
};
4652

4753
const prev = async () => {
48-
await mySlides.current.lockSwipes(false);
49-
await mySlides.current.slidePrev();
50-
await mySlides.current.lockSwipes(true);
54+
// await mySlides?.lockSwipes(false);
55+
await mySlides?.slidePrev();
56+
// await mySlides?.lockSwipes(true);
5157
};
5258

5359
const onSubmit = (data: any) => {
@@ -64,18 +70,25 @@ const Home: React.FC = () => {
6470
</IonHeader>
6571
<IonContent fullscreen className="ion-padding">
6672
<FormProvider {...methods}>
67-
<form onSubmit={handleSubmit(onSubmit)} autoComplete="off">
68-
<IonSlides pager={true} options={slideOpts} ref={mySlides}>
69-
<IonSlide>
70-
<BasicInfo next={next} />
71-
</IonSlide>
72-
<IonSlide>
73+
<form onSubmit={handleSubmit(onSubmit)} autoComplete="off">
74+
<Swiper
75+
spaceBetween={50}
76+
slidesPerView={1}
77+
noSwiping={true}
78+
noSwipingClass="noSwipingClass"
79+
onSlideChange={() => console.log("slide change")}
80+
onSwiper={(swiper) => setMySlides(swiper)}
81+
>
82+
<SwiperSlide className="noSwipingClass">
83+
<BasicInfo next={next} className="noSwiping"/>
84+
</SwiperSlide>
85+
<SwiperSlide className="noSwipingClass">
7386
<PasswordInfo next={next} prev={prev} />
74-
</IonSlide>
75-
<IonSlide>
87+
</SwiperSlide>
88+
<SwiperSlide className="noSwipingClass">
7689
<ContactInfo prev={prev} />
77-
</IonSlide>
78-
</IonSlides>
90+
</SwiperSlide>
91+
</Swiper>
7992
</form>
8093
</FormProvider>
8194
<div style={{ fontSize: "smaller" }}>

src/pages/PasswordInfo.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ import { ErrorMessage } from "@hookform/error-message";
44
import React from "react";
55

66
const PasswordInfo: React.FC<any> = ({ next, prev }) => {
7-
const { register, errors, getValues } = useFormContext(); // retrieve all hook methods
7+
const {
8+
register,
9+
formState: { errors },
10+
getValues,
11+
} = useFormContext(); // retrieve all hook methods
812
return (
913
<div className="slide-main ion-padding">
1014
<div className="form-content">
1115
<h1>Password Information</h1>
1216
<IonItem lines="none">
1317
<IonInput
1418
autocomplete="new-password"
15-
name="password-1"
1619
placeholder="Password"
1720
type="password"
18-
ref={register({ required: "Password Is Required" })}
21+
{...register("password-1", { required: "Password Is Required" })}
1922
></IonInput>
2023
</IonItem>
2124
<ErrorMessage errors={errors} name="password-1" />
2225

2326
<IonItem lines="none" style={{ marginTop: 8 }}>
2427
<IonInput
2528
autocomplete="new-password"
26-
name="password-2"
2729
placeholder="Confirm Password"
2830
type="password"
29-
ref={register({
31+
{...register("password-2", {
3032
validate: {
3133
noMatch: (value: string) => {
3234
return value !== getValues("password-1")

0 commit comments

Comments
 (0)