npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ncremental/carousel

v12.5.13

Published

An Angular carousel component with SSR support by Ncremental.

Downloads

798

Readme

Angular Carousel Component

An Angular carousel component with SSR support by Ncremental.

Installation

Simply run:

npm i @ncremental/carousel

Usage

First, add the component to your module:

import { NcrCarouselModule } from '@ncremental/carousel';

@NgModule({
  imports: [NcrCarouselModule]
})
export class MyModule {}

Then, use it in your component's HTML:

<ncr-carousel
  class="carousel carousel-xs-1 carousel-md-4 carousel-lg-4"
  [items]="items$ | async"
  [template]="carouselItem"
  [configuration]="{ autoplayDelay: 1000, visibleCount: { xs: 1, sm: 1, md: 4, lg: 4, xl: 4 } }"
>
</ncr-carousel>

<ng-template #carouselItem let-item$="item">
  <!-- Your slide template -->
</ng-template>

Configuration

The following properties can be set on the configuration object:

interface CarouselConfig {
  visibleCount: {
    xs: number;
    sm?: number;
    md?: number;
    lg?: number;
    xl?: number;
    xxl?: number;
  };
  touchEnabled?: boolean;
  touchEnabledDesktop?: boolean;
  autoplayDelay?: number;
  controls?: boolean;
  indicators?: boolean;
  moveBy?: number;
  loop?: boolean;
  lazyLoadIncrement?: number;
  ssrItemsToLoad?: number;
  dragThreshold?: number;
  templates?: {
    prevControl?: TemplateRef<any>;
    nextControl?: TemplateRef<any>;
    indicators?: TemplateRef<any>;
  };
  labels?: {
    prevControl?: string;
    nextControl?: string;
    indicators?: string;
  };
}

Linking Carousels

You can easily link different carousels with each other using our public observables and methods.

Thumbnails

Let's say you want a second carousel which shows thumbnails of your slides. You can simply create an observable which keeps track of the active UID:

activeUID$ = new BehaviorSubject(0);

Then, you need to sync the two carousels:

function syncCarousels(mainCarousel: NcrCarouselComponent, thumbCarousel: NcrCarouselComponent) {
  // Update UID on main carousel navigation
  mainCarousel.currentPage$.pipe(takeUntil(this.destroyed$)).subscribe((page) => this.activeUID$.next(page));
  // Sync carousels when UID changes
  this.activeUID$.pipe(takeUntil(this.destroyed$)).subscribe((page) => {
    mainCarousel.activePage = page;
    thumbCarousel.activePage = page;
  });
}

In your template you can add a click event which jumps to a specific slide when it is clicked:

<ng-template #thumbItem let-item="item" let-uid="uid">
  <a
    tabindex="0"
    (click)="activeUID$.next(uid)"
    [class]="activeUID$.getValue() === uid ? 'active-slide' : ''"
  >
    <img [src]="$any(item).img" width="100" loading="lazy" />
  </a>
</ng-template>

Autoplay Pause

You can control the autoplay functionality of the carousel using the autoplayPause input and listen for changes with the autoplayPauseChange output.

Using autoplayPause input

To pause the autoplay, set the autoplayPause input to true. To resume, set it to false:

<ncr-carousel
  class="carousel carousel-xs-1 carousel-md-4 carousel-lg-4"
  [items]="items$ | async"
  [template]="carouselItem"
  [configuration]="{ autoplayDelay: 1000, visibleCount: { xs: 1, sm: 1, md: 4, lg: 4, xl: 4 } }"
  [autoplayPause]="isAutoplayPaused"
>
</ncr-carousel>

In your component class:

import { Component } from '@angular/core';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {
  isAutoplayPaused: boolean = false;

  // Your button onClick
  toggleAutoplay() {
    this.isAutoplayPaused = !this.isAutoplayPaused;
  }
}

Listening to Autoplay Changes

If you want to listen to changes on autoplay that come from the carousel, just listen for the (autoplayPauseChange) output value emitted and set your current value to true/false:

<ncr-carousel
  class="carousel carousel-xs-1 carousel-md-4 carousel-lg-4"
  [items]="items$ | async"
  [template]="carouselItem"
  [configuration]="{ autoplayDelay: 1000, visibleCount: { xs: 1, sm: 1, md: 4, lg: 4, xl: 4 } }"
  [autoplayPause]="isPaused"
  (autoplayPauseChange)="handleAutoplayPause($event)"
>
</ncr-carousel>

In your component class:

import { Component } from '@angular/core';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {
  isAutoplayPaused: boolean = false;

  // Your button onClick
  toggleAutoplay() {
    this.isAutoplayPaused = !this.isAutoplayPaused;
  }
  
  handleAutoplayPause(state: boolean) {
    this.isAutoplayPaused = state;
  }
}

Try it locally

If you want to try it locally. Run in spartacus-extensions:

yarn build:carousel

Then in the package.json of the project you want to try the carousel updated :

"@ncremental/carousel": "file:/path/to/spartacus-extensions/dist/ncr-carousel"