Skip to content

Commit

Permalink
Merge pull request #144 from ZIA-Hans/feat/slide-gap-use-margin
Browse files Browse the repository at this point in the history
feat(carousel): slide item's gap use margin to complete
  • Loading branch information
FriedRiceNoodles authored May 28, 2024
2 parents e25fc00 + 6800fbf commit a92e12c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/fifty-paws-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@banana-ui/banana': patch
'@banana-ui/react': patch
---

slide item's gap use margin to complete
3 changes: 2 additions & 1 deletion packages/banana/src/carousel/index.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default [
transition: transform var(--banana-carousel-transition-duration, ${unsafeCSS(Var.TransitionNormal)});
/* This variable should not be used directly, use the gap property instead */
/* DO NOT PUT IT IN THE DOCUMENTATION */
gap: calc(var(--banana-carousel-gap, 0) * 1px);
}
.slides-wrapper--vertical {
flex-direction: column;
Expand All @@ -55,6 +54,7 @@ export default [
height: 100%;
flex-grow: 0;
flex-shrink: 0;
margin-right: calc(var(--banana-carousel-gap, 0) * 1px);
}
.slides-wrapper--vertical ::slotted(*) {
Expand All @@ -67,6 +67,7 @@ export default [
width: 100%;
flex-grow: 0;
flex-shrink: 0;
margin-bottom: calc(var(--banana-carousel-gap, 0) * 1px);
}
.navigation-buttons {
Expand Down
13 changes: 13 additions & 0 deletions packages/banana/src/carousel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,19 @@ export default class BCarousel extends LitElement {
this.requestUpdate();
await this.updateComplete;
this.calcHeight();
this._calcLastSlideGap();
}

private _calcLastSlideGap() {
if (this._loop) {
this.vertical
? (this._slidesWithCopys[this._slidesWithCopys.length - 1].style.marginBottom = '0px')
: (this._slidesWithCopys[this._slidesWithCopys.length - 1].style.marginRight = '0px');
} else {
this.vertical
? (this._slides[this._slides.length - 1].style.marginBottom = '0px')
: (this._slides[this._slides.length - 1].style.marginRight = '0px');
}
}

render() {
Expand Down

0 comments on commit a92e12c

Please sign in to comment.