Skip to content

Commit

Permalink
feat(carousel): add space and improve full-height
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch88 committed Jan 31, 2025
1 parent 3e58a06 commit c32fec0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-impalas-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**carousel**: full-height option makes all item the same height
5 changes: 5 additions & 0 deletions .changeset/wicked-wombats-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': minor
---

**carousel**: add space prop to define the gap between items
8 changes: 8 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ export namespace Components {
* If `true` vertical scrolling on mobile is enabled.
*/
"scrollY": boolean;
/**
* Defines the layout of the navigation controls.
*/
"space": 'normal' | 'medium' | 'none';
/**
* When how many slides are moved when going forward or backward.
*/
Expand Down Expand Up @@ -5511,6 +5515,10 @@ declare namespace LocalJSX {
* If `true` vertical scrolling on mobile is enabled.
*/
"scrollY"?: boolean;
/**
* Defines the layout of the navigation controls.
*/
"space"?: 'normal' | 'medium' | 'none';
/**
* When how many slides are moved when going forward or backward.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/components/bal-carousel/bal-carousel.sass
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
.bal-carousel--full-height
height: 100%

.bal-carousel--full-height .bal-carousel__item
height: auto

.bal-carousel__inner--full-height
height: 100%

Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/components/bal-carousel/bal-carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ export class Carousel
this.swiper.controls = this.controls
}

/**
* Defines the layout of the navigation controls.
*/
@Prop() space: 'normal' | 'medium' | 'none' = 'none'

@Watch('space')
onSpaceChange() {
this.swiper.gapSpace = this.space
}

/**
* @deprecated
* Defines the role of the carousel.
Expand Down Expand Up @@ -128,7 +138,7 @@ export class Carousel

@Watch('interface')
onInterFaceChange() {
this.swiper.gapSize = this.interface === 'product' ? 16 : 0
this.swiper.gapSpace = this.interface === 'product' ? 'normal' : this.space
}

/**
Expand Down Expand Up @@ -159,9 +169,10 @@ export class Carousel
connectedCallback(): void {
this.swiper.connectedCallback(this)
this.onControlsChange()
this.onInterFaceChange()
this.onItemsPerViewChange()
this.onStepsChange()
this.onSpaceChange()
this.onInterFaceChange()
this.onValueChange()
}

Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/utils/swiper/swiper.sass
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
transition-duration: 0ms
transform: translate3d(0px,0px,0px)

.bal-swiper__container--gap-none
gap: 0
.bal-swiper__container--gap-normal
gap: 1rem
.bal-swiper__container--gap-medium
gap: 1.5rem

// Controls
// --------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/swiper/swiper.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface SwiperSlide {
}

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

export type SwiperInterface = {
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/utils/swiper/swiper.util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
SwiperChildItem,
SwiperControl,
SwiperControlItem,
SwiperGapSpace,
SwiperInterface,
SwiperItemsPerView,
SwiperSlide,
Expand All @@ -31,12 +32,12 @@ export class SwiperUtil {
borderEl?: HTMLElement

index = 0
gapSize = 0
steps = 1
noNeedForControls = true
isLastSlideVisible = false
itemsPerView: SwiperItemsPerView = 1
controls: SwiperControl = 'none'
gapSpace: SwiperGapSpace = 'none'

/**
* LIFECYCLE
Expand Down Expand Up @@ -185,6 +186,7 @@ export class SwiperUtil {

public cssSwiperContainer = () => ({
...this.cssBlock.element('container').class(this.active),
...this.cssBlock.element('container').modifier(`gap-${this.gapSpace}`).class(this.active),
})

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

if (items.length > index && index >= 0) {
const gapSize = this.gapSize
const gaps = {
none: 0,
normal: 16,
medium: 24,
}
const gapSize = gaps[this.gapSpace]

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

0 comments on commit c32fec0

Please sign in to comment.