Skip to content

Commit 5f3e38c

Browse files
🐛 fix(carousel): support space and full-height (#1587)
* Create PR for #1586 * feat(carousel): add space and improve full-height --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gery Hirschfeld <[email protected]>
1 parent c2bf532 commit 5f3e38c

File tree

8 files changed

+51
-4
lines changed

8 files changed

+51
-4
lines changed

.changeset/fuzzy-impalas-smile.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@baloise/ds-core': patch
3+
---
4+
5+
**carousel**: full-height option makes all item the same height

.changeset/wicked-wombats-pump.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@baloise/ds-core': minor
3+
---
4+
5+
**carousel**: add space prop to define the gap between items

packages/core/src/components.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ export namespace Components {
419419
* If `true` vertical scrolling on mobile is enabled.
420420
*/
421421
"scrollY": boolean;
422+
/**
423+
* Defines the layout of the navigation controls.
424+
*/
425+
"space": 'normal' | 'medium' | 'none';
422426
/**
423427
* When how many slides are moved when going forward or backward.
424428
*/
@@ -5511,6 +5515,10 @@ declare namespace LocalJSX {
55115515
* If `true` vertical scrolling on mobile is enabled.
55125516
*/
55135517
"scrollY"?: boolean;
5518+
/**
5519+
* Defines the layout of the navigation controls.
5520+
*/
5521+
"space"?: 'normal' | 'medium' | 'none';
55145522
/**
55155523
* When how many slides are moved when going forward or backward.
55165524
*/

packages/core/src/components/bal-carousel/bal-carousel.sass

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
.bal-carousel--full-height
66
height: 100%
77

8+
.bal-carousel--full-height .bal-carousel__item
9+
height: auto
10+
811
.bal-carousel__inner--full-height
912
height: 100%
1013

packages/core/src/components/bal-carousel/bal-carousel.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ export class Carousel
9494
this.swiper.controls = this.controls
9595
}
9696

97+
/**
98+
* Defines the layout of the navigation controls.
99+
*/
100+
@Prop() space: 'normal' | 'medium' | 'none' = 'none'
101+
102+
@Watch('space')
103+
onSpaceChange() {
104+
this.swiper.gapSpace = this.space
105+
}
106+
97107
/**
98108
* @deprecated
99109
* Defines the role of the carousel.
@@ -128,7 +138,7 @@ export class Carousel
128138

129139
@Watch('interface')
130140
onInterFaceChange() {
131-
this.swiper.gapSize = this.interface === 'product' ? 16 : 0
141+
this.swiper.gapSpace = this.interface === 'product' ? 'normal' : this.space
132142
}
133143

134144
/**
@@ -159,9 +169,10 @@ export class Carousel
159169
connectedCallback(): void {
160170
this.swiper.connectedCallback(this)
161171
this.onControlsChange()
162-
this.onInterFaceChange()
163172
this.onItemsPerViewChange()
164173
this.onStepsChange()
174+
this.onSpaceChange()
175+
this.onInterFaceChange()
165176
this.onValueChange()
166177
}
167178

packages/core/src/utils/swiper/swiper.sass

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
transition-duration: 0ms
4747
transform: translate3d(0px,0px,0px)
4848

49+
.bal-swiper__container--gap-none
50+
gap: 0
51+
.bal-swiper__container--gap-normal
52+
gap: 1rem
53+
.bal-swiper__container--gap-medium
54+
gap: 1.5rem
55+
4956
// Controls
5057
// --------------------------------------------------
5158

packages/core/src/utils/swiper/swiper.type.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface SwiperSlide {
2323
}
2424

2525
export type SwiperControl = 'small' | 'large' | 'dots' | 'none' | 'tabs'
26+
export type SwiperGapSpace = 'normal' | 'medium' | 'none'
2627
export type SwiperItemsPerView = 'auto' | 1 | 2 | 3 | 4
2728

2829
export type SwiperInterface = {

packages/core/src/utils/swiper/swiper.util.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
SwiperChildItem,
1010
SwiperControl,
1111
SwiperControlItem,
12+
SwiperGapSpace,
1213
SwiperInterface,
1314
SwiperItemsPerView,
1415
SwiperSlide,
@@ -31,12 +32,12 @@ export class SwiperUtil {
3132
borderEl?: HTMLElement
3233

3334
index = 0
34-
gapSize = 0
3535
steps = 1
3636
noNeedForControls = true
3737
isLastSlideVisible = false
3838
itemsPerView: SwiperItemsPerView = 1
3939
controls: SwiperControl = 'none'
40+
gapSpace: SwiperGapSpace = 'none'
4041

4142
/**
4243
* LIFECYCLE
@@ -185,6 +186,7 @@ export class SwiperUtil {
185186

186187
public cssSwiperContainer = () => ({
187188
...this.cssBlock.element('container').class(this.active),
189+
...this.cssBlock.element('container').modifier(`gap-${this.gapSpace}`).class(this.active),
188190
})
189191

190192
/**
@@ -350,7 +352,12 @@ export class SwiperUtil {
350352
const index = slideIndex === undefined ? this.lastIndex() : slideIndex
351353

352354
if (items.length > index && index >= 0) {
353-
const gapSize = this.gapSize
355+
const gaps = {
356+
none: 0,
357+
normal: 16,
358+
medium: 24,
359+
}
360+
const gapSize = gaps[this.gapSpace]
354361

355362
const transformNext = items
356363
.filter((_, n) => n < index + 1)

0 commit comments

Comments
 (0)