Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
added readonly to ref type, changed click
 to onClick on carousel item type, and fixed wrong condition
  • Loading branch information
matheusnasser committed May 15, 2023
commit 6b1c13a0e415040f31cb0bcae96b51627520f699
14 changes: 7 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type CarouselItem = {
readonly alt?: string;
readonly content: React.ReactNode;
readonly image: string;
readonly click?: () => void;
readonly onClick?: () => void;
};

export type CarouselProps = {
Expand All @@ -19,13 +19,13 @@ export type CarouselProps = {
readonly ref?: React.ForwardedRef<CarouselRef>;
};

export type CarouselRef = {
readonly next: () => void;
readonly prev: () => void;
export type CarouselRef = Readonly<{
next: () => void;
prev: () => void;
getItems: () => CarouselItem[];
Comment thread
scriptex marked this conversation as resolved.
getSelectedIndex: () => number;
setSelectedIndex: (index: number) => void;
};
}>;

export const Carousel: React.FC<CarouselProps> = React.forwardRef((props: CarouselProps, CarouselRef) => {
const itemWidth = props.itemWidth;
Expand All @@ -39,7 +39,7 @@ export const Carousel: React.FC<CarouselProps> = React.forwardRef((props: Carous
const getSlideStyle = (index: number): React.CSSProperties => {
const style: React.CSSProperties = {};

if (index <= len) {
if (index < len) {
const cellAngle = theta * index;

style.opacity = 1;
Expand Down Expand Up @@ -100,7 +100,7 @@ export const Carousel: React.FC<CarouselProps> = React.forwardRef((props: Carous
{props.items.map((item: CarouselItem, index: number) => (
<div
onClick={() => {
if (item.click) item.click();
if (item.onClick) item.onClick();

if (props.slideOnClick) setSelectedIndex(index);
}}
Expand Down