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
4 changes: 4 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export namespace Components {
"autoplay"?: boolean;
"autoplayDelay"?: AutoplayOptions['delay'];
"centerInsufficientSlides"?: boolean;
"centeredSlides"?: boolean;
"freeMode"?: boolean;
"loop"?: boolean;
"navigation"?: boolean;
"navigationButtonSize"?: 'medium' | 'xxlarge';
"pagination"?: boolean;
"paginationClickable"?: boolean;
"paginationType"?: PaginationOptions['type'] | 'thumbnails';
Expand Down Expand Up @@ -498,9 +500,11 @@ declare namespace LocalJSX {
"autoplay"?: boolean;
"autoplayDelay"?: AutoplayOptions['delay'];
"centerInsufficientSlides"?: boolean;
"centeredSlides"?: boolean;
"freeMode"?: boolean;
"loop"?: boolean;
"navigation"?: boolean;
"navigationButtonSize"?: 'medium' | 'xxlarge';
"onAtomChange"?: (event: AtomCarouselCustomEvent<string>) => void;
"onAtomClickNext"?: (event: AtomCarouselCustomEvent<string>) => void;
"onAtomClickPrev"?: (event: AtomCarouselCustomEvent<string>) => void;
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
12 changes: 5 additions & 7 deletions packages/core/src/components/carousel/carousel.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
@import '~@atomium/scss-utils/index';
@import '~swiper/swiper-bundle.css';
@import '~swiper/swiper.css';

::part(button-prev),
::part(button-next) {
background: var(--color-neutral-white);
border: 1px solid transparent;
background: var(--color-brand-secondary-regular);
border-radius: var(--border-radius-full);
box-shadow: var(--elevation-3);
color: var(--color-brand-secondary-dark-1);
height: var(--spacing-medium);
color: var(--color-neutral-white);
padding: var(--spacing-small);
transition:
border var(--transition-duration),
box-shadow var(--transition-duration),
opacity var(--transition-duration);
width: var(--spacing-medium);
will-change: border, box-shadow;

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

Expand Down Expand Up @@ -64,4 +62,4 @@
height: var(--spacing-giant);
object-fit: contain;
width: var(--spacing-giant);
}
}
23 changes: 15 additions & 8 deletions packages/core/src/components/carousel/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
Prop,
h,
} from '@stencil/core'
import 'swiper/swiper-element-bundle.js'
import { register } from 'swiper/element/bundle'
import { AutoplayOptions, PaginationOptions, Swiper } from 'swiper/types'
register()

import { renderThumbs } from './utils/render-thumbs'

Expand All @@ -32,6 +33,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 All @@ -57,12 +60,8 @@ export class AtomCarousel {
thumbnailImages?: string = ''
@Prop({ mutable: true })
videoIcons?: boolean = false

// If you need more info please read the ADR 0012 at Caveat sections
private injectStyles = [
'.swiper-button-disabled { opacity: 0 !important}',
'.swiper-pagination-custom { display: flex; justify-content: center; column-gap: var(--spacing-base); } ',
]
@Prop({ mutable: true })
navigationButtonSize?: 'medium' | 'xxlarge' = 'medium'

componentDidLoad() {
this.swiperEl = this.host.querySelector('swiper-container')
Expand Down Expand Up @@ -111,6 +110,13 @@ export class AtomCarousel {
Object.assign(this.swiperEl, params)
}
render() {
const injectStyles = [
'.swiper-button-disabled { opacity: 0 !important}',
'.swiper-pagination-custom { display: flex; justify-content: center; column-gap: var(--spacing-base); } ',
`.swiper-button-next { width: var(--spacing-${this.navigationButtonSize}); height: var(--spacing-${this.navigationButtonSize}); }`,
`.swiper-button-prev { width: var(--spacing-${this.navigationButtonSize}); height: var(--spacing-${this.navigationButtonSize}); }`,
]

return (
<Host>
<swiper-container
Expand All @@ -124,9 +130,10 @@ export class AtomCarousel {
free-mode={this.freeMode}
autoplay={this.autoplay}
autoplay-delay={this.autoplayDelay}
injectStyles={this.injectStyles}
injectStyles={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 @@ -37,23 +37,32 @@ const createComponent = (args, itemClass: string) => {
: ''
}


${
args.navigationButtonSize !== undefined
? `navigationButtonSize="${args.navigationButtonSize}"`
: ''
}
${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 +86,9 @@ export const Default: StoryObj = {
createComponent(
{
pagination: true,
slidesPerView: 3,
spaceBetween: 40,
paginationClickable: true,
centeredSlides: true,
},
'item-default'
),
Expand Down Expand Up @@ -115,3 +124,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