MaskedInput component is a specialized version of input that automatically applies formatting masks as the user types. It's ideal for fields that require specific formats, such as CPF, CNPJ, phone number, zip code, credit card number, and others.tsx
import { MaskedInput } from "@arkyn/components";
name, mask and replacement property.tsx
<MaskedInputname="phone"mask="(__) _____-____"replacement={{ _: /\d/ }} // Only accepts numbers/>
mask property defines the mask pattern using special characters to represent positions to be filled. The replacement property defines which characters are accepted in each position.tsx
<MaskedInputname="simple-replacement"label="Simple replacement"mask="___-___-___"replacement="_"placeholder="000-000-000"/>
tsx
<MaskedInputname="regex-replacement"label="Numbers only"mask="(__) _____-____"replacement={{ _: /\d/ }}placeholder="(00) 00000-0000"leftIcon={Phone}/>
showMask to display the mask pattern as a visual placeholder.tsx
<MaskedInputname="cpf-show-mask"label="CPF (with visible mask)"mask="___.___.___-__"replacement="_"showMaskleftIcon={User}/>
separate to separate the mask characters from the actual input value.tsx
<MaskedInputname="cpf-separate"label="CPF (separate value)"mask="___.___.___-__"replacement="_"separateleftIcon={User}/>
md and lg, following the same pattern as the Input component.tsx
<MaskedInputname="phone-md"mask="(__) _____-____"replacement={{ _: /\d/ }}placeholder="(00) 00000-0000"size="md"/><MaskedInputname="phone-lg"mask="(__) _____-____"replacement={{ _: /\d/ }}placeholder="(00) 00000-0000"size="lg"/>
solid, outline, and underline, providing different visual styles.tsx
<MaskedInputname="cpf-solid"mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"variant="solid"/><MaskedInputname="cpf-outline"mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"variant="outline"/><MaskedInputname="cpf-underline"mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"variant="underline"/>
R$
tsx
<MaskedInputmask="____.___,__"replacement={{ _: /\d/ }}name="money"label="My wallet"placeholder="100.00"prefix="R$"/>
tsx
<MaskedInputmask="__/__/____"replacement={{ _: /\d/ }}name="day"label="Your birthday month"suffix={Calendar1}/>
tsx
<MaskedInputname="disabled-cpf"label="CPF disabled"mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"disabledleftIcon={User}/>
tsx
<MaskedInputname="readonly-cpf"label="CPF read-only"mask="___.___.___-__"replacement="_"value="123.456.789-00"readOnlyleftIcon={User}/>
rightIcon.tsx
<MaskedInputname="loading-cpf"label="Validating CPF..."mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"isLoadingleftIcon={User}/>
errorMessage property, it will take precedence over messages from the form provider.tsx
<MaskedInputname="invalid-cpf"label="CPF"mask="___.___.___-__"replacement="_"placeholder="000.000.000-00"errorMessage="Invalid CPF"leftIcon={User}showAsterisk/>
name - string (required)
Field name for form manipulationmask - string (required)
Mask pattern (e.g., ".._-" for CPF)replacement - string | Replacement (required)
Replacement character or setting for mask positionsseparate - boolean
Whether to separate mask characters from the input valueshowMask - boolean
Whether to show the mask placeholderlabel - string
Label text to display above the inputerrorMessage - string
Error message to display below the inputisLoading - boolean (default: false)
Controls the loading state with a spinnersize - "md" | "lg" (default: "md")
Input sizevariant - "solid" | "outline" | "underline" (default: "solid")
Visual variant of the inputprefix - `string | LucideIcon
Text or icon to display at the beginning of the inputsuffix - string | LucideIcon
Text or icon to display at the end of the inputshowAsterisk - boolean
Whether to display an asterisk in the label for required fieldsleftIcon - LucideIcon
Optional icon to display on the left siderightIcon - LucideIcon
Optional icon to display on the right side<input> are also supported, except type, which is controlled by the mask.type type is not supported because it is controlled by the mask.isLoading is true, the input is automatically disabled.@react-input/mask library for advanced mask functionality.