@@ -39,7 +39,7 @@ npm install swiper@latest
39
39
```
40
40
41
41
::: note
42
- Create React App does not support pure ESM packages yet. Developers can still use Swiper, but they will need to use Swiper 7.2 .0+ and use direct file imports. This guide assumes you are using Create React App and will show you how to use these direct imports .
42
+ Developers using Create React App must use ` react-scripts ` v5.0 .0+ with the latest version of Swiper .
43
43
:::
44
44
45
45
## Swiping with Style
@@ -53,7 +53,7 @@ import React from 'react';
53
53
import { IonContent , IonPage } from ' @ionic/react' ;
54
54
import { Swiper , SwiperSlide } from ' swiper/react' ;
55
55
56
- import ' swiper/swiper.min. css' ;
56
+ import ' swiper/css' ;
57
57
import ' @ionic/react/css/ionic-swiper.css' ;
58
58
59
59
const Home: React .FC = () => {
@@ -68,10 +68,6 @@ export default Home;
68
68
Importing ` @ionic/react/css/ionic-swiper.css ` is ** not** required to use Swiper.js with Ionic. This files is used for backward-compatibility with the ` IonSlides ` component and can be safely omitted if you prefer not to use the CSS Variables provided in the stylesheet.
69
69
:::
70
70
71
- ::: note
72
- Not using Create React App? You can import the Swiper CSS from ` swiper/css ` instead.
73
- :::
74
-
75
71
### Updating Selectors
76
72
77
73
Previously, we were able to target ` ion-slides ` and ` ion-slide ` to apply any custom styling. The contents of those style blocks remain the same, but we need to update the selectors. Below is a list of selector changes when going from ` ion-slides ` to Swiper React:
@@ -92,7 +88,7 @@ import React from 'react';
92
88
import { IonContent , IonPage } from ' @ionic/react' ;
93
89
import { Swiper , SwiperSlide } from ' swiper/react' ;
94
90
95
- import ' swiper/swiper. less' ;
91
+ import ' swiper/less' ;
96
92
import ' @ionic/react/css/ionic-swiper.css' ;
97
93
98
94
const Home: React .FC = () => {
@@ -110,7 +106,7 @@ import React from 'react';
110
106
import { IonContent , IonPage } from ' @ionic/react' ;
111
107
import { Swiper , SwiperSlide } from ' swiper/react' ;
112
108
113
- import ' swiper/swiper. scss' ;
109
+ import ' swiper/scss' ;
114
110
import ' @ionic/react/css/ionic-swiper.css' ;
115
111
116
112
const Home: React .FC = () => {
@@ -125,14 +121,14 @@ export default Home;
125
121
126
122
Swiper exports two components: ` Swiper ` and ` SwiperSlide ` . The ` Swiper ` component is the equivalent of ` IonSlides ` , and ` SwiperSlide ` is the equivalent of ` IonSlide ` .
127
123
128
- These components are imported from ` swiper/react/swiper-react.js ` :
124
+ These components are imported from ` swiper/react ` :
129
125
130
126
``` tsx
131
127
import React from ' react' ;
132
128
import { IonContent , IonPage } from ' @ionic/react' ;
133
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
129
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
134
130
135
- import ' swiper/swiper.min. css' ;
131
+ import ' swiper/css' ;
136
132
import ' @ionic/react/css/ionic-swiper.css' ;
137
133
138
134
const Home: React .FC = () => {
@@ -151,10 +147,6 @@ const Home: React.FC = () => {
151
147
export default Home ;
152
148
```
153
149
154
- ::: note
155
- Not using Create React App? You can import the Swiper components from ` swiper/react ` instead.
156
- :::
157
-
158
150
## Using Modules
159
151
160
152
By default, Swiper for React does not import any additional modules. To use modules such as Navigation or Pagination, you need to import them first.
@@ -166,15 +158,15 @@ To begin, we need to import the modules and their corresponding CSS files from t
166
158
``` tsx
167
159
import React from ' react' ;
168
160
import { IonContent , IonPage } from ' @ionic/react' ;
169
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
161
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
170
162
import { Autoplay , Keyboard , Pagination , Scrollbar , Zoom } from ' swiper' ;
171
163
172
- import ' swiper/swiper.min. css' ;
173
- import ' swiper/modules /autoplay/autoplay.min.css ' ;
174
- import ' swiper/modules /keyboard/keyboard.min.css ' ;
175
- import ' swiper/modules /pagination/pagination.min.css ' ;
176
- import ' swiper/modules /scrollbar/scrollbar.min.css ' ;
177
- import ' swiper/modules /zoom/zoom.min.css ' ;
164
+ import ' swiper/css' ;
165
+ import ' swiper/css /autoplay' ;
166
+ import ' swiper/css /keyboard' ;
167
+ import ' swiper/css /pagination' ;
168
+ import ' swiper/css /scrollbar' ;
169
+ import ' swiper/css /zoom' ;
178
170
import ' @ionic/react/css/ionic-swiper.css' ;
179
171
180
172
const Home: React .FC = () => {
@@ -193,24 +185,20 @@ const Home: React.FC = () => {
193
185
export default Home ;
194
186
```
195
187
196
- ::: note
197
- Not using Create React App? You can import these modules from ` swiper/css/[MODULE NAME] ` instead (i.e. ` swiper/css/autoplay ` ).
198
- :::
199
-
200
188
From here, we need to provide these modules to Swiper by using the ` modules ` property on the ` Swiper ` component:
201
189
202
190
``` tsx
203
191
import React from ' react' ;
204
192
import { IonContent , IonPage } from ' @ionic/react' ;
205
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
193
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
206
194
import { Autoplay , Keyboard , Pagination , Scrollbar , Zoom } from ' swiper' ;
207
195
208
- import ' swiper/swiper.min. css' ;
209
- import ' swiper/modules /autoplay/autoplay.min.css ' ;
210
- import ' swiper/modules /keyboard/keyboard.min.css ' ;
211
- import ' swiper/modules /pagination/pagination.min.css ' ;
212
- import ' swiper/modules /scrollbar/scrollbar.min.css ' ;
213
- import ' swiper/modules /zoom/zoom.min.css ' ;
196
+ import ' swiper/css' ;
197
+ import ' swiper/css /autoplay' ;
198
+ import ' swiper/css /keyboard' ;
199
+ import ' swiper/css /pagination' ;
200
+ import ' swiper/css /scrollbar' ;
201
+ import ' swiper/css /zoom' ;
214
202
import ' @ionic/react/css/ionic-swiper.css' ;
215
203
216
204
const Home: React .FC = () => {
@@ -234,15 +222,15 @@ Finally, we can turn these features on by using the appropriate properties:
234
222
``` tsx
235
223
import React from ' react' ;
236
224
import { IonContent , IonPage } from ' @ionic/react' ;
237
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
225
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
238
226
import { Autoplay , Keyboard , Pagination , Scrollbar , Zoom } from ' swiper' ;
239
227
240
- import ' swiper/swiper.min. css' ;
241
- import ' swiper/modules /autoplay/autoplay.min.css ' ;
242
- import ' swiper/modules /keyboard/keyboard.min.css ' ;
243
- import ' swiper/modules /pagination/pagination.min.css ' ;
244
- import ' swiper/modules /scrollbar/scrollbar.min.css ' ;
245
- import ' swiper/modules /zoom/zoom.min.css ' ;
228
+ import ' swiper/css' ;
229
+ import ' swiper/css /autoplay' ;
230
+ import ' swiper/css /keyboard' ;
231
+ import ' swiper/css /pagination' ;
232
+ import ' swiper/css /scrollbar' ;
233
+ import ' swiper/css /zoom' ;
246
234
import ' @ionic/react/css/ionic-swiper.css' ;
247
235
248
236
const Home: React .FC = () => {
@@ -281,15 +269,15 @@ We can install the `IonicSlides` module by importing it from `@ionic/react` and
281
269
``` tsx
282
270
import React from ' react' ;
283
271
import { IonContent , IonPage , IonicSlides } from ' @ionic/react' ;
284
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
272
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
285
273
import { Autoplay , Keyboard , Pagination , Scrollbar , Zoom } from ' swiper' ;
286
274
287
- import ' swiper/swiper.min. css' ;
288
- import ' swiper/modules /autoplay/autoplay.min.css ' ;
289
- import ' swiper/modules /keyboard/keyboard.min.css ' ;
290
- import ' swiper/modules /pagination/pagination.min.css ' ;
291
- import ' swiper/modules /scrollbar/scrollbar.min.css ' ;
292
- import ' swiper/modules /zoom/zoom.min.css ' ;
275
+ import ' swiper/css' ;
276
+ import ' swiper/css /autoplay' ;
277
+ import ' swiper/css /keyboard' ;
278
+ import ' swiper/css /pagination' ;
279
+ import ' swiper/css /scrollbar' ;
280
+ import ' swiper/css /zoom' ;
293
281
import ' @ionic/react/css/ionic-swiper.css' ;
294
282
295
283
const Home: React .FC = () => {
@@ -434,7 +422,7 @@ Accessing these properties can be tricky as you want to access the properties on
434
422
435
423
``` tsx
436
424
import React , { useState } from ' react' ;
437
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
425
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
438
426
import { Swiper as SwiperInterface } from ' swiper' ;
439
427
...
440
428
const Home: React .FC = () => {
@@ -477,9 +465,9 @@ If you are using effects such as Cube or Fade, you can install them just like we
477
465
import React from ' react' ;
478
466
import { IonContent , IonPage , IonicSlides } from ' @ionic/react' ;
479
467
import { EffectFade } from ' swiper' ;
480
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
468
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
481
469
482
- import ' swiper/swiper.min. css' ;
470
+ import ' swiper/css' ;
483
471
import ' @ionic/react/css/ionic-swiper.css' ;
484
472
485
473
const Home: React .FC = () => {
@@ -504,10 +492,10 @@ Next, we need to import the stylesheet associated with the effect:
504
492
import React from ' react' ;
505
493
import { IonContent , IonPage , IonicSlides } from ' @ionic/react' ;
506
494
import { EffectFade } from ' swiper' ;
507
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
495
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
508
496
509
- import ' swiper/swiper.min. css' ;
510
- import ' swiper/modules /effect-fade/effect-fade.min.css ' ;
497
+ import ' swiper/css' ;
498
+ import ' swiper/css /effect-fade' ;
511
499
import ' @ionic/react/css/ionic-swiper.css' ;
512
500
513
501
const Home: React .FC = () => {
@@ -526,20 +514,16 @@ const Home: React.FC = () => {
526
514
export default Home ;
527
515
```
528
516
529
- ::: note
530
- Not using Create React App? You can import these effects from ` swiper/css/[EFFECT NAME] ` instead (i.e. ` swiper/css/effect-fade ` ).
531
- :::
532
-
533
517
After that, we can activate it by setting the ` effect ` property on ` swiper ` to ` "fade" ` :
534
518
535
519
``` tsx
536
520
import React from ' react' ;
537
521
import { IonContent , IonPage , IonicSlides } from ' @ionic/react' ;
538
522
import { EffectFade } from ' swiper' ;
539
- import { Swiper , SwiperSlide } from ' swiper/react/swiper-react.js ' ;
523
+ import { Swiper , SwiperSlide } from ' swiper/react' ;
540
524
541
- import ' swiper/swiper.min. css' ;
542
- import ' swiper/modules /effect-fade/effect-fade.min.css ' ;
525
+ import ' swiper/css' ;
526
+ import ' swiper/css /effect-fade' ;
543
527
import ' @ionic/react/css/ionic-swiper.css' ;
544
528
545
529
const Home: React .FC = () => {
0 commit comments