Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@elbstack/react-text-mask-hoc
Advanced tools
A higher-order text-mask component for React and React Native.
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:
text-mask
, see its
documentation
for more information.TextMask
withTextMask
InputAdapter
and SpanAdapter
TextInputAdapter
and TextAdapter
TextMaskTransformer
yarn add react-text-mask-hoc
# or
npm install --save react-text-mask-hoc
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';
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
text-mask
settingsComponent
(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
value
getterfocus()
blur()
withTextMask(AdaptedComponent)
A helper HOC
that passes AdaptedComponent
down to the TextMask
.
Arguments
AdaptedComponent
(React.Component): A component that
follows the adapter specification.Returns
An extended TextMask
.
Usage
import {withTextMask} from 'react-text-mask-hoc';
class MyAdapterComponent extends React.Component {
// ...
}
const MyTextMaskComponent = withTextMask(MyAdapterComponent)
export default () =>
<MyTextMaskComponent
mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
guide={false}
value="5554953947"
/>;
Adapters are React components that implement a special interface for the
withTextMask
.
List of adapters included in this library:
InputAdapter
SpanAdapter
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.
FAQs
A higher-order text-mask component for React and React Native.
We found that @elbstack/react-text-mask-hoc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.