Skip to content

Instantly share code, notes, and snippets.

@VinSpee
Created October 9, 2017 16:22
Show Gist options
  • Save VinSpee/090fa35bf875804a9e932394ac6e0001 to your computer and use it in GitHub Desktop.
Save VinSpee/090fa35bf875804a9e932394ac6e0001 to your computer and use it in GitHub Desktop.
Flywheel: A react carousel.
export default MyCarousel = ({ myItems }) => (
<Flywheel>
{
({
activeItemIndex,
getNextButtonProps,
getPrevButtonProps,
}) => (
<div>
<button
{...getPrevButtonProps({
onClick: () => console.log('prev clicked'),
})}
>
Prev
</button>
{myItems.map({ id, imageURL }, index) => (
<FlywheelItem key={id}>
{
({
getItemProps,
}) => (
<div
{...getItemProps({
key: id,
style: {
borderTop: `1px solid ${index === activeItemIndex ? 'red'
: 'transparent'},
},
onClick: () => console.log(`${id} clicked`)
})}
>
<img src={imageURL} />
</div>
)
}
</FlywheelItem>
)}
<button
{...getNextButtonProps({
onClick: () => console.log('next clicked'),
})}
>
Next
</button>
</div>
)
}
</Flywheel>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment