Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(carousel): centralize the slide item content #385

Merged
merged 12 commits into from
Feb 27, 2024
363 changes: 252 additions & 111 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"postcss-scss": "^4.0.6",
"prettier": "3.0.0",
"prop-types": "^15.8.1",
"puppeteer": "^21.5.2",
"puppeteer": "^22.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "^3.26.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export namespace Components {
"autoplay"?: boolean;
"autoplayDelay"?: AutoplayOptions['delay'];
"centerInsufficientSlides"?: boolean;
"centeredSlides"?: boolean;
"freeMode"?: boolean;
"loop"?: boolean;
"navigation"?: boolean;
Expand Down Expand Up @@ -498,6 +499,7 @@ declare namespace LocalJSX {
"autoplay"?: boolean;
"autoplayDelay"?: AutoplayOptions['delay'];
"centerInsufficientSlides"?: boolean;
"centeredSlides"?: boolean;
"freeMode"?: boolean;
"loop"?: boolean;
"navigation"?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/badge/badge.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
line-height: 0;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/button/button.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
display: inline-block;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import '~@atomium/scss-utils/index';

.atom-carousel-item {
width: fit-content;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Element, Host, h } from '@stencil/core'
@Component({
tag: 'atom-carousel-item',
styleUrl: 'carousel-item.scss',
shadow: false,
})
export class AtomCarouselItem {
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
@@ -1,3 +1,4 @@
@import '~@atomium/scss-utils/index';
@import '~swiper/swiper-bundle.css';
@import '~swiper/swiper.css';

Expand All @@ -7,7 +8,7 @@
border: 1px solid transparent;
border-radius: var(--border-radius-full);
box-shadow: var(--elevation-3);
color: var(--color-brand-secondary-dark-1);
color: var(--color-brand-secondary-regular);
height: var(--spacing-medium);
padding: var(--spacing-small);
transition:
Expand All @@ -18,7 +19,7 @@
will-change: border, box-shadow;

&:hover {
border-color: var(--color-brand-secondary-dark-1);
border-color: var(--color-brand-secondary-regular);
}
}

Expand Down Expand Up @@ -64,4 +65,4 @@
height: var(--spacing-giant);
object-fit: contain;
width: var(--spacing-giant);
}
}
3 changes: 3 additions & 0 deletions packages/core/src/components/carousel/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class AtomCarousel {
@Prop({ mutable: true })
autoplayDelay?: AutoplayOptions['delay']
@Prop({ mutable: true })
centeredSlides?: boolean = false
@Prop({ mutable: true })
centerInsufficientSlides?: boolean = false
@Prop({ mutable: true })
freeMode?: boolean
Expand Down Expand Up @@ -127,6 +129,7 @@ export class AtomCarousel {
injectStyles={this.injectStyles}
touch-start-prevent-default='false'
center-insufficient-slides={this.centerInsufficientSlides}
centered-slides={this.centeredSlides}
></swiper-container>
</Host>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@ const createComponent = (args, itemClass: string) => {

${args.loop !== undefined ? `loop="${args.loop}"` : ''}
${args.autoplay !== undefined ? `autoplay="${args.autoplay}"` : ''}
${args.speed !== undefined ? `speed="${args.speed}"` : ''} >
<atom-carousel-item ><div class="${itemClass}">Slide 1</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 2</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 3</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 4</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 5</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 6</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 7</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 8</div></atom-carousel-item>
<atom-carousel-item lazy="true">
<div class="${itemClass}">Slide 9
<img loading="lazy" width="100px" src="https://user-images.githubusercontent.com/3603793/257943112-fb180815-7bd7-45f7-ad14-bd1677079931.png"/>
</div>
</atom-carousel-item>
${args.speed !== undefined ? `speed="${args.speed}"` : ''}
${
args.centeredSlides !== undefined
? `centered-slides="${args.centeredSlides}"`
: ''
} >
<atom-carousel-item><div class="${itemClass}">Slide 1</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 2</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 3</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 4</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 5</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 6</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 7</div></atom-carousel-item>
<atom-carousel-item><div class="${itemClass}">Slide 8</div></atom-carousel-item>
<atom-carousel-item lazy="true">
<div class="${itemClass}">Slide 9
<img loading="lazy" width="100px" src="https://user-images.githubusercontent.com/3603793/257943112-fb180815-7bd7-45f7-ad14-bd1677079931.png"/>
</div>
</atom-carousel-item>
</atom-carousel>
<script>
const atomCarousel${carouselStoryId} = document.querySelector('atom-carousel#carousel-${carouselStoryId}');
Expand All @@ -77,9 +82,9 @@ export const Default: StoryObj = {
createComponent(
{
pagination: true,
slidesPerView: 3,
spaceBetween: 40,
paginationClickable: true,
centeredSlides: true,
},
'item-default'
),
Expand Down Expand Up @@ -115,3 +120,18 @@ export const PaginationType: StoryObj = {
'item-pag-type'
),
}

export const CenteredSlide: StoryObj = {
render: () =>
createComponent(
{
pagination: true,
slidesPerView: 'auto',
slidesPerGroup: 'auto',
spaceBetween: 20,
paginationClickable: true,
centeredSlides: true,
},
'item-smaller'
),
}
15 changes: 12 additions & 3 deletions packages/core/src/components/carousel/stories/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
display: flex;
height: 400px;
justify-content: center;
width: 100% !important;
width: 100%;
}

.item-loop {
Expand All @@ -13,7 +13,7 @@
display: flex;
height: 400px;
justify-content: center;
width: 100% !important;
width: 100%;
}

.item-pag-type {
Expand All @@ -22,5 +22,14 @@
display: flex;
height: 400px;
justify-content: center;
width: 100% !important;
width: 100%;
}

.item-smaller {
align-items: center;
background: coral;
display: flex;
height: 400px;
justify-content: center;
width: 400px;
}
2 changes: 2 additions & 0 deletions packages/core/src/components/chip/chip.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
--icon-size: var(--spacing-base);
display: inline-flex;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/grid/grid.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

.atom-grid {
display: flex;
flex-wrap: wrap;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/input/input.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
--atom-icon-color: var(--color-neutral-regular);
--atom-icon-grid: var(--spacing-xxxxlarge);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/select/select.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
--atom-icon-color: var(--color-neutral-regular);
--atom-icon-grid: var(--spacing-xxxxlarge);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/tag/tag.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
--icon-size: var(--spacing-small);
--atom-tag-height: 10px;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/textarea/textarea.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~@atomium/scss-utils/index';

:host {
--atom-icon-color: var(--color-neutral-regular);
--atom-icon-grid: var(--spacing-xxxxlarge);
Expand Down
Loading