Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-react-carousel

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-react-carousel

React resposive carousel component w/ grid layout

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
753
increased by9.29%
Maintainers
1
Weekly downloads
 
Created
Source

React responsive carousel component w/ grid layout
to easily create a carousel like photo gallery, shopping product card or anything you want

Features

  • RWD
  • Multiple items
  • Multiple rows
  • Infinite loop
  • Support any component as a item to put into grid
  • Show/hide dots
  • Show/hide arrow buttons
  • Autoplay
  • Enable/Disable scroll-snap for each item on mobile device
  • Customized layout (cols & rows) for different breakpoint
  • Customized arrow button
  • Customized dots
  • Support SSR

Install

$ npm install better-react-carousel --save

Usage

Just import the Carousel component from better-react-carousel
and put your item into Carousel.Item

import React from 'react'
import Carousel from 'better-react-carousel'

const Gallery = () => {
  return (
    <Carousel cols={2} rows={1} gap={10} loop>
      <Carousel.Item>
        <img width="100%" src="https://picsum.photos/800/600?random=1" />
      </Carousel.Item>
      <Carousel.Item>
        <img width="100%" src="https://picsum.photos/800/600?random=2" />
      </Carousel.Item>
      <Carousel.Item>
        <img width="100%" src="https://picsum.photos/800/600?random=3" />
      </Carousel.Item>
      <Carousel.Item>
        {/* anything you want to show in the grid */}
      </Carousel.Item>
      {/* ... */}
    </Carousel>
  )
}

Props

PropTypeDefaultDescription
colsNumber1Column amount rendered per page
rowsNumber1Row amount rendered per page
gapNumber | String10Margin (grid-gap) for each item/grid in px or %, passed Number will turn to px unit
loopBooleanfalseInfinite loop or not
scrollSnapBooleantruetrue for applying scroll-snap to items on mobile
hideArrowBooleanfalseShow/hide the arrow prev/next buttons
showDotsBooleanfalseShow dots indicate the current page on desktop mode
autoplayNumberAutoplay timeout in ms; undefined for autoplay disabled
dotColorActiveString'#795548'Valid css color value for active dot
dotColorInactiveString'#ccc'Valid css color value for inactive dot
responsiveLayoutArrayCustomized cols & rows on different viewport size
mobileBreakpointNumber767The breakpoint(px) to switch to default mobile layout
arrowLeftElementCustomized left arrow button
arrowRightElementCustomized left arrow button
dotElementCustomized dot component with prop isActive
containerStyleObjectStyle object for carousel container

responsiveLayout

Array of layout settings for each breakbpoint

Setting options
  • breakpoint: Number; Requried; Equals to max-width used in media query, in px unit
  • cols: Number; Column amount in specific breakpoint
  • rows: Number; Row amount in specific breakpoint
  • gap: Number | String; Gap size in specific breakpoint
  • loop: Boolean; Infinite loop in specific breakpoint
  • autoplay: Number; autoplay timeout(ms) in specific breakpoint; undefined for autoplay disabled

e.g.

[
  {
    breakpoint: 800,
    cols: 3,
    rows: 1,
    gap: 10,
    loop: true,
    autoplay: 1000
  }
]

dot

Example
// your custom dot component with prop `isActive`
const MyDot = ({ isActive }) => (
  <span
    style={{
      display: 'inline-block',
      height: isActive ? '8px' : '5px',
      width: isActive ? '8px' : '5px',
      background: '#1890ff'
    }}
  ></span>
)

// set custom dot
<Carousel dot={MyDot} />

Example

Storybook (Don't forget to try on different viewport size)

$ git clone https://github.com/DevPanther/better-react-carousel
$ cd better-react-carousel

$ npm ci
$ npm run storybook

Use case in real world

# clone & install packages
$ npm run dev
# open localhost:8080

LICENSE

MIT

Keywords

FAQs

Package last updated on 28 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc