Carousel

A slideshow component for cycling through elements with support for mouse drag, touch swipe, and automatic playback.

PreviousNext
1
2
3
4
5
import { ChangeDetectionStrategy, Component } from '@angular/core';
 
import { ZardCardComponent } from '../../card';
import { ZardCarouselModule } from '../carousel.module';
 
@Component({
  imports: [ZardCarouselModule, ZardCardComponent],
  template: `
    <div class="mx-auto w-3/4 max-w-md">
      <z-carousel>
        <z-carousel-content>
          @for (slide of slides; track slide) {
            <z-carousel-item>
              <z-card>
                <div class="flex h-[100px] items-center justify-center text-4xl font-semibold md:h-[200px]">
                  {{ slide }}
                </div>
              </z-card>
            </z-carousel-item>
          }
        </z-carousel-content>
      </z-carousel>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoCarouselDefaultComponent {
  protected slides = ['1', '2', '3', '4', '5'];
}
 

Installation

1

Run the CLI

Use the CLI to add the component to your project.

npx @ngzard/ui@latest add carousel
1

Install dependencies

Install the required dependencies for this component.

Loading...
2

Add the component files

Create the component directory structure and add the following files to your project.

Loading...

Examples

default

1
2
3
4
5
import { ChangeDetectionStrategy, Component } from '@angular/core';
 
import { ZardCardComponent } from '../../card';
import { ZardCarouselModule } from '../carousel.module';
 
@Component({
  imports: [ZardCarouselModule, ZardCardComponent],
  template: `
    <div class="mx-auto w-3/4 max-w-md">
      <z-carousel>
        <z-carousel-content>
          @for (slide of slides; track slide) {
            <z-carousel-item>
              <z-card>
                <div class="flex h-[100px] items-center justify-center text-4xl font-semibold md:h-[200px]">
                  {{ slide }}
                </div>
              </z-card>
            </z-carousel-item>
          }
        </z-carousel-content>
      </z-carousel>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoCarouselDefaultComponent {
  protected slides = ['1', '2', '3', '4', '5'];
}
 

dot controls

1
2
3
4
5
import { ChangeDetectionStrategy, Component } from '@angular/core';
 
import { ZardCardComponent } from '../../card';
import { ZardCarouselModule } from '../carousel.module';
 
@Component({
  imports: [ZardCarouselModule, ZardCardComponent],
  template: `
    <div class="mx-auto w-3/4 max-w-md">
      <z-carousel zControls="dot">
        <z-carousel-content>
          @for (slide of slides; track slide) {
            <z-carousel-item>
              <z-card>
                <div class="flex h-[100px] items-center justify-center text-4xl font-semibold md:h-[200px]">
                  {{ slide }}
                </div>
              </z-card>
            </z-carousel-item>
          }
        </z-carousel-content>
      </z-carousel>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoCarouselDotControlsComponent {
  protected slides = ['1', '2', '3', '4', '5'];
}
 

orientation

1
2
3
4
5
Loading...

sizes

To set the size of the items, you can use the basis utility class on the <z-carousel-item />.

1
2
3
4
5
Loading...

spacing

To set the spacing between the items, we use a pl-[VALUE] utility on the <z-carousel-item /> and a negative -ml-[VALUE] on the <z-carousel-content />.

1
2
3
4
5
6

Content class: -ml-4

Item class: basis-1/3 pl-4

Loading...

api demo

1
2
3
4
5

Current slide: 1 / 0

Scroll progress: 0%

Can scroll prev: No

Can scroll next: No

Slides in view:

Loading...

plugins

1
2
3
4
5

Current slide: 1 / 0

Loading...

API

A carousel component with slide controls and swipe gesture support.

Property Description Type Default
[class] Additional CSS classes ClassValue ''
[zOptions] Embla Carousel configuration options. See the Embla Carousel docs for more information. EmblaOptionsType {loop: false}
[zPlugins] Embla Carousel plugins EmblaPluginType[] []
[zOrientation] Carousel orientation horizontal | vertical horizontal
[zControls] Navigation type buttons 'button' | 'dot' | 'none' button
(zInited) Emits Embla API when carousel is initialized EmblaCarouselType -
(zSelected) Emitted when a slide is selected void -

The content container for the carousel

Property Description Type Default
[class] Additional CSS classes ClassValue ''

An individual carousel item

Property Description Type Default
[class] Additional CSS classes ClassValue ''