npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wecareu/input-masked

v0.2.1

Published

Campo de texto com máscara dinâmica para o design system WeCareU

Downloads

479

Readme

@wecareu/input-masked

Campo de texto com máscara dinâmica para o design system WeCareU. Aplica formatação visual automática (CPF, CNPJ, CEP, telefone, cartão de crédito, data) enquanto mantém o valor bruto sem máscara no onChangeText.

Instalação

yarn add @wecareu/input-masked

Peer dependencies

yarn add @wecareu/input-text @wecareu/theme @wecareu/tokens

Uso básico

import { InputMasked } from '@wecareu/input-masked'

// Com preset
<InputMasked
  preset="cpf"
  value={cpf}
  onChangeText={setCpf}
  label="CPF"
/>

// Com máscara customizada
<InputMasked
  mask="999.999.999-99"
  value={cpf}
  onChangeText={setCpf}
  label="CPF"
/>

Presets disponíveis

| Preset | Máscara | Exemplo de exibição | Valor bruto | |--------|---------|---------------------|-------------| | cpf | 999.999.999-99 | 123.456.789-09 | 12345678909 | | cnpj | 99.999.999/9999-99 | 12.345.678/0001-90 | 12345678000190 | | cep | 99999-999 | 01310-100 | 01310100 | | phone | (99) 9999-9999 / (99) 99999-9999 | (11) 98765-4321 | 11987654321 | | credit-card | 9999 9999 9999 9999 | 4111 1111 1111 1111 | 4111111111111111 | | date | 99/99/9999 | 31/12/2025 | 31122025 |

O preset phone alterna automaticamente entre a máscara de 8 e 9 dígitos conforme o usuário digita.

Máscara customizada

Use os tokens abaixo para montar qualquer padrão:

| Token | Aceita | |-------|--------| | 9 | Dígito [0-9] | | A | Letra [a-zA-Z] | | * | Alfanumérico [a-zA-Z0-9] |

Qualquer outro caractere é tratado como literal e inserido automaticamente.

// Placa de veículo (Mercosul): AAA9A99
<InputMasked mask="AAA9A99" value={placa} onChangeText={setPlaca} label="Placa" />

// Processo judicial: 9999999-99.9999.9.99.9999
<InputMasked
  mask="9999999-99.9999.9.99.9999"
  value={processo}
  onChangeText={setProcesso}
  label="Número do processo"
/>

Props

InputMasked herda todas as props de InputText (exceto formatter, parser e type), acrescentando:

| Prop | Tipo | Padrão | Descrição | |------|------|--------|-----------| | preset | 'cpf' \| 'cnpj' \| 'cep' \| 'phone' \| 'credit-card' \| 'date' | — | Preset predefinido. Quando informado junto com mask, mask tem precedência | | mask | string | — | Padrão de máscara customizado com tokens 9, A, * |

Props herdadas relevantes (InputText)

| Prop | Tipo | Padrão | Descrição | |------|------|--------|-----------| | value | string | — | Valor bruto controlado (sem máscara) | | onChangeText | (value: string) => void | — | Callback com o valor bruto (sem máscara) | | label | string | — | Label do campo | | placeholder | string | — | Placeholder exibido quando vazio | | disabled | boolean | false | Bloqueia interação | | readonly | boolean | false | Somente leitura | | validator | (value: string) => boolean | — | Validação customizada (recebe valor bruto) | | validatorMessage | string | — | Mensagem exibida quando validator retorna false | | onValidation | (isValid: boolean) => void | — | Callback com resultado da validação | | validateOnBlur | boolean | true | Valida ao perder foco | | inputError | boolean | false | Força estado de erro externamente | | errorMessage | string | — | Mensagem usada com inputError | | maxLength | number | — | Sobrescreve o limite de caracteres do preset/mask | | leftIcon | InputTextIconProps | — | Ícone à esquerda | | rightIcon | InputTextIconProps | — | Ícone à direita | | testID | string | — | Identificador para testes |

Validação

O validator recebe o valor bruto (sem máscara), facilitando qualquer lógica de validação:

function validarCPF(cpf: string): boolean {
  if (cpf.length !== 11) return false
  // ... algoritmo de verificação dos dígitos verificadores
  return true
}

<InputMasked
  preset="cpf"
  value={cpf}
  onChangeText={setCpf}
  label="CPF"
  validator={validarCPF}
  validatorMessage="CPF inválido"
  onValidation={(isValid) => setFormValid(isValid)}
/>

A validação é acionada no onBlur por padrão e exibe a mensagem de erro com animação de shake.

Exemplos

// CPF com validação
<InputMasked
  preset="cpf"
  value={cpf}
  onChangeText={setCpf}
  label="CPF"
  validator={(v) => v.length === 11}
  validatorMessage="CPF deve ter 11 dígitos"
/>

// Telefone com ícone
<InputMasked
  preset="phone"
  value={phone}
  onChangeText={setPhone}
  label="Telefone"
  leftIcon={{ name: 'phone' }}
/>

// Data de nascimento com limite de data
<InputMasked
  preset="date"
  value={birthDate}
  onChangeText={setBirthDate}
  label="Data de nascimento"
  placeholder="DD/MM/AAAA"
/>

// Placa customizada
<InputMasked
  mask="AAA-9999"
  value={plate}
  onChangeText={setPlate}
  label="Placa"
/>

// Desabilitado
<InputMasked
  preset="cpf"
  value="12345678909"
  onChangeText={() => {}}
  disabled
  label="CPF"
/>

Notas

  • O valor armazenado em value e retornado em onChangeText é sempre bruto (sem os literais da máscara).
  • Quando mask e preset são informados simultaneamente, mask tem precedência.
  • Se nenhum dos dois for informado, o componente exibe um InputText simples e loga um aviso em modo de desenvolvimento.