2.1.10 • Published 3 years ago

enhanced-material-ui-carousel v2.1.10

Weekly downloads
24
License
MIT
Repository
github
Last release
3 years ago

React Material UI Carousel

Description

A Generic, extendible Carousel UI component for React using Material UI
It switches between given children using a smooth animation.
Provides next and previous buttons. Also provides interactible bullet indicators.

Live Demo

Take a look at this interactible Live Demo

Installation

npm install react-material-ui-carousel --save

Note:

You will need to have material-ui installed, in order to use this library/component

npm install @material-ui/core
npm install @material-ui/icons

Usage Example

import React from 'react';
import Carousel from 'react-material-ui-carousel'
import {Paper} from '@material-ui/core'

function Example(props)
{
    var items = [
        {
            name: "Random Name #1",
            description: "Probably the most random thing you have ever seen!"
        },
        {
            name: "Random Name #2",
            description: "Hello World!"
        }
    ]

    return (
        <Carousel>
            {
                items.map( (item, i) => <Item key={i} item={item} /> )
            }
        </Carousel>
    )
}

function Item(props)
{
    return (
        <Paper>
            <h2>{props.item.name}</h2>
            <p>{props.item.description}</p>

            <Button className="CheckButton">
                Check it out!
            </Button>
        </Paper>
    )
}

Next & Prev Usage

    <Carousel
        next={ (next, active) => console.log(`we left ${active}, and are now at ${next}`); }
        prev={ (prev, active) => console.log(`we left ${active}, and are now at ${prev}`); }
    >
        {...}
    </Carousel>

    // OR

    <Carousel
        next={ () => {/* Do stuff */} }
        prev={ () => {/* Do other stuff */} }
    >
        {...}
    </Carousel>

    // And so on...

Note: onChange works in a similar fashion. See Props below.

Props

Prop nameTypeDefaultDescription
classNamestring""Defines custom class name(s), that will be added to Carousel element
autoPlaybooleantrueDefines if the component will auto scroll between children
intervalnumber4000Defines the interval in ms between active child changes (autoPlay)
indicatorsbooleantrueDefines the existence of bullet indicators
animation"fade" \| "slide""fade"Defines the animation style of the Carousel
timeoutnumber \| {appear? number, enter?: number, exit?: number}500Defines the duration of the animation
navButtonsAlwaysVisiblebooleanfalseDefines if the next/previous buttons will always be visible or not
navButtonsAlwaysInvisiblebooleanfalseDefines if the next/previous buttons will always be invisible or not
fullHeightHoverbooleantrueDefines if the the next/previous button wrappers will cover the full height of the Item element and show buttons on full height hover
indexnumber0Defines which child (assuming there are more than 1 children) will be displayed. Next and Previous Buttons as well as Indicators will work normally after the first render. When this prop is updated the carousel will display the chosen child. Use this prop to programmatically set the active child. If (index > children.length) then if (strictIndexing) index = last element. index
strictIndexingbooleantrueDefines whether index can be bigger than children length
indicatorProps{className: string, style: React.CSSProperties}undefinedUsed to customize the non-active indicators
activeIndicatorProps{className: string, style: React.CSSProperties}undefinedUsed to customize the active indicator
indicatorContainerProps{className: string, style: React.CSSProperties}undefinedUsed to customize the indicators container/wrapper
onChange(index: number, active: number) => void (internally: Function)() => {}Function that is called after internal setActive() method. The setActive() method is called when the next and previous buttons are pressed, when an indicator is pressed, or when the index prop changes. First argument is the child we are going to display, while the second argument is the child that was previously displayed. Will be called in conjunction with and after next and prev props if defined. It will not get called in first render, except if changeOnFirstRender is defined
changeOnFirstRenderbooleanfalseDefines if onChange prop will be called when the carousel renders for the first time. In componentDidMount
next(next: number, active: number) => void (internally: Function)() => {}Function that is called after internal next() method. First argument is the child we are going to display, while the second argument is the child that was previously displayed
prev(prev: number, active: number) => void (internally: Function)() => {}Function that is called after internal prev() method. First argument is the child we are going to display, while the second argument is the child that was previously displayed

License

The MIT License.

Author

Learus

2.1.10

3 years ago

2.1.9

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago