Carousel
Embla based carousel component
Source
Docs
Package
License
Installation
After installation import package styles at the root of your application:
Usage
@mantine/carousel
package is based on embla carousel,
it supports most of its features:
Options
Size and gap
Set slideSize
and slideGap
on Carousel
component to control size and gap of every slide:
Responsive styles
slideSize
and slideGap
props work the same way as style props,
you can pass an object with values for different breakpoints:
Drag free
dragFree
will disable slides snap points – user will be able to stop dragging at any position:
Vertical orientation
Carousel with orientation="vertical"
requires height
prop to be set:
Controls icons
You can replace default next/previous controls icons with any React nodes:
100% height
Set height="100%"
to make Carousel take 100% height of the container. Note that in this case:
- container element must have
display: flex
styles - carousel root element must have
flex: 1
styles - container element must have fixed height
Get embla instance
You can get embla instance with getEmblaApi
prop.
You will be able enhance carousel with additional logic after that using embla api methods:
Embla plugins
Set plugins
prop to enhance carousel with embla plugins.
Note that plugins are not installed with @mantine/carousel
package and you will need to
install them on your side.
Example with autoplay plugin:
Styles API
Carousel
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Indicator styles
Hide inactive controls
Show controls on hover
Example: Images carousel
Example: Cards carousel
Carousel container animation offset
Embla carousel only reads slides positions and sizes upon initialization. When you are using Carousel component inside animated component you may experience an issue with incorrect slides offset after animation finishes.
Example of incorrect slides offset calculation (scroll though slides):
To solve this issue use useAnimationOffsetEffect
hook exported from @mantine/carousel
package.
It accepts embla instance as first argument and transition duration as second: