Socket
Socket
Sign inDemoInstall

react-grid-carousel

Package Overview
Dependencies
88
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-grid-carousel

React resposive carousel component w/ grid layout


Version published
Weekly downloads
2.6K
decreased by-3%
Maintainers
1
Install size
7.74 MB
Created
Weekly downloads
 

Readme

Source

NPM
GitHub license npm version Open Source

React resposive 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 react-grid-carousel --save

Usage

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

import React from 'react'
import Carousel from 'react-grid-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/x3388638/react-grid-carousel
$ cd react-grid-carousel
$ npm ci
$ npm run storybook

Use case in real world

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

or visit https://react-grid-carousel.now.sh/#use-case-in-real-world

LICENSE

MIT

Keywords

FAQs

Last updated on 14 Apr 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc