Skip to content

Commit

Permalink
fix(core): carousel slides order render (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-rosa-jsm authored Jan 2, 2024
1 parent f45c3a5 commit fe08197
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { newSpecPage } from '@stencil/core/testing'

import { AtomCarousel } from '../carousel'

import { AtomCarouselItem } from './carousel-item'

describe('AtomCarouselItem', () => {
Expand All @@ -12,6 +13,7 @@ describe('AtomCarouselItem', () => {
<atom-carousel-item> Slide 2</atom-carousel-item>
</atom-carousel>`,
})

await page.waitForChanges()
expect(page.root?.innerHTML).not.toContain('<atom-carousel-ite')
expect(page.root?.innerHTML).toContain('<swiper-slide')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ import { Component, Element, Host, h } from '@stencil/core'
export class AtomCarouselItem {
@Element() host!: HTMLElement

componentDidLoad() {
const parentSwiperContainer =
this.host.parentElement.querySelector('swiper-container')
const swiperSlide = this.host.querySelector('swiper-slide')
parentSwiperContainer.appendChild(swiperSlide)
this.host.parentElement.removeChild(this.host)
}
render() {
return (
<Host>
<swiper-slide class="atom-carousel-item">
<swiper-slide class='atom-carousel-item'>
<slot />
</swiper-slide>
</Host>
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/components/carousel/carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
}
}

::part(container) {
padding-bottom: var(--spacing-giant);
::part(pagination) {
margin-top: var(--spacing-large);
position: unset;
}

::part(thumb) {
Expand Down Expand Up @@ -63,4 +64,4 @@
height: var(--spacing-giant);
object-fit: contain;
width: var(--spacing-giant);
}
}
12 changes: 12 additions & 0 deletions packages/core/src/components/carousel/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ export class AtomCarousel {

componentDidLoad() {
this.swiperEl = this.host.querySelector('swiper-container')

const children = this.host.querySelectorAll('atom-carousel-item')

children.forEach((child) => {
const slide = child.querySelector('swiper-slide')

if (slide) {
this.swiperEl.appendChild(slide)
this.host.removeChild(child)
}
})

this.swiperEl.swiper?.on('slideChange', () => {
this.atomChange.emit()
})
Expand Down

0 comments on commit fe08197

Please sign in to comment.