2.7.0 • Published 4 years ago

react-nice-input-password v2.7.0

Weekly downloads
373
License
MIT
Repository
github
Last release
4 years ago

React-Nice-Input-Password

Build Status Coverage Status FOSSA Status Known Vulnerabilities

An input password built with and for React and works nicely with Material-UI

Demo

https://codesandbox.io/s/o1v16rqqrz

Material UI Support

MaterialUI

And more ...

Sample

Installation

npm install react-nice-input-password --save

Usage

import NiceInputPassword from 'react-nice-input-password';
import 'react-nice-input-password/dist/react-nice-input-password.css';

React-Nice-Input-Password uses the traditional inputtype=password behinde the cenes. The strenght configuration can be passed as an array of objects to the prop securityLevels.

You can see a sample of code bellow:

import React from 'react';
import NiceInputPassword from 'react-nice-input-password';
import 'react-nice-input-password/dist/react-nice-input-passord.css';

class App extends React.Component {
  state = {}
  handleChange = (data) => {
    this.setState({
      [data.name]: data.value,
    });
  }
  render() {
    const { passwordField } = this.state;
    const value = passwordField && passwordField.value;

    return (
      <NiceInputPassword
        label="My password field"
        name="passwordField"
        value={value}
        securityLevels={[
          {
            descriptionLabel: '1 number',
            validator: /.*[0-9].*/,
          },
          {
            descriptionLabel: '1 lowercase letter',
            validator: /.*[a-z].*/,
          },
          {
            descriptionLabel: '1 uppercase letter',
            validator: /.*[A-Z].*/,
          },
        ]}
        showSecurityLevelBar
        showSecurityLevelDescription
        onChange={this.handleChange}
      />
    );
  }
}

Usage with Material-UI

import React from 'react';
import NiceInputPassword from 'react-nice-input-password';
import {TextField, InputLabel, Typography} from '@material-ui/core';
import LockIcon from '@material-ui/icons/Lock';

class App extends React.Component {
  state = {}
  handleChange = (data) => {
    this.setState({
      [data.name]: data.value,
    });
  }
  render() {
    const { passwordField } = this.state;
    const value = passwordField && passwordField.value;

    return (
      <NiceInputPassword
        label="My password field"
        name="passwordField"
        value={value}
        showSecurityLevelBar
        onChange={this.handleChange}
        LabelComponent={InputLabel}
        InputComponent={TextField}
        InputComponentProps={{
          variant: 'outlined',
          InputProps: {
            endAdornment: <LockIcon />,
          }
        }}
        securityLevels={[
          {
            descriptionLabel: <Typography>1 number</Typography>,
            validator: /.*[0-9].*/,
          },
          {
            descriptionLabel: <Typography>1 lowecase letter</Typography>,
            validator: /.*[a-z].*/,
          },
          {
            descriptionLabel: <Typography>1 uppercase letter</Typography>,
            validator: /.*[A-Z].*/,
          },
        ]}
      />
    );
  }
}

Custom classNames

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.

Select Props

PropertyTypeDefaultDescription
labelstring or functionundefinedThe label showned on top of input element
namestringundefinedThe name used on input element name={name}
visiblebooleanfalseMake the password visible by changing the input type to text
placeholderstring(empty string)The placeholder used on input element placeholder={placeholder}
classNamestring(empty string)Optional class to be passed to niceinputpassword context
styleobjectundefinedOptional style to be passed to input field
LabelComponentReactComponentinputOptional label component to be used
InputComponentReactComponentinputOptional input component to be used
InputComponentPropsObjectnullOptional object to be passed to the custom InputComponent
renderLevelBarComponentRender functionnullOptional function to return a custom levelbar component
normalClassNamestring'none'The className used on level color
dangerClassNamestring'danger'The className used on level color
warningClassNamestring'warning'The className used on level color
successClassNamestring'success'The className used on level color
startAdornmentReactNodeundefinedStart adornment for this component
endAdornmentReactNodeundefinedEnd adornment for this component
valuestringundefinedThe value to be renderized on element
showSecurityLevelBarboolfalseKey to show or not the security level bullets of password
showSecurityLevelDescriptionboolfalseKey to show or not the security level description securityLevels object
securityLevelsarray of objects[]The array containing the objects to validate the password, see a sample of this object on after this table
onChangefuncundefinedonChange handler: @params: { name, value, isValid}

License

MIT Licensed. Copyright (c) Renan Borges.

FOSSA Status

2.7.0

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.1

4 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago