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