Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 43c6335

Browse files
authored
Merge pull request #18 from renanborgez/renan/readme
Add material-ui example
2 parents 0b8da31 + 50aad4a commit 43c6335

File tree

1 file changed

+71
-23
lines changed

1 file changed

+71
-23
lines changed

README.md

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Coverage Status](https://coveralls.io/repos/github/renanborgez/react-nice-input-password/badge.svg?branch=master)](https://coveralls.io/github/renanborgez/react-nice-input-password?branch=master)
55
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frenanborgez%2Freact-nice-input-password.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Frenanborgez%2Freact-nice-input-password?ref=badge_shield) [![Known Vulnerabilities](https://snyk.io//test/github/renanborgez/react-nice-input-password/badge.svg?targetFile=package.json)](https://snyk.io//test/github/renanborgez/react-nice-input-password?targetFile=package.json)
66

7-
A input password control built with and for [React](http://facebook.github.io/react/index.html)
7+
An input password built with and for [React](http://facebook.github.io/react/index.html)
88
and works nicely with [Material-UI](https://material-ui.com/)
99

1010
## Demo
@@ -19,24 +19,19 @@ and works nicely with [Material-UI](https://material-ui.com/)
1919

2020
## Installation
2121

22-
The easiest way to use react-nice-input-password is to install it from npm and build it into your app with Webpack.
23-
24-
```js
22+
```
2523
npm install react-nice-input-password --save
2624
```
2725

28-
You can then import react-nice-input-password and its styles in your application as follows:
26+
## Usage
2927

3028
```js
3129
import NiceInputPassword from 'react-nice-input-password';
3230
import 'react-nice-input-password/dist/react-nice-input-password.css';
3331
```
3432

35-
## Usage
36-
37-
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.
38-
39-
The strenght can be passed as a `array` of `objects` to a prop of the component called `securityLevels`.
33+
React-Nice-Input-Password uses the traditional input[type=password] behinde the cenes.
34+
The strenght configuration can be passed as an `array` of `objects` to the prop `securityLevels`.
4035

4136
You can see a sample of code bellow:
4237

@@ -51,7 +46,6 @@ class App extends React.Component {
5146
this.setState({
5247
[data.name]: data.value,
5348
});
54-
console.log(`Value: ${passwordField.value}`);
5549
}
5650
render() {
5751
const { passwordField } = this.state;
@@ -63,18 +57,18 @@ class App extends React.Component {
6357
name="passwordField"
6458
value={value}
6559
securityLevels={[
66-
{
67-
descriptionLabel: 'At least 1 number',
68-
validator: /.*[0-9].*/,
69-
},
70-
{
71-
descriptionLabel: 'At least 1 letter',
72-
validator: /.*[a-zA-Z].*/,
73-
},
74-
{
75-
descriptionLabel: 'At least 1 uppercase letter',
76-
validator: /.*[A-Z].*/,
77-
},
60+
{
61+
descriptionLabel: '1 number',
62+
validator: /.*[0-9].*/,
63+
},
64+
{
65+
descriptionLabel: '1 lowercase letter',
66+
validator: /.*[a-z].*/,
67+
},
68+
{
69+
descriptionLabel: '1 uppercase letter',
70+
validator: /.*[A-Z].*/,
71+
},
7872
]}
7973
showSecurityLevelBar
8074
showSecurityLevelDescription
@@ -85,6 +79,60 @@ class App extends React.Component {
8579
}
8680
```
8781

82+
### Usage with Material-UI
83+
84+
```js
85+
import React from 'react';
86+
import NiceInputPassword from 'react-nice-input-password';
87+
import {TextField, InputLabel, Typography} from '@material-ui/core';
88+
import LockIcon from '@material-ui/icons/Lock';
89+
90+
class App extends React.Component {
91+
state = {}
92+
handleChange = (data) => {
93+
this.setState({
94+
[data.name]: data.value,
95+
});
96+
}
97+
render() {
98+
const { passwordField } = this.state;
99+
const value = passwordField && passwordField.value;
100+
101+
return (
102+
<NiceInputPassword
103+
label="My password field"
104+
name="passwordField"
105+
value={value}
106+
showSecurityLevelBar
107+
onChange={this.handleChange}
108+
LabelComponent={InputLabel}
109+
InputComponent={TextField}
110+
InputComponentProps={{
111+
variant: 'outlined',
112+
InputProps: {
113+
endAdornment: <LockIcon />,
114+
}
115+
}}
116+
securityLevels={[
117+
{
118+
descriptionLabel: <Typography>1 number</Typography>,
119+
validator: /.*[0-9].*/,
120+
},
121+
{
122+
descriptionLabel: <Typography>1 lowecase letter</Typography>,
123+
validator: /.*[a-z].*/,
124+
},
125+
{
126+
descriptionLabel: <Typography>1 uppercase letter</Typography>,
127+
validator: /.*[A-Z].*/,
128+
},
129+
]}
130+
/>
131+
);
132+
}
133+
}
134+
```
135+
88136
### Custom classNames
89137

90138
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`.

0 commit comments

Comments
 (0)