4.3.9 • Published 2 years ago

@lendi-ui/carousel v4.3.9

Weekly downloads
204
License
ISC
Repository
-
Last release
2 years ago

@lendi-ui/carousel

A carousel component.

Installation

yarn add @lendi-ui/carousel

Simple Carousel

The simple carousel allows you to get up and running with minimal configuration using our default arrows and default dots.

Usage

import Carousel from '@lendi-ui/carousel';
<Carousel initialIndex={1} increment={2} height="200px" withDots withArrows infinite>
  <div style={{ width: '50%' }}> #1 </div>
  <div style={{ width: '50%' }}> #2 </div>
  <div style={{ width: '50%' }}> #3 </div>
  <div style={{ width: '50%' }}> #4 </div>
  <div style={{ width: '50%' }}> #5 </div>
  <div style={{ width: '50%' }}> #6 </div>
  <div style={{ width: '50%' }}> #7 </div>
</Carousel>

Properties

children: \<React.ReactNode> | The slides

increment: \ = 1 | How many slides to jump per scroll

initialIndex: \ = 0 | The index of inital slide shown by the carousel

height: \ = "500px" | The carousel height

width: \ = "100%" | The carousel width

withArrows: \ = false | Whether to display the default arrows

withDots: \ = false | Whether to display the default dots

swipe: \ = true | Whether to allow moving between slides using swipe gestures

infinite: \ = false | Whether the slides are circular or linear

autoplay: \ = false | Whether slides automatically scroll on an interval

duration: \ = 5000 | If autoplaying, how long is the interval between automatic slides

speed: \ = 300 | How fast the scroll animation is

Compound Carousel

The compound carousel allows you to significantly modify the look and feel of your carousel by customising the children, arrows, and dots.

Usage

import Carousel, { CarouselArrowStyleProps, CarouselDotsStyleProps } from '@lendi/carousel';
<Carousel height="200px">
  <Carousel.PreviousArrow>
    {(disabled) => (
      <span
        style={{
          float: 'left',
          paddingLeft: '40px',
          cursor: disabled ? 'inherit' : 'pointer',
        }}
      >
        {disabled ? '✋' : '👈'}
      </span>
    )}
  </Carousel.PreviousArrow>

  <Carousel.NextArrow>
    {(disabled) => (
      <span
        style={{
          float: 'right',
          paddingRight: '40px',
          cursor: disabled ? 'inherit' : 'pointer',
        }}
      >
        {disabled ? '✋' : '👉'}
      </span>
    )}
  </Carousel.NextArrow>

  <Carousel.Slides>
    <div style={{ width: '40%', background: '#f00', textAlign: 'center', padding: '20px' }}> #1 </div>
    <div style={{ width: '40%', background: '#0f0', textAlign: 'center', padding: '20px' }}> #2 </div>
    <div style={{ width: '40%', background: '#00f', textAlign: 'center', padding: '20px' }}> #3 </div>
    <div style={{ width: '40%', background: '#ff0', textAlign: 'center', padding: '20px' }}> #4 </div>
    <div style={{ width: '40%', background: '#0ff', textAlign: 'center', padding: '20px' }}> #5 </div>
    <div style={{ width: '40%', background: '#f0f', textAlign: 'center', padding: '20px' }}> #6 </div>
    <div style={{ width: '40%', background: '#f90', textAlign: 'center', padding: '20px' }}> #7 </div>
  </Carousel.Slides>

  <div style={{ border: '1px solid black', padding: '10px' }}>
    <span>
      I am a custom component with access to the <code>CarouselContext</code> using <code>useCarouselContext()</code>
    </span>
  </div>

  <Carousel.Dots style={{ display: 'flex' }}>
    {(isActive) => (
      <div
        style={{
          flexGrow: 1,
          padding: '16px',
          cursor: 'pointer',
          textAlign: 'center',
        }}
      >
        {isActive ? '🌝' : '🌚'}
      </div>
    )}
  </Carousel.Dots>
</Carousel>

Compound Components

Slides: \ | Container to hold slides when adding custom components to the Carousel

PreviousArrow: \ | Create a custom Previous Arrow

Arrows: \ | Create a custom Next Arrow

Dots: \ | Create custom Dots

children: \<React.ReactNode> | Any other components you wish to have access to the CarouselContext

Carousel.PreviousArrow & Carousel.NextArrow Properties

children: \<React.ReactNode> | The custom arrow you have created

width: \ = 40 | Change the width of the default arrow

Carousel.Dots Properties

children: \<React.ReactNode> | The custom dot you have created

style: \ | Override the default styles of the Dots

CarouselContext

You can access the CarouselContext from your custom component by running the function useCarouselContext().

isPreviousDisabled: \ | If not infinite, whether one can go to the previous increment

isNextDisabled: \ | If not infinite, whether one can go to the next increment

previousSlide: \<() => void> | Move back one increment

nextSlide: \<() => void> | Move forward one increment

slides: \ | The count of all slides

currentIndex: \ | The current slide index

increment: \ | How many slides to jump per scroll

infinite: \ | Whether the slides are circular or linear

containerBox: \<ClientRect | DOMRect> | The bounding box of the CarouselContainer, useful for calculating arrow locations

4.3.10-beta.0

2 years ago

4.3.10-beta.1

2 years ago

4.3.9

2 years ago

4.3.8

2 years ago

4.3.8-beta.0

2 years ago

4.3.9-beta.0

2 years ago

4.3.6

2 years ago

4.3.7

2 years ago

4.3.8-canary.0

2 years ago

4.3.7-beta.0

2 years ago

4.3.5

2 years ago

4.3.6-beta.0

2 years ago

4.3.5-beta.0

2 years ago

4.3.5-canary.2

2 years ago

5.0.0-beta.2

2 years ago

4.3.5-beta.1

2 years ago

4.3.4-beta.0

2 years ago

4.3.4

2 years ago

4.3.3-beta.1

2 years ago

4.3.3

2 years ago

4.3.3-beta.2

2 years ago

4.3.3-beta.3

2 years ago

4.3.3-beta.0

2 years ago

4.3.2

3 years ago

4.3.2-beta.0

3 years ago

4.3.1

3 years ago

4.3.0

3 years ago

4.2.6

3 years ago

4.2.5

4 years ago

4.2.4

4 years ago

4.2.3

4 years ago

4.2.2

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

5.0.0-beta.0

4 years ago

4.1.2

4 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

4.0.0-alpha

5 years ago

3.0.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago