Skip to content

Commit f596d0b

Browse files
authored
refactor: use native swiper instead of ngx-swiper-wrapper (#552)
1 parent afc7bfd commit f596d0b

16 files changed

+153
-135
lines changed

angular.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
{
6767
"type": "bundle",
6868
"name": "vendor",
69-
"baseline": "1mb",
70-
"warning": "200kb",
71-
"error": "500kb"
69+
"baseline": "900kb",
70+
"warning": "100kb",
71+
"error": "300kb"
7272
},
7373
{
7474
"type": "initial",

docs/guides/migrations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ We removed the property `production` from Angular CLI `environment.ts` files.
1313
Production mode can now consistently be set by using Angular CLI configurations.
1414
This also works when running multiple configurations like `--configuration=brand,production`.
1515

16+
We removed the dependency `ngx-swiper-wrapper` as it will [no longer be supported](https://github.com/zefoy/ngx-swiper-wrapper#eol-notice) and `swiper` now [natively supports](https://swiperjs.com/angular) Angular.
17+
1618
## 0.26 to 0.27
1719

1820
We upgraded Cypress from Version 4 to 6 and followed all migrations in their [Migration Guide](https://docs.cypress.io/guides/references/migration-guide.html).

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@
8989
"morgan": "^1.10.0",
9090
"ng-recaptcha": "^6.1.0",
9191
"ngx-infinite-scroll": "^10.0.0",
92-
"ngx-swiper-wrapper": "^10.0.0",
9392
"ngx-toastr": "^13.2.0",
9493
"ngx-utils-cookies-port": "^1.0.1",
9594
"prom-client": "^12.0.0",
9695
"rxjs": "~6.6.3",
97-
"swiper": "^6.3.5",
96+
"swiper": "^6.4.12",
9897
"tslib": "^2.0.3",
9998
"typeface-roboto": "1.1.13",
10099
"typeface-roboto-condensed": "1.1.13",

src/app/core/appearance.module.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import { NgModule } from '@angular/core';
22
import { NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap';
3-
import { SWIPER_CONFIG, SwiperConfigInterface } from 'ngx-swiper-wrapper';
43
import { ToastrModule } from 'ngx-toastr';
54

65
import { IconModule } from './icon.module';
76
import { ThemeService } from './utils/theme/theme.service';
87

9-
const DEFAULT_SWIPER_CONFIG: SwiperConfigInterface = {
10-
direction: 'horizontal',
11-
keyboard: true,
12-
mousewheel: false,
13-
navigation: true,
14-
scrollbar: false,
15-
};
16-
178
@NgModule({
189
imports: [
1910
IconModule,
@@ -24,7 +15,6 @@ const DEFAULT_SWIPER_CONFIG: SwiperConfigInterface = {
2415
preventDuplicates: true,
2516
}),
2617
],
27-
providers: [{ provide: SWIPER_CONFIG, useValue: DEFAULT_SWIPER_CONFIG }],
2818
})
2919
export class AppearanceModule {
3020
constructor(popoverConfig: NgbPopoverConfig, themeService: ThemeService) {

src/app/extensions/wishlists/shared/wishlist-widget/wishlist-widget.component.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ <h3>{{ 'account.wishlists.widget.heading' | translate }}</h3>
55
<div class="product-list">
66
<swiper [config]="swiperConfig">
77
<div *ngFor="let sku of itemSku" class="swiper-slide">
8-
<ish-product-item
9-
displayType="tile"
10-
ishProductContext
11-
[sku]="sku"
12-
[configuration]="tileConfiguration"
13-
></ish-product-item>
8+
<ng-template swiperSlide>
9+
<ish-product-item
10+
displayType="tile"
11+
ishProductContext
12+
[sku]="sku"
13+
[configuration]="tileConfiguration"
14+
></ish-product-item>
15+
</ng-template>
1416
</div>
1517
</swiper>
18+
<div class="swiper-pagination"></div>
1619
</div>
1720
</ng-container>
1821
<ng-template #noItems>

src/app/extensions/wishlists/shared/wishlist-widget/wishlist-widget.component.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { TranslateModule } from '@ngx-translate/core';
33
import { MockComponent, MockDirective } from 'ng-mocks';
4-
import { SwiperModule } from 'ngx-swiper-wrapper';
54
import { EMPTY } from 'rxjs';
5+
import { SwiperComponent } from 'swiper/angular';
66
import { instance, mock, when } from 'ts-mockito';
77

88
import { ProductContextDirective } from 'ish-core/directives/product-context.directive';
@@ -24,10 +24,11 @@ describe('Wishlist Widget Component', () => {
2424
await TestBed.configureTestingModule({
2525
declarations: [
2626
MockComponent(ProductItemComponent),
27+
MockComponent(SwiperComponent),
2728
MockDirective(ProductContextDirective),
2829
WishlistWidgetComponent,
2930
],
30-
imports: [SwiperModule, TranslateModule.forRoot()],
31+
imports: [TranslateModule.forRoot()],
3132
providers: [{ provide: WishlistsFacade, useFactory: () => instance(wishlistFacadeMock) }],
3233
}).compileComponents();
3334
});

src/app/extensions/wishlists/shared/wishlist-widget/wishlist-widget.component.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core';
2-
import { SwiperConfigInterface } from 'ngx-swiper-wrapper';
32
import { Observable } from 'rxjs';
3+
import { SwiperOptions } from 'swiper';
4+
import SwiperCore, { Navigation, Pagination } from 'swiper/core';
45

5-
import { LARGE_BREAKPOINT_WIDTH } from 'ish-core/configurations/injection-keys';
6+
import { LARGE_BREAKPOINT_WIDTH, MEDIUM_BREAKPOINT_WIDTH } from 'ish-core/configurations/injection-keys';
67
import { ProductContextDisplayProperties } from 'ish-core/facades/product-context.facade';
78
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';
89

910
import { WishlistsFacade } from '../../facades/wishlists.facade';
1011

12+
SwiperCore.use([Navigation, Pagination]);
13+
1114
/**
1215
* The Wishlist Widget Component displays all unique items from all wish lists.
1316
*/
@@ -20,15 +23,19 @@ import { WishlistsFacade } from '../../facades/wishlists.facade';
2023
export class WishlistWidgetComponent implements OnInit {
2124
allWishlistsItemsSkus$: Observable<string[]>;
2225
itemsPerSlide = 4;
26+
tileConfiguration: Partial<ProductContextDisplayProperties>;
27+
2328
/**
2429
* configuration of swiper carousel
2530
* find possible parameters here: http://idangero.us/swiper/api/#parameters
2631
*/
27-
swiperConfig: SwiperConfigInterface;
32+
swiperConfig: SwiperOptions;
2833

29-
tileConfiguration: Partial<ProductContextDisplayProperties>;
30-
31-
constructor(private wishlistsFacade: WishlistsFacade, @Inject(LARGE_BREAKPOINT_WIDTH) largeBreakpointWidth: number) {
34+
constructor(
35+
private wishlistsFacade: WishlistsFacade,
36+
@Inject(LARGE_BREAKPOINT_WIDTH) largeBreakpointWidth: number,
37+
@Inject(MEDIUM_BREAKPOINT_WIDTH) mediumBreakpointWidth: number
38+
) {
3239
this.tileConfiguration = {
3340
addToWishlist: false,
3441
addToOrderTemplate: false,
@@ -37,7 +44,20 @@ export class WishlistWidgetComponent implements OnInit {
3744
};
3845

3946
this.swiperConfig = {
47+
direction: 'horizontal',
48+
keyboard: true,
49+
mousewheel: false,
50+
navigation: true,
51+
scrollbar: false,
4052
breakpoints: {
53+
0: {
54+
slidesPerView: 2,
55+
slidesPerGroup: 2,
56+
},
57+
[mediumBreakpointWidth]: {
58+
slidesPerView: 3,
59+
slidesPerGroup: 3,
60+
},
4161
[largeBreakpointWidth]: {
4262
slidesPerView: 4,
4363
slidesPerGroup: 4,
@@ -48,8 +68,6 @@ export class WishlistWidgetComponent implements OnInit {
4868
clickable: true,
4969
clickableClass: 'swiper-pagination-clickable',
5070
},
51-
slidesPerView: 2,
52-
slidesPerGroup: 2,
5371
};
5472
}
5573

src/app/pages/product/product-links-carousel/product-links-carousel.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ <h2>{{ productLinkTitle }}</h2>
44
<div class="product-list">
55
<swiper [config]="swiperConfig">
66
<div *ngFor="let sku of links.products" class="swiper-slide">
7-
<ish-product-item ishProductContext [sku]="sku"></ish-product-item>
7+
<ng-template swiperSlide>
8+
<ish-product-item ishProductContext [sku]="sku"></ish-product-item>
9+
</ng-template>
810
</div>
911
</swiper>
12+
<div class="swiper-pagination"></div>
1013
</div>
1114
</div>

src/app/pages/product/product-links-carousel/product-links-carousel.component.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { MockComponent, MockDirective } from 'ng-mocks';
3-
import { SwiperModule } from 'ngx-swiper-wrapper';
3+
import { SwiperComponent } from 'swiper/angular';
44

55
import { ProductContextDirective } from 'ish-core/directives/product-context.directive';
66
import { ProductLinks } from 'ish-core/models/product-links/product-links.model';
@@ -15,9 +15,9 @@ describe('Product Links Carousel Component', () => {
1515

1616
beforeEach(async () => {
1717
await TestBed.configureTestingModule({
18-
imports: [SwiperModule],
1918
declarations: [
2019
MockComponent(ProductItemComponent),
20+
MockComponent(SwiperComponent),
2121
MockDirective(ProductContextDirective),
2222
ProductLinksCarouselComponent,
2323
],
@@ -38,10 +38,5 @@ describe('Product Links Carousel Component', () => {
3838
expect(element).toBeTruthy();
3939
expect(() => fixture.detectChanges()).not.toThrow();
4040
expect(element.querySelector('swiper')).toBeTruthy();
41-
expect(element.querySelector('swiper .swiper-slide')).toMatchInlineSnapshot(`
42-
<div class="swiper-slide">
43-
<ish-product-item ishproductcontext="" ng-reflect-sku="sku"></ish-product-item>
44-
</div>
45-
`);
4641
});
4742
});

src/app/pages/product/product-links-carousel/product-links-carousel.component.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
2-
import { SwiperConfigInterface } from 'ngx-swiper-wrapper';
1+
import { ChangeDetectionStrategy, Component, Inject, Input } from '@angular/core';
2+
import { SwiperOptions } from 'swiper';
3+
import SwiperCore, { Navigation, Pagination } from 'swiper/core';
34

5+
import { LARGE_BREAKPOINT_WIDTH, MEDIUM_BREAKPOINT_WIDTH } from 'ish-core/configurations/injection-keys';
46
import { ProductLinks } from 'ish-core/models/product-links/product-links.model';
57

8+
SwiperCore.use([Navigation, Pagination]);
9+
610
/**
711
* The Product Link Carousel Component
812
*
@@ -26,8 +30,42 @@ export class ProductLinksCarouselComponent {
2630
* title that should displayed for the specific product link type
2731
*/
2832
@Input() productLinkTitle: string;
33+
2934
/**
30-
* configuration for swiper carousel
35+
* configuration of swiper carousel
36+
* find possible parameters here: http://idangero.us/swiper/api/#parameters
3137
*/
32-
@Input() swiperConfig: SwiperConfigInterface;
38+
swiperConfig: SwiperOptions;
39+
40+
constructor(
41+
@Inject(LARGE_BREAKPOINT_WIDTH) largeBreakpointWidth: number,
42+
@Inject(MEDIUM_BREAKPOINT_WIDTH) mediumBreakpointWidth: number
43+
) {
44+
this.swiperConfig = {
45+
direction: 'horizontal',
46+
keyboard: true,
47+
mousewheel: false,
48+
navigation: true,
49+
scrollbar: false,
50+
breakpoints: {
51+
0: {
52+
slidesPerView: 2,
53+
slidesPerGroup: 2,
54+
},
55+
[mediumBreakpointWidth]: {
56+
slidesPerView: 3,
57+
slidesPerGroup: 3,
58+
},
59+
[largeBreakpointWidth]: {
60+
slidesPerView: 4,
61+
slidesPerGroup: 4,
62+
},
63+
},
64+
pagination: {
65+
el: '.swiper-pagination',
66+
clickable: true,
67+
clickableClass: 'swiper-pagination-clickable',
68+
},
69+
};
70+
}
3371
}

src/app/pages/product/product-links/product-links.component.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,36 @@
1515
<ish-product-links-carousel
1616
[links]="links.crossselling"
1717
[productLinkTitle]="'product.product_links.crossselling.title' | translate"
18-
[swiperConfig]="swiperConfig"
1918
></ish-product-links-carousel>
2019
</ng-container>
2120
<ng-container *ngIf="links.accessory?.products?.length">
2221
<ish-product-links-carousel
2322
[links]="links.accessory"
2423
[productLinkTitle]="'product.product_links.accessory.title' | translate"
25-
[swiperConfig]="swiperConfig"
2624
></ish-product-links-carousel>
2725
</ng-container>
2826
<ng-container *ngIf="links.differentorderunit?.products?.length">
2927
<ish-product-links-carousel
3028
[links]="links.differentorderunit"
3129
[productLinkTitle]="'product.product_links.differentorderunit.title' | translate"
32-
[swiperConfig]="swiperConfig"
3330
></ish-product-links-carousel>
3431
</ng-container>
3532
<ng-container *ngIf="links.followup?.products?.length">
3633
<ish-product-links-carousel
3734
[links]="links.followup"
3835
[productLinkTitle]="'product.product_links.followup.title' | translate"
39-
[swiperConfig]="swiperConfig"
4036
></ish-product-links-carousel>
4137
</ng-container>
4238
<ng-container *ngIf="links.other?.products?.length">
4339
<ish-product-links-carousel
4440
[links]="links.other"
4541
[productLinkTitle]="'product.product_links.other.title' | translate"
46-
[swiperConfig]="swiperConfig"
4742
></ish-product-links-carousel>
4843
</ng-container>
4944
<ng-container *ngIf="links.replacement?.products?.length">
5045
<ish-product-links-carousel
5146
[links]="links.replacement"
5247
[productLinkTitle]="'product.product_links.replacement.title' | translate"
53-
[swiperConfig]="swiperConfig"
5448
></ish-product-links-carousel>
5549
</ng-container>
5650
</ng-container>

0 commit comments

Comments
 (0)