Skip to main content

Carousel

A circular conveyor of information, cycling between cards.

Submit feedback
github

** Disclaimer: ** On a mobile device the carousel has the full functionality of scrolling, pagination, and snapping to a slide. While on the web, the carousel is restricted to scrolling only by dragging the bottom scroll bar or using the pagination buttons.

import { Carousel } from '@uhg-abyss/mobile';

Heading

Use the heading prop to add a heading above the carousel.

Action Text

Use the actionText prop to add an action button next to the heading.

Programmatic Slide Navigation

Carousel exposes methods and state to programmatically control the current slide via a ref.

  • goToSlide(slide: number): Function to programmatically change to a specific slide
  • goToPrevSlide(): Function to programmatically go to the previous slide
  • goToNextSlide(): Function to programmatically go to the next slide
  • activeSlide: The currently active slide

Disable Scrolling

Use the disableScrolling prop to prevent the carousel from scrolling.

Disable Pagination

Use the disablePagination prop to remove the pagination bullets below the carousel.

Slide Gap

Use the slideGap prop to add a gap between each slide. The default value is $carousel.space.slide-gap || 8.

Snap Percentage

Use the snapPercentage prop to set minimum percent in either direction a carousel should be shifted to snap to another carousel. The default value is 30.

In the examples below, there is a green line denoting how much the carousel would need to scroll before snapping to the next slide.

Data

Carousel is made to be used in conjunction with slides, therefore the data prop is required. This prop takes in an array that contains the information to be rendered on each slide.

const slides = [
{
imageBackgroundColor: '$semantic.color.surface.container.secondary',
eyebrow: 'New Service',
heading: 'Virtual Care',
paragraph:
'Get medical advice from the comfort of your home. Discover our new virtual care services.',
},
{
imageBackgroundColor: '$semantic.color.surface.container.emphasis.3',
eyebrow: 'Mental health',
paragraph:
'Learn more about available mental health benefits and resources available to you',
heading: 'Explore Coverage & Support',
},
{
imageBackgroundColor: '$semantic.color.surface.container.emphasis.4',
eyebrow: 'Update',
heading: 'COVID-19 Vaccine Information',
paragraph:
'Stay informed about the COVID-19 vaccine. Learn about eligibility, safety, and how to get your shot.',
},
{
imageBackgroundColor: '$semantic.color.surface.container.emphasis.2',
eyebrow: 'Event',
heading: 'United Healthcare Community Health Fair',
paragraph:
'Join us for a day of free health screenings and wellness activities. Bring your family and friends!',
},
{
imageBackgroundColor: '$semantic.color.surface.container.emphasis.1',
eyebrow: 'In-App Care',
heading: 'Real-time, online visits',
paragraph: 'Connect with a designated provider using your smartphone.',
},
];

Render Slide

Use the renderSlide prop to render the data passed into Carousel. This function takes in the slide object and index number.

renderSlide={{({ slide, index }) => {
return (
<Carousel.Card
paragraph={slide.paragraph}
eyebrow={slide.eyebrow}
heading={slide.heading}
variant={'vertical-small'}
imageBackgroundColor="$semantic.color.surface.container.secondary"
onPress={() => {
console.log(`card ${index + 1} pressed`);
}}
/>);
}}}

Use the Carousel.Card component to display content on a card with pre-defined styled specific for use within a carousel. It does not allow for multiple variants within the same carousel. Please follow design guidelines when implementing.

Use the Carousel.Nib component to display nibs within a carousel. Nibs are small, pill-shaped buttons that can be used for navigation or to represent different categories or options. They are typically used in a horizontal layout and can be scrolled through if there are more nibs than can fit on the screen at once.

Carousel Props

Prop NameTypeDefaultDescription
actionTextstring-Text for the action button
dataany[]-Each individual slide data stored in an array
disablePaginationbooleanfalseFlag to remove pagination bullets
disableScrollingbooleanfalseFlag to disable carousel scrolling
onActionPressfunction-Callback fired when the action button is pressed
renderSlidefunction-Callback fired on slide render
slideGapnumber$carousel.space.slide-gapThe gap between each slide
snapPercentagenumber30The minimum percent in either direction a carousel should be shifted to snap to another slide

Carousel Classes

Class NameDescription
abyss-carousel-bulletsCarousel bullets component
abyss-carousel-bullets-containerCarousel bullets container
abyss-carousel-rootCarousel root element
abyss-carousel-slideCarousel slide

Carousel.Card Props

Prop NameTypeDefaultDescription
background"white" | "peach" | "mint" | "aqua" | "sky-blue"whiteThe background color of the carousel card
eyebrowstring-The eyebrow text of the carousel card
headingstring-The heading text of the carousel card
imageReact.ReactNode-The image of the carousel card
imageBackgroundColorstring-The background color of the image container
isExternalboolean-Displays an external icon after the heading
paragraphstring-The paragraph text of the carousel card
variant"horizontal" | "vertical-lg" | "vertical-sm" | "branded"horizontalThe carousel card variant

Carousel.Card Classes

Class NameDescription
abyss-carousel-card-contentCarousel card content section
abyss-carousel-card-eyebrowCarousel card eyebrow text
abyss-carousel-card-headingCarousel card heading text
abyss-carousel-card-image-containerCarousel card image container
abyss-carousel-card-paragraphCarousel card paragraph text
abyss-carousel-card-rootCarousel card root element

Carousel.Nib Props

Prop NameTypeDefaultDescription
childrennode-The contents of the Nib Group component
size'small' | 'medium' | 'large'smallThe size of the nibs. Nibs in a list should use small, while nibs in a carousel can use medium or large
type'list' | 'carousel'listThe type of Nib group. This can either be a list or carousel

Carousel.Nib Classes

Class NameDescription
abyss-nib-labelThe label element
abyss-nib-rootThe root element

Pagination

When a screen reader is enabled, the pagination should not be shown. Be sure to set disablePagination prop to true.

Carousel Tokens

Token NameValue
carousel.color.text.heading
#002677
carousel.color.icon.one-tap-alt
#4B4D4F
carousel.sizing.all.icon.one-tap-alt
24
carousel.sizing.all.icon.external
16
carousel.spacing.gap.horizontal.cards-container
8
carousel.spacing.gap.horizontal.heading-container
16
carousel.spacing.gap.vertical.container
8
carousel.spacing.padding.top.heading-container
24
Table of Contents