Updated
Page Indicator
Customize
Total48
Visible11
Start page6
Drag step14px
Stretch30px
Installation
npx shadcn@latest add https://uibrik.com/r/page-indicator.jsonInstall the packages
npm install @number-flow/react motion react-use-measureSet up squircle corners
Needs
@squircle/core,@squircle/tailwindcssand a few lines of CSS. See squircle setup.Copy the source into your project
components/uibrik/page-indicator/page-indicator.tsx"use client"; import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react"; import NumberFlow from "@number-flow/react"; import useMeasure from "react-use-measure"; import { animate, AnimatePresence, motion, MotionValue, useMotionValue, useTransform } from "motion/react"; function subscribe(onChange: () => void) { const observer = new MutationObserver(onChange); observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"], }); return () => observer.disconnect(); } const getSnapshot = () => document.documentElement.classList.contains("dark"); function useIsDark() { return useSyncExternalStore(subscribe, getSnapshot, () => false); } // Page indicator. Click a dash to jump, grab the wide one and scrub, arrow keys // to step, click the number to type a page.
Adds the files to
components/uibrik/page-indicator and installs @number-flow/react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/page-indicator.Usage
import { PageIndicator } from "@/components/uibrik/page-indicator/page-indicator";<PageIndicator total={48} visible={11} defaultPage={6} dragStep={14} stretch={30} showNumber onChange={(page) => {}}/>Where to use Page Indicator
Onboarding carousels
Dashes you can click, scrub or step through show progress and allow jumping.
Pairs with Progress Dots
Slide and step views
Typing a page number makes long decks easy to navigate.
Mobile pagers
Scrubbing across dashes is fast with one thumb.
Props
PageIndicator- total
- Type number
- 48
- Number of pages.
- visible
- Type number
- 11
- Dashes shown at once.
- defaultPage
- Type number
- 6
- Starting page when uncontrolled.
- dragStep
- Type number
- 14
- Drag distance per page while scrubbing.
- stretch
- Type number
- 30
- How far the grabbed dash stretches past either end.
- showNumber
- Type boolean
- true
- Show the number pill; click it to type a page.
- onChange
- Type (page: number) => void
- –
- Called when the page changes.
- className
- Type string
- –
- Classes for the wrapper.