All Projects β†’ vlad-zhukov β†’ react-text-mask-hoc

vlad-zhukov / react-text-mask-hoc

Licence: MIT license
A higher-order text-mask component decorator for React and React Native.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-text-mask-hoc

Text Mask
Input mask for React, Angular, Ember, Vue, & plain JavaScript
Stars: ✭ 8,102 (+44911.11%)
Mutual labels:  text-formatting, input-mask, inputmask
input-mask
🎭 @ngneat/input-mask is an angular library that creates an input mask
Stars: ✭ 174 (+866.67%)
Mutual labels:  input-mask, inputmask
js-input-masking
No description or website provided.
Stars: ✭ 37 (+105.56%)
Mutual labels:  input-mask, inputmask
use-input-mask
use-input-mask.now.sh
Stars: ✭ 17 (-5.56%)
Mutual labels:  input-mask, text-mask
strf
Yet another C++ text formatting library.
Stars: ✭ 57 (+216.67%)
Mutual labels:  text-formatting
vue-jquery-mask
Vue.js component for jQuery mask plugin
Stars: ✭ 19 (+5.56%)
Mutual labels:  input-mask
FormatEditText
ζ ΌεΌεŒ–θΎ“ε…₯ζ‘†οΌŒε―η”¨ζ₯ζ ΌεΌεŒ–ζ•°ε­—γ€ι‡‘ι’γ€ε·η η­‰; FormatEditText can be used as a formatted text input box
Stars: ✭ 121 (+572.22%)
Mutual labels:  input-mask
wrap
πŸ“–βŽ An efficient and flexible word-wrapping package for Go (golang)
Stars: ✭ 14 (-22.22%)
Mutual labels:  text-formatting
Swiftrichstring
πŸ‘©β€πŸŽ¨ Elegant Attributed String composition in Swift sauce
Stars: ✭ 2,744 (+15144.44%)
Mutual labels:  text-formatting
Bonmot
Beautiful, easy attributed strings in Swift
Stars: ✭ 3,182 (+17577.78%)
Mutual labels:  text-formatting
table-layout
Styleable plain-text table generator. Useful for formatting console output.
Stars: ✭ 18 (+0%)
Mutual labels:  text-formatting
Cleave.js
Format input text content when you are typing...
Stars: ✭ 17,098 (+94888.89%)
Mutual labels:  input-mask
remask
A multi-mask lib
Stars: ✭ 99 (+450%)
Mutual labels:  input-mask
Autonumeric
autoNumeric is a standalone library that provides live as-you-type formatting for international numbers and currencies.
Stars: ✭ 1,626 (+8933.33%)
Mutual labels:  inputmask
Inputmask
Input Mask plugin
Stars: ✭ 5,695 (+31538.89%)
Mutual labels:  inputmask
Imaskjs
vanilla javascript input mask
Stars: ✭ 3,434 (+18977.78%)
Mutual labels:  inputmask

react-text-mask-hoc Β· npm

A higher-order text-mask component for React and React Native.

text-mask is great. It's a feature-rich solution for creating input masks for various libraries and frameworks. However the React implementation has some long-standing bugs and feature requests that bury the potential of the library.

Features:

  • Supports all features from text-mask, see its documentation for more information.
  • Custom components: you can mask any components through a simple adapter interface!
  • Platform agnostic: works in all browsers, React Native and Node.js (useful for server-side rendering)!

Table of Contents

Install

yarn add react-text-mask-hoc
  # or
npm install --save react-text-mask-hoc

Usage

import {TextMask, InputAdapter} from 'react-text-mask-hoc';

export default () => (
    <TextMask
        // You can provide your own adapter component or use one of included in the library.
        Component={InputAdapter}
        mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
        guide={false}
        value="5554953947"
    />
);

To use in React Native import react-text-mask-hoc/ReactNative instead:

import {TextMask, TextInputAdapter} from 'react-text-mask-hoc/ReactNative';

Examples

API

TextMask

A component that grants text-mask functionality to the passed component.

It's a controlled component by default, but it also maintains its own state, however it can also be switched to uncontrolled.

Props

  • all text-mask settings
  • Component (React.Component): A component that follows the adapter specification.
  • [value] (String|Number): A value that will be masked. Will be used as an initial value on mounting, and later can be used to control the component. If isControlled prop is set to false, the value will be ignored on rerenders. Defaults to null.
  • [isControlled] (Boolean): A way to set the component behaviour to be controlled by a value prop or to ignore it (to be uncontrolled). Can also be used to switch it in runtime. Defaults to true.
  • [onChange] (Function): A function that is called on input changes. Takes 2 arguments: the native event (varies from a platform) and the next state (has value and caretPosition properties).
  • [componentRef] (Function): A function that is called with a reference to the Component.

Instance methods

  • the value getter
  • focus()
  • blur()

Adapters

Adapters are React components that implement a special interface for the withTextMask.

List of adapters included in this library:

  • for React
    • InputAdapter
    • SpanAdapter
  • for React Native
    • TextInputAdapter
    • TextAdapter

Specification

An adapter must be a React component that takes value, caretPosition and onChange props, and exposes a caretPosition getter that always returns a positive integer number.


TextMaskTransformer

A class that calculates a value and a caret position. Based on the createTextMaskInputElement() from text-mask-core.

Exported for testing purposes only.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].