mask-input
diceui-radix/mask-inputFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/mask-input.jsonSource
1"use client";23import { Slot as SlotPrimitive } from "radix-ui";4import * as React from "react";5import { useComposedRefs } from "@/lib/compose-refs";6import { cn } from "@/lib/utils";78const PAST_YEARS_LIMIT = 120;9const FUTURE_YEARS_LIMIT = 10;10const DEFAULT_CURRENCY = "USD";11const DEFAULT_LOCALE = "en-US";1213const NUMERIC_MASK_PATTERNS =14 /^(phone|zipCode|zipCodeExtended|ssn|ein|time|date|creditCard|creditCardExpiry)$/;15const CURRENCY_PERCENTAGE_SYMBOLS = /[€$%]/;1617interface CurrencySymbols {18 currency: string;19 decimal: string;20 group: string;21}2223const formattersCache = new Map<string, Intl.NumberFormat>();24const currencyAtEndCache = new Map<string, boolean>();25const currencySymbolsCache = new Map<string, CurrencySymbols>();26const daysInMonthCache = [27 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,28] as const;2930const REGEX_CACHE = {31 digitsOnly: /^\d+$/,32 nonDigits: /\D/g,33 nonAlphaNumeric: /[^A-Z0-9]/gi,34 nonNumericDot: /[^0-9.]/g,35 nonCurrencyChars: /[^\d.,]/g,36 hashPattern: /#/g,37 currencyAtEnd: /\d\s*[^\d\s]+$/,38 percentageChars: /[^\d.]/g,39 phone: /^\d{10}$/,40 ssn: /^\d{9}$/,41 zipCode: /^\d{5}$/,42 zipCodeExtended: /^\d{9}$/,43 isbn: /^\d{13}$/,44 ein: /^\d{9}$/,45 time: /^\d{4}$/,46 creditCard: /^\d{13,19}$/,47 creditCardExpiry: /^\d{4}$/,48 licensePlate: /^[A-Z0-9]{6}$/,49 macAddress: /^[A-F0-9]{12}$/,50 currencyValidation: /^\d+(\.\d{1,2})?$/,51 ipv4Segment: /^\d{1,3}$/,52} as const;5354function getCachedFormatter(55 locale: string | undefined,56 opts: Intl.NumberFormatOptions,57): Intl.NumberFormat {58 const {59 currency,60 minimumFractionDigits = 0,61 maximumFractionDigits = 2,62 } = opts;6364 const key = `${locale}|${currency}|${minimumFractionDigits}|${maximumFractionDigits}`;6566 if (!formattersCache.has(key)) {67 try {68 formattersCache.set(69 key,70 new Intl.NumberFormat(locale, {71 style: "currency",72 currency,73 ...opts,74 }),75 );76 } catch {77 formattersCache.set(78 key,79 new Intl.NumberFormat(DEFAULT_LOCALE, {80 style: "currency",81 currency: DEFAULT_CURRENCY,82 ...opts,83 }),84 );85 }86 }8788 const formatter = formattersCache.get(key);89 if (!formatter) {90 throw new Error(`Failed to create formatter for ${key}`);91 }92 return formatter;93}9495function getCachedCurrencySymbols(opts: TransformOptions): CurrencySymbols {96 const { locale, currency } = opts;9798 const key = `${locale}|${currency}`;99// … truncated
What it pulls in
npm packages
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
