Skip to content

Commit e4868b7

Browse files
committed
bug fixes
1 parent 59aa3df commit e4868b7

5 files changed

Lines changed: 21 additions & 23 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "react-card-stack-carousel",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "A tiny configurable carousel component for React",
5-
"main": "dist/index.js",
5+
"main": "index.js",
66
"scripts": {
77
"dev": "vite ./playground",
88
"build": "vite build",

playground/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from "path";
21
// vite.config.js
2+
import path from "path";
33
import { defineConfig } from "vite";
44
import react from "@vitejs/plugin-react";
55

src/StackedCarousel.jsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function StackedCarousel(props) {
2121
verticalOffset,
2222
} = props;
2323

24+
const totalCount = React.Children.count(children);
25+
26+
const rootHeight = useRootHeight(height);
2427
const { handleNext, handlePrevious, getState } = useCardStackCarousel({
2528
autoplay,
2629
autoplayInterval,
@@ -29,11 +32,10 @@ export function StackedCarousel(props) {
2932
onPrevious,
3033
scaleFactor,
3134
startIndex,
32-
totalCount: children.length,
35+
totalCount,
3336
transitionDuration,
3437
verticalOffset,
3538
});
36-
const rootHeight = useRootHeight(height);
3739

3840
const renderCards = () => {
3941
return React.Children.map(children, (child, index) => {
@@ -60,11 +62,13 @@ export function StackedCarousel(props) {
6062
<section className={className} style={inlineStyle}>
6163
{renderCards()}
6264

63-
<Navigation
64-
styleOverrides={styleOverrides}
65-
onNext={handleNext}
66-
onPrevious={handlePrevious}
67-
/>
65+
{totalCount > 1 && (
66+
<Navigation
67+
styleOverrides={styleOverrides}
68+
onNext={handleNext}
69+
onPrevious={handlePrevious}
70+
/>
71+
)}
6872
</section>
6973
);
7074
}

src/useCardStackCarousel.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export const useCardStackCarousel = (config) => {
3030
} = config;
3131

3232
const [activeIndex, setActiveIndex] = useState(startIndex);
33-
const [transitionState, setTransitionState] = useState(
34-
TRANSITION_STATE.Idle
35-
);
33+
const [transitionState, setTransitionState] = useState(TRANSITION_STATE.Idle);
3634
const direction = useRef(DIRECTION.None);
3735

3836
const validateParams = () => {
@@ -160,7 +158,7 @@ export const useCardStackCarousel = (config) => {
160158

161159
useEffect(() => {
162160
validateParams();
163-
}, []);
161+
}, [totalCount, startIndex]);
164162

165163
useAutoPlay(config, handleNext);
166164

@@ -173,10 +171,8 @@ export const useCardStackCarousel = (config) => {
173171
};
174172

175173
const useAutoPlay = (config, actionCallback) => {
176-
const {
177-
autoplay = DEFAULT_AUTOPLAY,
178-
autoplayInterval = DEFAULT_AUTOPLAY_INTERVAL,
179-
} = config;
174+
const { autoplay = DEFAULT_AUTOPLAY, autoplayInterval = DEFAULT_AUTOPLAY_INTERVAL } =
175+
config;
180176
const autoplayTimer = useRef(null);
181177

182178
useEffect(() => {

types/index.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
declare module "react-card-stack-carousel" {
2-
import { ReactNode } from "react";
2+
import { ReactNode, FC } from "react";
33

44
type StyleKeys = "Root" | "CarouselItem" | "Navigation" | "NavIcon";
5-
type StyleOverrides = Record<StyleKeys, React.CSSProperties | string>;
5+
type StyleOverrides = Partial<Record<StyleKeys, React.CSSProperties | string>>;
66

77
export interface StackedCarouselProps {
88
height: number | string;
99
children: ReactNode;
1010
autoplay?: boolean;
1111
autoplayInterval?: number;
12-
containerClassName?: string;
1312
easingFunction?: string;
14-
navContainerClassName?: string;
1513
onNext?: () => void;
1614
onPrevious?: () => void;
1715
scaleFactor?: number;
@@ -21,5 +19,5 @@ declare module "react-card-stack-carousel" {
2119
verticalOffset?: number;
2220
}
2321

24-
export const StackedCarousel: (props: StackedCarouselProps) => ReactNode;
22+
export const StackedCarousel: FC<StackedCarouselProps>;
2523
}

0 commit comments

Comments
 (0)