Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stories/slideshow.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
scroll-snap-align: start;
}

.snapStop {
scroll-snap-stop: always;
}

.itemText {
position: absolute;
z-index: 100;
Expand Down
19 changes: 19 additions & 0 deletions stories/slideshow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,22 @@ export const ScrollPadding = () => {
/>
);
};

export const SnapEachSlide = () => {
return (
<SlideShow
items={items}
renderItem={({ item, index, isActive, isSnapPoint }) => (
<SlideShowItem
key={index}
isSnapPoint={isSnapPoint}
isActive={isActive}
src={item.src}
title={item.title}
subtitle={item.subtitle}
isSnapStop
/>
)}
/>
);
};
11 changes: 7 additions & 4 deletions stories/slideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ export const SlideShow = <T extends any>({
const handle = (e: KeyboardEvent) => {
switch (e.key) {
case 'ArrowLeft':
next();
prev();
return;
case 'ArrowRight':
prev();
next();
return;
default:
return;
}
};
window.addEventListener('keypress', handle);
window.addEventListener('keydown', handle);
return () => {
window.removeEventListener('keypress', handle);
window.removeEventListener('keydown', handle);
};
}, [next, prev]);

Expand Down Expand Up @@ -118,6 +118,7 @@ export const SlideShow = <T extends any>({

export interface SlideShowItemProps {
readonly isSnapPoint: boolean;
readonly isSnapStop?: boolean;
readonly isActive: boolean;
readonly src: string;
readonly title: string;
Expand All @@ -126,6 +127,7 @@ export interface SlideShowItemProps {

export const SlideShowItem = ({
isSnapPoint,
isSnapStop,
isActive,
src,
title,
Expand All @@ -135,6 +137,7 @@ export const SlideShowItem = ({
<li
className={classNames(styles.item, {
[styles.snapPoint]: isSnapPoint,
[styles.snapStop]: isSnapStop,
[styles.itemActive]: isActive
})}
>
Expand Down