README
React-Control-Library
Install
npm install react-control-library
# or
yarn add react-control-library
Example
import React from 'react';
import { SecureMaskedInput } from 'react-control-library';
const App = () => {
const ssnMask = [/^[0-9]*$/, /^[0-9]*$/, /^[0-9]*$/, '-', /^[0-9]*$/, /^[0-9]*$/, '-', /^[0-9]*$/, /^[0-9]*$/, /^[0-9]*$/, /^[0-9]*$/];
const [ssn, setSsn] = React.useState('');
return (
<SecureMaskedInput
mask={ssnMask}
value={ssn}
onChange={(e: any) => setSsn(e.target.value)}
secure={{
getValue: (detail, ssnValue) => {
return '***-HIDDEN';
}
}}
/>
);
};
export default App;
Demo
React-Control-Library With Material UI
React-Control-Library With ReactStrap
Controls
- NumberMask
- MaskedInput
- SecureMaskedInput
- NumberInput
- DecimalInput
- Password
- Alphanumeric
- TextInput
- Checkbox
- RadioButton
About
This project provides some awesome light weight controls for every web application that is designed and developed. They are developed upon pure HTML input controls and hence can be used and styled in a known manner. Controls can be styled using any styling library like BootStrap.
React-Control-Library was bootstrapped with Create React App. They are easy to use in any web application, easy to integrate with any third party libraries like ReactStrap, Material UI. Upon integration with ReactStrap or Material UI, you can have ReactStrap or Material UI controls working usually with all functionalities of this library.
Salient Features
Detail & Validation
All RCL controls (except Checkbox and RadioButton) comes with some validation features in-built which helps developers avoid writing repeated code. It makes development faster and convenient.
On every control onChange
and onBlur
event, eventArgs are populated with detail
object. This behavior can be seen in demo for all controls.
Below is the schema for the detail object (in terms of typescript).
isValid: boolean,
value: any
attribute: string | null,
metadata?: any[]
detail: any
isValid
(boolean)- Denotes weather the control is in valid or invalid state.
- This flag is derived by based on various attributes that are sent to the controls.
- In case of
SecureMaskedInput
, when value of the control is being set by the parent container/page, themetadata
may contains value as['Unknown Validity']
. In these casesisValid
flag maybe incorrect. This documentation will updated once this is addressed nicely :).
value
(any)- Holds value of the control. We can continue to use
e.target.value
in order to fetch the value. - However in cases like
MaskedInput
and other such controls like phone number with format(987) 654-3210
,e.target.value
will provide the value in the same above format. Bute.detail.value
should provide you the actual value like9876543210
.
- Holds value of the control. We can continue to use
attribute
(string | null)When control is in invalid state, this attribute provides info on which attribute makes the control invalid.
For example, in code
<NumberInput min={100} >
if user enters 50, thene.detail
inonChange
andonBlur
should be populated withisValid: false
andattribute: min
.When attribute value is
userInput
it denotes that the control is in invalid state due to behavior provided by rcl library. For example, if a user enters invalid email format inEmail
control, then attribute should be populated withuserInput
value.
metadata
(any[])- This attribute is populated to provide further information about the state of control if needed.
- Look for
Password
control. In case control is valid, then metadata is populated withstrength
of the password. In case it is invalid, metadata is populated with all the password violations and strength of the password.
detail
(any)- This is populated with original
e.detail
value. - The value will be mostly null until set explicitly.
- This is populated with original
Attributes
RCL controls accept all attributes that of HTML input controls. However there are additional attributes introduced with this library to perform additional validation.
exactLength
(number)- This attribute can be passed to see if user input the control value is of exact length passed by user.
- If user input is not that of length passed by user, validation is considered as failed and
e.detail.isValid
is populated withfalse
flag.e.detail.attribute
will holdexactLength
as value.
hasError
(boolean)- When passed as true, this will assign a
class
to control with valuercl-control-error
. - Class
rcl-control-error
will also be assigned whene.detail.isValid
is false ononChange
andonBlur
event. - This attribute is present for all controls.
- When passed as true, this will assign a
mask
(any[])- This attribute can be passed to
MaskedInput
andSecureMaskedInput
control. - They are generally array of strings and regex to hold a mask on the control. See demo for more details on usage.
- In case the mask is empty array, the control behaves without any masking and any of the characters are allowed.
- This attribute can be passed to
mask
(object)- This attribute is specific to
NumberMask
control. - It provides configuration for
NumberMask
control.prefix
: (string): Prefix string that will concatenated to the user input when entered. Defaults to$
.suffix
: (string): Suffix string that will concatenated to the user input when entered. Defaults to empty string.thousandsSeparatorSymbol
: (string): Can be useful to format currency. String that will be used every thousand denomination of the user input. When passed empty string, nothing no formatting will be done at thousand denomination. Defaults to,
.decimalLimit
: (number): Maximum of decimal limit allowed in the user input. Defaults to4
. If passed as0
, then decimal will not be allowed.decimalSymbol
: (string): String used to denote decimal point. Defaults to.
. Will never be used ifdecimalLimit
is passed as0
.maxLength
: (number): Maximum length of user input allowed. Defaults to 20. This length will excludethousandsSeparatorSymbol
,decimalSymbol
etc.negativeAllowed
: (boolean): Negative currency allowed istrue
. Defaults tofalse
.
- This attribute is specific to
inputTag
(React Component)- RCL controls can be integrated with any third party libraries like ReactStrap, Material UI.
- For example, we can pass
Input
from ReactStrap asinputTag
attribute. Like<NumberInput inputTag={Input}
.
detailModes
(string[])- This attribute decides on which event
e.detail
is populated. - Possible values:
onChange
,onBlur
,onKeyPress
,none
. - Default value is
["onChange", "onBlur"]
.
- This attribute decides on which event
decimalLimit
(number)- This attribute is specific to
DecimalInput
control. It limits the decimal point on the decimal value. - Default value is
4
.
- This attribute is specific to
allowSymbols
(string)AlphaNumeric
control allows only numbers, A-Z and a-z.- This attribute is specific to
AlphaNumeric
control. And allows any symbols passed in the control. - For example,
<AlphaNumeric allowSymbols="@._" />
will allow '@', '_', '.' along with alphanumeric values.
restrictSymbols
(string)TextInput
control allows any characters to be typed by user.- This attribute is specific to
TextInput
control. And restricts any symbols passed in the control. - For example,
<TextInput restrictSymbols="@._" />
will restrict '@', '_', '.' characters to be typed by user.
passwordCriteria
(object)- This attribute is specific to
Password
control. - It specifies the criteria for a password.
capital
: (number): Minimum number of capital characters required. Defaults to1
;minLength
: (number): Minimum number of characters required. Defaults to8
;maxLength
: (number): Maximum number of characters allowed. Defaults to0
which means infinite.;numberCount
: (number): Minimum numbers required. Defaults to1
.;symbols
: (number): Minimum number of symbols required. Defaults to1
.;restrictSymbols
: (string): Characters that are not allowed in password. User will be allowed to type the characters however.sequence
: (object): Maximum sequence of characters allowed. a.number
: (number): Defaults to5
. Means 6 or more consecutive numbers are considered invalid password. b.characters
: (number): Defaults to5
. Means 6 or more consecutive characters are considered invalid password.
- This attribute is specific to
secure
(object)- This attribute is specific to
SecureMaskedInput
control. - This provides the secure format of value when user leaves the control.
- Function
getValue
is called to get the formatted text. - Original masking is not respected while showing secure text.
- This attribute is specific to
indeterminate
(boolean)- This attribute is specific to
Checkbox
control. - When trues, checkbox is rendered as partially checked.
- See demo for more usage.
- This attribute is specific to
Copy/Paste & Drag/Drop
- RCL controls do allow copy/paste or drag/drop of text into the controls.
- Only valid characters are accepted upon action for that specific control.
- For example,
<NumberInput />
upon dragging and dropping text of425 123 4567
or(425) 123-4567
, only4251234567
will be seen and accepted in the control.
Seamless Integration with Third Library controls
- RCL controls are designed to provide awesome and useful functionality. However they do not come with any predefined styles.
- RCL controls can be integrated with any third party controls. Any Component to be rendered can be passed as
inputTag
. - For example,
<NumberInput inputTag={TextField} />
will renderTextField
from@material-ui/core
with functionality ofNumberInput
control. - Please note that, any custom-attributes like
label
,passing children for Checkbox/RadioButton
,indeterminate
etc. may or may not work based on the implementation of third party control and how they handle that attribute internally.
Controls
## NumberMask
import React from "react";
import { NumberMask } from "react-control-library";
const App = () => {
const [data, setData] = React.useState('');
function getNumberMask() {
return {
prefix: '