Skip to content

Commit

Permalink
Merge pull request #46 from vadymshymko/feature/add-persistentChangeC…
Browse files Browse the repository at this point in the history
…allbacks-prop

Feature/add persistent change callbacks prop
  • Loading branch information
vadymshymko authored Jun 8, 2022
2 parents aebbd33 + 607094f commit 59199c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export default ReactSimplyCarouselExample;
| **disableNavIfEdgeVisible** (disabled if `infinite` prop enabled) | boolean | `true` | Disable carousel forward nav if last slide is visible / Disable carousel backward nav if first slide is visible |
| **disableNavIfEdgeActive** | boolean | `true` | Disable carousel forward nav if activeSlideIndex === lastSlideIndex / Disable carousel backward nav if activeSlideIndex === 0 |
| **dotsNav** (experimental) | object | `{}` | Props for carousel dots. Includes `show` (boolean) property for toggle dots nav visibility, `containerProps` (DOM Props for dots nav wrapper div) property, `itemBtnProps` (DOM props for all dots nav buttons) property and `activeItemBtnProps` (DOM props for active dots nav button) |
| **persistentChangeCallbacks** | boolean | `false` | Enable call `onRequestChange` prop even if activeSlideIndex equals new value |

## Demo

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-simply-carousel",
"version": "8.0.0",
"version": "8.1.0",
"description": "A simple, lightweight, fully controlled isomorphic (with SSR support) React.js carousel component. Touch enabled and responsive. With support for autoplay and infinity options. Fully customizable",
"files": [
"dist/"
Expand Down
8 changes: 7 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ReactSimplyCarouselStaticProps = {
disableNavIfEdgeVisible?: boolean;
disableNavIfEdgeActive?: boolean;
dotsNav?: DotsNav;
persistentChangeCallbacks?: boolean;
};

type ReactSimplyCarouselResponsiveProps = (Omit<
Expand Down Expand Up @@ -154,6 +155,7 @@ function ReactSimplyCarousel({
disableNavIfEdgeVisible = true,
disableNavIfEdgeActive = true,
dotsNav = {},
persistentChangeCallbacks = false,
} = windowWidth
? {
...propsByWindowWidth,
Expand Down Expand Up @@ -353,7 +355,10 @@ function ReactSimplyCarousel({
itemsListRef.current!.style.transition =
speed || delay ? `transform ${speed}ms ${easing} ${delay}ms` : 'none';

if (newActiveSlideIndex !== activeSlideIndex) {
if (
newActiveSlideIndex !== activeSlideIndex ||
persistentChangeCallbacks
) {
clearTimeout(autoplayTimerRef.current);
onRequestChange(newActiveSlideIndex);
} else {
Expand All @@ -368,6 +373,7 @@ function ReactSimplyCarousel({
}
},
[
persistentChangeCallbacks,
activeSlideIndex,
offsetCorrectionForCenterMode,
delay,
Expand Down

0 comments on commit 59199c0

Please sign in to comment.