<vega-flex use-native-flex="true" gap="size-32" direction="col">
<div class="v-w-1/3 " data-shrink="0">
<vega-flex use-native-flex="true" gap="size-16">
<vega-button-circle
id="prevPage#1"
variant="secondary"
size="default"
icon="arrow-left"
data-shrink="0"
>
</vega-button-circle>
<vega-button-circle
id="nextPage#1"
variant="secondary"
size="default"
icon="arrow-right"
data-shrink="0"
>
</vega-button-circle>
</vega-flex>
</div>
<div class="v-w-2/3" data-shrink="0">
<vega-carousel id="carousel#1" per-page="1" spacing="size-32" show-slider="true">
<vega-card shadow="shadow-card" background-color="bg-primary" padding="size-24"><div class="v-text-primary v-font-p2-short">First page</div></vega-card>
<vega-card shadow="shadow-card" background-color="bg-primary" padding="size-24"><div class="v-text-primary v-font-p2-short">Second page</div></vega-card>
<vega-card shadow="shadow-card" background-color="bg-primary" padding="size-24"><div class="v-text-primary v-font-p2-short">Third page</div></vega-card>
</vega-carousel>
</div>
</vega-flex>
const carousel = document.getElementById('carousel#1');
const prevIcon = document.getElementById('prevPage#1');
const nextIcon = document.getElementById('nextPage#1');
prevIcon.addEventListener('click', function () {
carousel.prevPage();
});
nextIcon.addEventListener('click', function () {
carousel.nextPage();
});
carousel.goToPage(1);
Note: The above example uses Vanilla JS. If you would like to use React, Angular, or Vue, please consult Storybook.
The vega-carousel is a complex component which constructs a movable carousel which enables users to tab between different cards. It serves the functionality of enabling the inclusion of multiple items on a single page using movable cards without requiring a page refresh.
Name | Description | Default |
---|---|---|
per-page | This setting designates the number of cards showing for each page while the screen size is larger than 1024px. Optional |
3 |
spacing | Spacing designates the amount of space between cards. This is set by choosing from a set of preset values: xxs, xs, sm, md, lg, xl, 2xl, 3xl, 4xl. Optional |
md |
show-slider | This is a Boolean attribute which designates whether or not to show the navigational buttons on the bottom of the slider. Optional |
true |
For more details, view in Storybook.
When changing a page on a carousel, the vegaPageUpdate
event will be dispatched.
document.getElementById("carousel#1").addEventListener("vegaPageUpdate", (e) => { // do something })
Carousels can negatively impact accessibility, particularly for those with motor skills issues.
We have applied the following accessibility adaptations to carousels in Vega:
Do
Don't