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

react-carousel-ts

v3.0.1

Published

A lightweight carousel component for React applications that allows users to cycle through images or content cards.

Downloads

16

Readme

React-carousel- ts

npm bundle size

Ultra-light carousel component for React

About

This carousel provides infinite scrolling without cloning elements, ensuring efficient memory use and performance. It leverages requestAnimationFrame for smooth animations, optimizing performance and reducing CPU load.

Installation

Install the package using npm:

npm i -D react-carousel-ts

Basic Usage

First, import the Carousel component and ensure you include the necessary CSS file for styling:

import { Carousel } from 'react-carousel-ts';
import 'carousel.css';

export const MyComponent = () => {
  const data = [
    <div className="example">1</div>,
    <div className="example">2</div>,
    <div className="example">3</div>,
  ];

  return <Carousel items={data} className="carousel" />;
};

To ensure the carousel displays correctly, it's important to include CSS styles for sizing, borders, and other visual aspects.

.carousel {
  height: 40vh;
  width: 50vw;
  border: 2px solid white;
  border-radius: 14px;
}

[!IMPORTANT]

  • The carousel requires at least three elements to function properly with all transition effects.
  • With only two elements, only the FADE and SCALE transition effects will function correctly.
  • If there is only one or no elements, the carousel will not be displayed.

Infinity scrolling

To enable the infinite scrolling effect in the Carousel component, simply set the infinity property to true.

<Carousel infinity={true} />

This will allow the carousel to loop through items endlessly.

Setting the number of visible elements

To control the number of items displayed at once in the Carousel, use the visibleItemCount property.

<Carousel visibleItemCount={2} />

Customizing Arrows and Dots

You can control their visibility, position, size, and color to match the design of your application.

import { Carousel, CarouselProps, ArrowPosition, DotsTheme } from 'react-carousel-ts';
import 'carousel.css';

export const MyComponent = () => {
  const data = [
    <div className="example">1</div>,
    <div className="example">2</div>,
    <div className="example">3</div>,
  ];

  const props: CarouselProps = {
    className: 'carousel',
    // The size of the arrow in vh/vw units. Default value is 8.
    arrowSize: 8,

    // The color of the arrow. It can be one of the predefined colors or in RGB, RGBA, HEX format.
    arrowColor: 'gray',

    // The position of the arrow. It can be INSIDE, OUTSIDE, or BORDER.
    arrowPosition: ArrowPosition.BORDER,

    // Whether to show dots. Default value is false.
    showDots: true,

    // The theme of the dots. It can be LINE, ROUND, or RECTANGLE.
    dotsTheme: DotsTheme.LINE,

    // The color of the dots. It can be one of the predefined colors or in RGB, RGBA, HEX format.
    dotsColor: 'gray',
  };

  return <Carousel items={data} {...props} />;
};

Transition Effects

If moveEffect is not specified, a simple x-axis rotation is used. This can be changed using the moveEffect prop Currently, MoveEffect has three values: PERPETUAL_AD_SCROLL(Continuous scrolling effect), FADE(fade in and out), SCALE(scale up and down)

import { Carousel, CarouselProps, MoveEffect } from 'react-carousel-ts';
import 'carousel.css';

export const MyComponent = () => {
  const data = [
    <div className="example">1</div>,
    <div className="example">2</div>,
    <div className="example">3</div>,
  ];

  return <Carousel items={data} moveEffect={MoveEffect.SCALE} />;
};

Props

| Name | Type | Default | Description | | :--------------- | :--------------------: | :---------: | :--------------------------------------------------------------------------- | | items | ReactNode[] | [] | Carousel items. | | showDots | boolean | false | Shows navigation dots. | | showArrows | boolean | true | Shows navigation arrows. | | speed | number | 1000 | Transition speed in ms. | | autoplay | boolean | false | Enable automatic cycling. | | infinity | boolean | false | Enables infinite cycling of carousel items. | | autoplaySpeed | number | 4000 | Autoplay interval (ms). | | moveEffect | MoveEffect | undefined | Slide transition effect. (Possible values: FADE, SCALE, PERPETUAL_AD_SCROLL) | | visibleItemCount | number | 1 | Visible items count. | | arrowPosition | ArrowPosition | INSIDE | Arrow position. | | arrowSize | number | 7 | Size of the navigation arrows. | | arrowColor | CarouselControlColor | white | Arrow color. (Possible values: Any valid CSS color value) | | dotsTheme | DotsTheme | RECTANGLE | Shape of the navigation dots. (Possible values: ROUND, RECTANGLE, LINE) | | dotsColor | CarouselControlColor | white | Dots color. (Possible values: Any valid CSS color value) | | className | string | '' | Additional CSS class. |

TODO

  • [ ] Add support for custom arrows and dots
  • [ ] Add support custom transition effects

Contact Information