Skip to Content
zjkm-ui
Components

Dot Pagination

Dots for carousel pages, the active one stretched.

Props
<DotPagination count={5} index={index} onChange={setIndex} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/dot-pagination.json
import { DotPagination } from "@/components/dot-pagination"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

Dots for the pages of a carousel. The current one stretches into a pill, using a transform, so the row never shifts. Each dot is a button named "Slide 2 of 5".

import { DotPagination } from "@/components/dot-pagination";

export function Carousel({ slides }: { slides: React.ReactNode[] }) {
  const [index, setIndex] = useState(0);
  return (
    <>
      {slides[index]}
      <DotPagination count={slides.length} index={index} onChange={setIndex} />
    </>
  );
}

Props

PropTypeDefaultDescription
countnumberNumber of pages.
indexnumberThe current page, from 0.
onChange(index: number) => voidCalled with the chosen page.
labelstring"Slides"Accessible name; each dot is named after it.
colorstringcurrentColorColour of the current dot.
classNamestringClasses for the nav.

With reduced motion, the current dot changes without stretching.

On this page