- Notifications
You must be signed in to change notification settings - Fork3
Fast and tiny React carousel
License
pietile/pietile-carousel
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
React carousel based onFramer Motion without repaints and simple in use.
- Doesn't require to specify items dimensions (pure css solution)
- Relies on translates for movements (zero paints)
- Arbitrary number of visible items
- Сyclicality
Using yarn
yarn add pietile-carousel
or using npm
npm install -S pietile-carousel
Pietile Carouseldepends onFramer Motion which is a peer dependency so be sure that it's installed in you project (if not then install it usingyarn add framer-motion
ornpm install -S framer-motion
)
Every item is wrapped in container where it can layout it's content. The size of container depends on the size of carousel and amount of visible items. You can use any styling system you want to set styles. Get ref and use moveLeft/moveRight/moveTo methods for scroll.
importReactfrom'react';import{PietileCarousel}from'pietile-carousel';functionApp(){constcarouselStyle={width:150,height:100,};constitemStyle={width:'100%',height:'100%',};return(<PietileCarouselstyle={carouselStyle}><divstyle={{ ...itemStyle,backgroundColor:'red'}}/><divstyle={{ ...itemStyle,backgroundColor:'orange'}}/><divstyle={{ ...itemStyle,backgroundColor:'yellow'}}/></PietileCarousel>);}
name | description | type | default |
---|---|---|---|
autoplayInterval | How often autoplay happens (0 to disable) | number | 0 |
children | Components rendered in carousel (required) | Node | - |
className | CSS class | string | - |
count | Amount of visible items | number | 1 |
draggable | Allow drag | boolean | true |
margin | Margin between items | number | 0 |
style | Style object | Object | - |
onChange | Callback when index changes | Function | - |
name | description |
---|---|
slideNext() | Scroll to next slide |
slidePrev() | Scroll to previous slide |
slideTo(index) | Scroll to index |
Carousel protects nesting links (a-tag's) from undesirable behavior (link click is being processed when the user starts dragging and release the mouse outside of the carousel) by callingpreventDefault
for the correspondentclick
event. If you are handling clicks manually you can checkdefaultPrevented when processing your event.
Pietile Carousel is MIT License.
About
Fast and tiny React carousel