Updated
Amount Pad
NewCustomize
Decimals2
Max100000
Size64px
Installation
npx shadcn@latest add https://uibrik.com/r/amount-pad.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/amount-pad/amount-pad.tsx"use client"; import { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, } from "motion/react"; import { useEffect, useId, useLayoutEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; export type AmountPadProps = { /** Controlled amount as typed, e.g. "1250.5". Empty string is nothing entered. */ value?: string; /** Amount on mount when uncontrolled. */ defaultValue?: string; /** Fires on every change with the typed string and its number. */ onChange?: (value: string, amount: number) => void; /** Text before the number. */ currency?: string; /** Digits allowed after the decimal point. 0 turns the point off. */ decimals?: number; /** Largest amount. Going past it bounces the extra digit off and shows the limit. */
Adds the files to
components/uibrik/amount-pad and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/amount-pad.Usage
import { AmountPad } from "@/components/uibrik/amount-pad/amount-pad";<AmountPad currency="$" decimals={2} max={100000} size={64} defaultValue="" label="Amount" // value="…" // onChange={(value, amount) => {}} // autoFocus={false}/>Props
AmountPad- currency
- Type string
- "$"
- Text before the number.
- decimals
- Type number
- 2
- Digits allowed after the decimal point. 0 turns the decimal point off.
- max
- Type number
- 100000
- Largest amount. A digit past it bounces off and the limit shows.
- size
- Type number
- 64
- Font size of the number before it shrinks to fit.
- value / onChange
- Type string / (value, amount) => void
- –
- Controlled amount as typed, e.g. "1250.5", with its number.
- defaultValue
- Type string
- ""
- Amount on mount when uncontrolled.
- autoFocus
- Type boolean
- false
- Focus the field on mount.
- label
- Type string
- "Amount"
- Accessible name.
- className
- Type string
- –
- Classes for the wrapper.