Updated
Scrub Number
NewCustomize
Sensitivity6px
Acceleration1.00
Fine10
Radius16px
Installation
npx shadcn@latest add https://uibrik.com/r/scrub-number.jsonInstall the packages
npm install @number-flow/react @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/scrub-number/scrub-number.tsx"use client"; import NumberFlow from "@number-flow/react"; import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react"; import { animate, motion, useMotionValue, useReducedMotion, useTransform, type MotionStyle } from "motion/react"; import { useEffect, useId, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent } from "react"; import { cn } from "@/lib/utils"; export type ScrubNumberProps = { label: string; /** Controlled value. */ value?: number; /** Value on mount when uncontrolled. */ defaultValue?: number; /** Fires on every step of a drag, every arrow key and every typed commit. */ onChange?: (value: number) => void; /** Fires once when a drag or edit settles. */ onCommit?: (value: number) => void; min?: number; max?: number; /** Smallest change. Also sets how many decimals show. */ step?: number; /** Text after the number, e.g. "px", "%" or "°". */ suffix?: string;
Adds the files to
components/uibrik/scrub-number and installs @number-flow/react, @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/scrub-number.Usage
import { ScrubNumber } from "@/components/uibrik/scrub-number/scrub-number";<ScrubNumber label="Width" sensitivity={6} acceleration={1} fine={10} radius={16} defaultValue={320} min={0} max={1440} step={1} suffix="px" onCommit={(value) => {}} // value={0} // onChange={(value) => {}} // resetValue={0} // disabled={false}/>Props
ScrubNumber- sensitivity
- Type number
- 6
- Pixels of slow drag per step. Higher is slower and more precise.
- acceleration
- Type number
- 1
- How much a fast drag speeds up, so large ranges don't need a long drag. Slow drags stay precise. 0 turns it off.
- fine
- Type number
- 10
- Holding Shift while dragging divides the step by this. Alt with the arrow keys does the same. 1 turns it off.
- radius
- Type number
- 16
- Corner radius of the field.
- labelrequired
- Type string
- –
- Shown on the left; also the input's label.
- value / onChange
- Type number / (value) => void
- –
- Controlled value. onChange fires on every step of a drag.
- defaultValue
- Type number
- 0
- Value on mount when uncontrolled.
- onCommit
- Type (value) => void
- –
- Fires once when a drag, arrow key or typed edit settles.
- min / max
- Type number
- –
- Limits. The ruler ends at them and the marker stretches a little past before springing back.
- resetValue
- Type number
- defaultValue
- Value a double-click or double-tap returns to.
- step
- Type number
- 1
- Smallest change; also sets the decimals shown.
- suffix
- Type string
- –
- Text after the number, e.g. "px", "%" or "°".
- disabled
- Type boolean
- false
- Dims the field and ignores input.
- className
- Type string
- –
- Classes for the field.