Skip to content

Instantly share code, notes, and snippets.

@jeiea
Created September 4, 2020 07:44
Show Gist options
  • Save jeiea/f6fef946c3b22a560b7aef24a24b81c2 to your computer and use it in GitHub Desktop.
Save jeiea/f6fef946c3b22a560b7aef24a24b81c2 to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import { useKeenSlider } from 'keen-slider/react';
import 'keen-slider/keen-slider.min.css';
KeenSlider.propTypes = {
children: PropTypes.node,
};
function KeenSlider({ children, ...props }) {
const [sliderRef] = useKeenSlider({
mode: 'free',
});
return (
<div
css={css`
position: relative;
`}
{...props}
>
<div ref={sliderRef}>
{React.Children.map(children, child =>
React.cloneElement(
child,
{ className: `keen-slider__slide ${child.props.className || ''}` },
child.props.children,
),
)}
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment