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

feat(carousel): Improve support for high item counts #10315

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { newE2EPage } from "@stencil/core/testing";
import { accessible, hidden, renders, t9n } from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { CSS, DURATION } from "./resources";
import { breakpoints } from "../../utils/responsive";
import { CSS, DURATION, maxItemBreakpoints } from "./resources";

const slideDurationWaitTimer = DURATION + 250;

Expand Down Expand Up @@ -1055,3 +1056,59 @@ describe("calcite-carousel", () => {
expect(animationEndSpy).toHaveReceivedEventTimes(8);
});
});
describe("handles overflow of pagination items", () => {
it("correctly limits the number of slide pagination items shown when overflowing xxsmall first selected", async () => {
const page = await newE2EPage();
await page.setContent(
html`<calcite-carousel label="carousel" style="width:${breakpoints.width["xxsmall"]}px">
<calcite-carousel-item label="item 1" selected><p>first</p></calcite-carousel-item>
<calcite-carousel-item label="item 2"><p>second</p></calcite-carousel-item>
<calcite-carousel-item label="item 3"><p>third</p></calcite-carousel-item>
<calcite-carousel-item label="item 4"><p>fourth</p></calcite-carousel-item>
<calcite-carousel-item label="item 5"><p>fifth</p></calcite-carousel-item>
<calcite-carousel-item label="item 6"><p>sixth</p></calcite-carousel-item>
<calcite-carousel-item label="item 7"><p>seventh</p></calcite-carousel-item>
<calcite-carousel-item label="item 8"><p>eighth</p></calcite-carousel-item>
</calcite-carousel>`,
);

const items = await page.findAll(`calcite-carousel >>> .${CSS.paginationItemVisible}`);
expect(items).toHaveLength(maxItemBreakpoints["xxsmall"] + 2);
});
it("correctly limits the number of slide pagination items shown when overflowing xsmall middle selected", async () => {
const page = await newE2EPage();
await page.setContent(
html`<calcite-carousel label="carousel" style="width:${breakpoints.width["xsmall"]}px">
<calcite-carousel-item label="item 1"><p>first</p></calcite-carousel-item>
<calcite-carousel-item label="item 2"><p>second</p></calcite-carousel-item>
<calcite-carousel-item label="item 3"><p>third</p></calcite-carousel-item>
<calcite-carousel-item label="item 4" selected><p>fourth</p></calcite-carousel-item>
<calcite-carousel-item label="item 5"><p>fifth</p></calcite-carousel-item>
<calcite-carousel-item label="item 6"><p>sixth</p></calcite-carousel-item>
<calcite-carousel-item label="item 7"><p>seventh</p></calcite-carousel-item>
<calcite-carousel-item label="item 8"><p>eighth</p></calcite-carousel-item>
</calcite-carousel>`,
);

const items = await page.findAll(`calcite-carousel >>> .${CSS.paginationItemVisible}`);
expect(items).toHaveLength(maxItemBreakpoints["xsmall"] + 2);
macandcheese marked this conversation as resolved.
Show resolved Hide resolved
});
it("correctly limits the number of slide pagination items shown when overflowing small last selected", async () => {
const page = await newE2EPage();
await page.setContent(
html`<calcite-carousel label="carousel" style="width:${breakpoints.width["small"]}px">
<calcite-carousel-item label="item 1" selected><p>first</p></calcite-carousel-item>
<calcite-carousel-item label="item 2"><p>second</p></calcite-carousel-item>
<calcite-carousel-item label="item 3"><p>third</p></calcite-carousel-item>
<calcite-carousel-item label="item 4"><p>fourth</p></calcite-carousel-item>
<calcite-carousel-item label="item 5"><p>fifth</p></calcite-carousel-item>
<calcite-carousel-item label="item 6"><p>sixth</p></calcite-carousel-item>
<calcite-carousel-item label="item 7"><p>seventh</p></calcite-carousel-item>
<calcite-carousel-item label="item 8" selected><p>eighth</p></calcite-carousel-item>
</calcite-carousel>`,
);

const items = await page.findAll(`calcite-carousel >>> .${CSS.paginationItemVisible}`);
expect(items).toHaveLength(maxItemBreakpoints["small"] + 2);
});
});
19 changes: 19 additions & 0 deletions packages/calcite-components/src/components/carousel/carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ calcite-carousel-item:not([selected]) {
}
}

.pagination-item--individual {
@apply w-0 p-0 opacity-0 pointer-events-none;
visibility: hidden;
transition:
var(--calcite-animation-timing) ease-in-out inline-size,
var(--calcite-animation-timing) ease-in-out padding,
var(--calcite-internal-animation-timing-slow) ease-in-out opacity;

&.pagination-item--visible {
@apply w-8 opacity-100 pointer-events-auto;
visibility: visible;
}
}

.pagination-item--range-edge calcite-icon {
scale: 0.75;
transition: var(--calcite-internal-animation-timing-slow) ease-in-out scale;
}

.container--overlaid .pagination-item {
background-color: var(--calcite-internal-internal-carousel-item-background-color);
&:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,82 @@ export const simple = (args: CarouselStoryArgs): string =>
</calcite-carousel>
</div>`;

export const simpleManyItems = (args: CarouselStoryArgs): string =>
html` <div style="width:600px;height:400px;">
<calcite-carousel
control-overlay="${args.controlOverlay}"
${boolean("disabled", args.disabled)}
autoplay-duration="${args.autoplayDuration}"
${args.autoplay ? "autoplay" : ""}
macandcheese marked this conversation as resolved.
Show resolved Hide resolved
label="${args.label}"
arrow-type="${args.arrowType}"
>
<calcite-carousel-item label="Carousel Item 1">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-1"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 2">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-2"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 3">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-3"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 4">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-4"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 5">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-5"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 6">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-6"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 7">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-7"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 8">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-8"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
<calcite-carousel-item label="Carousel Item 9">
<calcite-card>
<span slot="title">Some kind of carousel item content</span>
<span slot="subtitle">In this case, in a card</span>
<calcite-icon scale="s" slot="footer-start" icon="number-circle-9"></calcite-icon>
</calcite-card>
</calcite-carousel-item>
</calcite-carousel>
</div>`;

export const carouselAutoplayFullImageWithOverlayAndEdge = (): string =>
html` <div style="width:600px;height:400px;">
<style>
Expand Down Expand Up @@ -173,9 +249,6 @@ export const carouselWithAutoplayNoOverlay = (): string =>
margin: 2rem auto 1rem;
display: block;
}
calcite-carousel {
width: 400px;
}
calcite-carousel-item p {
text-align: center;
margin: 0 auto 1rem;
Expand Down Expand Up @@ -330,9 +403,6 @@ export const darkModeRTL = (): string =>
margin: 2rem auto 1rem;
display: block;
}
calcite-carousel {
width: 400px;
}
calcite-carousel-item p {
text-align: center;
margin: 0 auto 1rem;
Expand Down
Loading
Loading