|
| 1 | +[](https://travis-ci.org/renanborgez/react-nice-input-password) |
| 2 | + |
| 3 | +React-Nice-Input-Password |
| 4 | +============ |
| 5 | + |
| 6 | +A input password control built with and for [React](http://facebook.github.io/react/index.html) |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +The easiest way to use react-select is to install it from npm and build it into your app with Webpack. |
| 11 | + |
| 12 | +```js |
| 13 | +npm install react-nice-input-password --save |
| 14 | +``` |
| 15 | + |
| 16 | +You can then import react-nice-input-password and its styles in your application as follows: |
| 17 | + |
| 18 | +```js |
| 19 | +import NiceInputPassword from 'react-nice-input-password'; |
| 20 | +import 'react-nice-input-password/dist/react-nice-input-password.css'; |
| 21 | + |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +React-Nice-Input-Password uses the traditional input[type=password] behinde the cenes, but you can now validate the strenght level of this value and show it to your users. |
| 26 | + |
| 27 | +The strenght can be passed as a `array` of `objects` to a prop of the component called `securityLevels`. |
| 28 | + |
| 29 | +You can see a sample of code bellow: |
| 30 | + |
| 31 | +```js |
| 32 | +import React from 'react'; |
| 33 | +import NiceInputPassword from 'react-nice-input-password'; |
| 34 | +import 'react-nice-input-password/dist/react-nice-input-passord.css'; |
| 35 | +
|
| 36 | +class App extends React.Component { |
| 37 | + state = {} |
| 38 | + handleChange = (data) => { |
| 39 | + this.setState({ |
| 40 | + [data.name]: data.value, |
| 41 | + }); |
| 42 | + console.log(`Value: ${passwordField.value}`); |
| 43 | + } |
| 44 | + render() { |
| 45 | + const { passwordField } = this.state; |
| 46 | + const value = passwordField && passwordField.value; |
| 47 | +
|
| 48 | + return ( |
| 49 | + <NiceInputPassword |
| 50 | + label="My password field" |
| 51 | + name="passwordField" |
| 52 | + value={value} |
| 53 | + securityLebels={[ |
| 54 | + { |
| 55 | + descriptionLabel: 'At least 1 number', |
| 56 | + validator: /.*[0-9].*/, |
| 57 | + }, |
| 58 | + { |
| 59 | + descriptionLabel: 'At least 1 letter', |
| 60 | + validator: /.*[a-zA-Z].*/, |
| 61 | + }, |
| 62 | + { |
| 63 | + descriptionLabel: 'At least 1 uppercase letter', |
| 64 | + validator: /.*[A-Z].*/, |
| 65 | + }, |
| 66 | + ]} |
| 67 | + onChange={this.handleChange} |
| 68 | + /> |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Custom classNames |
| 75 | + |
| 76 | +You can provide a custom `className` to the Nice Input Password and custom `className` to the color levels, which will be added to input, description and bullets level elements using `dangerClassName`, `warningClassName` and `successClassName`. |
| 77 | + |
| 78 | + |
| 79 | +### Select Props |
| 80 | + |
| 81 | +| Property | Type | Default | Description | |
| 82 | +|:---|:---|:---|:---| |
| 83 | +| label | string or function | undefined | The label showned on top of input element | |
| 84 | +| name | string | undefined | The name used on input element `name={name}` | |
| 85 | +| className | string | (empty string) | Optional class to be passed to niceinputpassword context | |
| 86 | +| normalClassName | string | 'none' | The className used on level color |
| 87 | +| dangerClassName | string | 'none' | The className used on level color |
| 88 | +| warningClassName | string | 'none' | The className used on level color |
| 89 | +| successClassName | string | 'none' | The className used on level color |
| 90 | +| value | string | undefined | The value to be renderized on element |
| 91 | +| showSecurityLevelBar | bool | false | Key to show or not the security level bullets of password |
| 92 | +| showSecurityLevelDescription | bool | false | Key to show or not the security level description securityLevels object |
| 93 | +| securityLevels | array of objects | [] | The array containing the objects to validate the password, see a sample of this object on after this table |
| 94 | +| onChange | func | undefined | onChange handler: `function(newOption) {}` |
| 95 | +
|
| 96 | +
|
| 97 | +
|
| 98 | +# License |
| 99 | +
|
| 100 | +MIT Licensed. Copyright (c) Renan Borges 2018. |
0 commit comments