0.5.2 • Published 1 year ago

embla-carousel-react-component v0.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Embla Carousel React Component

A lightweight carousel library for React, based on Embla Carousel.

Features

This library helps build carousels with declarative API. Easy to use, yet still powerful when needed.

  • Comparison with Embla Carousel React:

    You need to rely on external CSS to lay out the slide container. It's not optimal in case you want to reuse the carousel somewhere with different slide sizes.

    This library comes with minimal styles needed to layout the grid, giving developers the ability to define the slide sizes in the component itself, while leaving the rest completely unstyled.

  • Comparison with @mantine/carousel:

    @mantine/carousel introduces its own way to define carousel options. In contrast, this library gives you a familiar experience just like working with the base Embla Carousel React.

    The former comes with limited customization on controller components (Prev/Next Buttons or Indicator Dots) as they're tied to the Carousel. This library allows you to fully customize how those components look.

    This library also comes with a thumbs component if you need to build a product gallery for an e-commerce use case.

Installation

npm install embla-carousel-react-component

Basic Usage

import Carousel from 'embla-carousel-react-component';

<Carousel>
  {[...Array(5).keys()].map((n) => (
    <Carousel.Slide key={n}>
      <div>Slide {n + 1}</div>
    </Carousel.Slide>
  ))}
</Carousel>;

View all the examples

Component API

Carousel

PropTypeDefaultDescription
perViewnumber \| "custom"1The number of slides per view. Pass "custom" if you want to customize the slide sizes later.
containerStyleReact.CSSPropertiesCustomize the container's style
gapstring \| number16The spacing between slides. String is interpreted as is. Number is interpreted as pixel unit.
optionsEmblaOptionsTypeSee hereEmbla Carousel's options
pluginsEmblaPluginType[]Embla Carousel's plugins
PrevButton() => JSX.ElementPrevious Button component
NextButton() => JSX.ElementNext Button component
Indicators() => JSX.ElementDot Indicators component
Thumbs() => JSX.ElementThumbs component
thumbsOptionsEmblaOptionsTypeSee hereOptions for Thumbs component
thumbsPluginsEmblaPluginType[]Plugins for Thumbs component
getEmblaApi(embla: EmblaCarouselType) => voidAccess Embla API for advanced use cases

options

The component comes with a few opinionated options to ensure it works properly out of the box.

{
  align: 'start',
  slidesToScroll: 'auto',
  containScroll: 'trimSnaps'
}

You can overwrite this by providing your own styles.

Carousel.Slide

PropTypeDefaultDescription
sizestringThe slide size. To you this option, you need to pass perView="custom" on Carousel component.

Carousel.PrevButton, Carousel.NextButton

PropTypeDefaultDescription
disabledClassNamestring"disabled"ClassName for disabled state

The components also expose a data-disabled attribute that you can use to conditionally apply different styles.

Carousel.Indicators

PropTypeDefaultDescription
selectedClassNamestring"selected"ClassName for selected state
nonSelectedClassNamestringClassName for non-selected state (Tailwind CSS users may need this)

The component also exposes a data-selected attribute that you can use to conditionally apply different styles.

Carousel.Thumbs

PropTypeDefaultDescription
perViewnumber1The number of thumbs per view
gapstring \| number8The spacing between thumbs. String is interpreted as is. Number is interpreted as pixel unit.

thumbsOptions

Default options:

{
  containScroll: 'keepSnaps',
  dragFree: true,
}

Carousel.Thumb

PropTypeDefaultDescription
indexnumberrequiredThe index of thumb item
selectedClassNamestring"selected"ClassName for selected state
nonSelectedClassNamestringClassName for non-selected state (Tailwind CSS users may need this)

The component also exposes a data-selected attribute that you can use to conditionally apply different styles.

Examples

Basic

Plugins

Others

Acknowledgement

  • This library cannot be possible without Embla Carousel React. It really is a lightweight and sleek library for building carousels.
  • This library also takes @mantine/carousel as a reference, especially the idea of exposing emblaApi to the outside.

License

MIT

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago