import React from "react"; import { Slot } from "radix-ui"; import { Button } from "../button"; import { Icon } from "../icon"; import { ArrowRight } from "@washingtonpost/wpds-assets"; import { CarouselContext } from "./CarouselRoot"; const NAME = "CarouselNextButton"; export type CarouselNextButtonProps = { asChild?: boolean; } & React.ComponentPropsWithRef; export const CarouselNextButton = React.forwardRef< HTMLButtonElement, CarouselNextButtonProps >( ( { css, onClick, density = "compact", icon = "center", variant = "primary", asChild, ...props }, ref ) => { const { page, setPage, totalPages } = React.useContext(CarouselContext); const handleClick = (event: React.MouseEvent) => { if (totalPages && page < totalPages - 1) { setPage(page + 1); onClick && onClick(event); } }; let isDisabled; if (totalPages) { isDisabled = page === totalPages - 1; } return ( <> {asChild ? ( ) : ( )} ); } ); CarouselNextButton.displayName = NAME;