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

@steute.dev/react-carousel

v1.1.1

Published

This project aims to provide a React based interface for creating carousels. A primary goal of the project is to have as little opinion on how the carousel should look as possible. The project has two types of ways it can be used. The first way and simple

Downloads

106

Readme

React Carousel

This project aims to provide a React based interface for creating carousels. A primary goal of the project is to have as little opinion on how the carousel should look as possible. The project has two types of ways it can be used. The first way and simplest way, is to use the Carousel component for a caruosel with some pre-built functionality and customization options. The second way to use the library is to use building blocks provided by the library to build your own custom carousel.

Storybook

https://ssteuteville.github.io/react-carousel

Carousel Component

Basic Usage

This example will render a carousel that fills its containers width, and uses default navigation buttons.

import { Carousel } from "@steute.dev/react-carousel";
import { useExampleData } from "./some-file-of-your-own";
import { ExampleItem } from "./some-file-of-your-own";

const MyComponent: FC = () => {
  const exampleData = useExampleData(); // some sort of arrays
  
  return (
    <div style={{ maxWidth: "500px" }}>
      <Carousel>
        {exampleData.map((datum) => (<ExampleItem {...datum} key={datum.key} />))}
      </Carousel>
    </div>
  )
}

AutoPlay

import { Carousel } from "@steute.dev/react-carousel";
import { useExampleData } from "./some-file-of-your-own";
import { ExampleItem } from "./some-file-of-your-own";

const MyComponent: FC = () => {
  const exampleData = useExampleData(); // some sort of arrays
  
  // this example will auto scroll every 3 seconds
  return (
    <div style={{ maxWidth: "500px" }}>
      <Carousel autoPlay autoPlayInterval={3000}>
        {exampleData.map((datum) => (<ExampleItem {...datum} key={datum.key} />))}
      </Carousel>
    </div>
  )
}

Navigation Modes

The Carousel component has a prop called navigationMode. It can be set to a value in the enum CarouselNavigaitonMode.

export enum CarouselNavigationMode {
  never = "never", // never show navigation buttons
  always = "always", // always show navigation buttons
  hover = "hover", // always show navigation buttons on hover
  dynamicHover = "dynamic-hover", // only show navigation buttons on hover if the button will reveal more elements (defualt)
  dynamicAlways = "dynamic-always", // always show navigation buttons (without hover) if the button will reveal more elements
}

Customization

You can use the components and componentProps properties to customize the Carousel component.

import { Carousel } from "@steute.dev/react-carousel";
import { useExampleData } from "./some-file-of-your-own";
import { ExampleItem } from "./some-file-of-your-own";

// the only requirement of the button component is that it has an onClick prop that doesn't require parameters
import { YourButton } from './your-custom-button';

const components = {
  NextButton: YourButton,
  BackButton: YourButton,
}

// these props assume that the `YourButton` component has a `direction` and `color` prop
const componentProps = {
  nextButton: { direction: "right", color: "blue" },
  backButton: { direction: "left", color: "blue" }
}

const MyComponent: FC = () => {
  const exampleData = useExampleData(); // some sort of arrays
  
  return (
    <div style={{ maxWidth: "500px" }}>
      <Carousel components={components} componentProps={componentProps}>
        {exampleData.map((datum) => (<ExampleItem {...datum} key={datum.key} />))}
      </Carousel>
    </div>
  )
}

Building your own compound component

Building blocks

  • CarouselBase - used to render items for the carousel
  • CarouselNavigation - used to add navigation options
  • DefaultNavigationButton - the default button used by Carousel
  • LeftButtonContainer / RightButtonContainer - used to position buttons on top of the carousel
  • CarouselProvider - used to provide context for carousel components
  • useCarousel - creates a context object for CarouselProvider
  • useCarouselContext - gets a carousel object from the CarouselProvider

Usage

More documentation is on the way, for now read the source code for the Carousel component in this project.

Future Plans

  • better docs
  • unit tests
  • feel free to submit requests with issues