0.1.22 • Published 6 years ago

react-input-error-tip v0.1.22

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-input-error-tip

An HTML input element with build-in errorTips

Demo

https://phuhwei.github.io/react-input-error-tip/

Requried Packages in Your Dependencies

    react     styled-components

Install  npm

Through npm install react-input-error-tip --save or yarn add react-input-error-tip

Usage

ES6

import InputTip from 'react-input-error-tip';

ES5

const InputTip = require('react-input-error-tip');

Component

export default class App extends Component {
  constructor(props) {
    super(props);
    this.ref = {};
    this.state = {};
  }
  render() {
    return (
      <InputTip
        type="password"
        name="password"
        placeholder="At least 15 digit"
        value={this.state.password}
        onChange={evt => this.setState({ password: evt.target.value })}
        toggleTip={(name, bool) => this.setState({ password_tip: bool })}
        refInput={(node) => { this.ref.password = node; }}
        errorTips={[{
          placement: 'bottom',
          name: 'password_tip',
          show: this.state.password_tip,
          text: 'at least 15 digit password',
          validate: value => value.length >= 15,
          offset: {
            X: -1,
          },
        }]}
      />
    );
  }
}

Props

PropsOptionsDefaultDescription
toggleTipFunctionrequiredthe function to toggle the errorTip, should take (tipName, boolean) as input
valueString or Numberrequiredwould render a controlled element
onChangeFunctionrequiredwould render a controlled element
refInputFunctionnullact as regular ref property
errorTipsArray of Objectnull {       name: String,       show: bool,       text: String,       validate: Function,       offset: Object,       placement: String }
validate(inside errorTips)Functionnulltake the event.target.value as input, triggerd when input field loses focus
offset(inside errorTips)Objectnull{X: integer, Y: integer}, in px unit
placement(inside errorTip)one of: 'top', 'right', 'bottom', 'left''top'the position of error tip
showAllTipsBooleanfalseif false, only show the first errorTip; otherwise show all invalid errors

Accepts all props which can be given to a input element.

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago