• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated almost 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React responsive carousel component w/ grid layout

NPM
GitHub license npm version Open Source

React Grid Carousel

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 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

Prop Type Default Description
cols Number 1 Column amount rendered per page
rows Number 1 Row amount rendered per page
gap Number | String 10 Margin (grid-gap) for each item/grid in px or %, passed Number will turn to px unit
loop Boolean false Infinite loop or not
scrollSnap Boolean true true for applying scroll-snap to items on mobile
hideArrow Boolean false Show/hide the arrow prev/next buttons
showDots Boolean false Show dots indicate the current page on desktop mode
autoplay Number Autoplay timeout in ms; undefined for autoplay disabled
dotColorActive String '#795548' Valid css color value for active dot
dotColorInactive String '#ccc' Valid css color value for inactive dot
responsiveLayout Array Customized cols & rows on different viewport size
mobileBreakpoint Number 767 The breakpoint(px) to switch to default mobile layout
arrowLeft Element Customized left arrow button
arrowRight Element Customized left arrow button
dot Element Customized dot component with prop isActive
containerStyle Object Style 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

More Repositories

1

tw-stock-telegram-bot

台股機器人,提供即時個股及大盤報價、走勢、新聞、盤後資料等 Telegram bot to query real-time TW stock quotes, charts, news, and other related information
JavaScript
60
star
2

cakeresume-html-editor

A user friendly HTML editor to be plugged to CakeResume to easily tweak your resume layout
JavaScript
56
star
3

104-ignore-not-interesting

過濾 104人力銀行 搜尋結果中你不感興趣的職缺 | Ignore jobs you are not interested in on 104
JavaScript
32
star
4

github-calendar-graph

Get GitHub contribution calendar graph & data
JavaScript
28
star
5

KeBiau

自己的課表自己排 2.0 - 暨大專屬排課表、換課、課程評價平台
JavaScript
24
star
6

dcard-images

Dcard 圖片瀏覽器 - Dcard gallery to browser all images in both article and comments
JavaScript
15
star
7

github-explorer

Explore all repos in the GitHub world - interview take-home assignment
JavaScript
14
star
8

PokemonMap-for-GoPatrol

A web display for GoPatrol
JavaScript
11
star
9

x3388638.github.io

Personal site
JavaScript
9
star
10

svelte-todo

Simple todo list made by Svelte
HTML
6
star
11

ChuCooBlogg

A blog system (Nodejs, Express, jQuery, Bootstrap 4)
JavaScript
5
star
12

gatsby-blog

Typography driven, feature-rich blogging theme with minimal aesthetics. Includes tags/categories support and extensive features for code blocks such as live preview, line numbers, and line highlighting.
JavaScript
5
star
13

EzCast_web_client

Web client for EzCast (Nodejs real-time chat base on multicast)
JavaScript
4
star
14

YahooAnswersSpamReport

Use Thanos snap to report spam on Yahoo! Answers
JavaScript
4
star
15

LANChat

Ad Hoc Group Communication Based on Multicast in Wireless LAN developed via React Native
JavaScript
4
star
16

CYTau

以此紀念暨大系外套之亂
JavaScript
3
star
17

package-finder

Userscript to find npm package in GitHub
JavaScript
2
star
18

EzCast_web_server

Web server for EzCast
JavaScript
2
star
19

x3388638

2
star
20

jQuery-todo

HTML
2
star
21

moliday-12

moliday#12
HTML
1
star
22

react-amp-test

Test AMP with React
JavaScript
1
star
23

Frontend-basic-examples

HTML
1
star
24

moliday-13

Just for moliday 13
HTML
1
star
25

Redux-TODOList

A simple TODO list with Redux, webpack, jQuery, Bootstrap
JavaScript
1
star
26

react-datepicker-example

React DatePicker example
JavaScript
1
star
27

NCNU-LIB

NCNU-LIB
JavaScript
1
star
28

THSRschedule

THSR schedule
1
star
29

react-search-form-example

react-search-form-example
TypeScript
1
star
30

webpack-react

Test for webpack & react
JavaScript
1
star
31

course

imcourse
HTML
1
star
32

angular-todo-list-example

An Angular todo list
TypeScript
1
star
33

ncnu-pmtl

NCNU PMTL project
HTML
1
star
34

pov

A React (Next.js) app integrated with Contentful (headless CMS) collects car photography and POV driving videos to share the beauty of Taiwan.
TypeScript
1
star