1.1.1 • Published 5 years ago

react-amazing-input v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-amazing-input

Installation

    npm install react-amazing-input

or

    yarn add react-amazing-input

Props

NameTypeDescriptionDefault
value?stringvalue of inputnull
focused?booleanset focus statenull
hidden?booleanset hidden statenull
hiddenStyle?CSSPropertiescustom style for hidden statenull
style?CSSPropertiescustom style for defaultnull
className?stringclassName for inputnull
onNativeFocus?() => voidhandle for onFocusnull
onNativeBlur?() => voidhandle for onBlurnull
onInput?(inputValue: string) => voidhandle onInputnull
onChange?(evt: any) => voidhandle onChange() => {}
onTouchStart?(evt: any) => voidhandle onTouchStartnull
onTouchEnd?(evt: any) => voidhandle onTouchEndnull
onTouchMove?(evt: any) => voidhandle onTouchMovenull
onTouchCancel?(evt: any) => voidhandle onTouchCancelnull
onMouseDown?(evt: any) => voidhandle onMouseDownnull
onMouseUp?(evt: any) => voidhandle onMouseUpnull
onMouseMove?(evt: any) => voidhandle onMouseMovenull
onKeyDown?(evt: any) => voidhandle onKeyDownnull
onKeyUp?(evt: any) => voidhandle onKeyUpnull
onKeyPress?(evt: any) => voidhandle onKeyPressnull

###Usage

import * as React from "react";
import {Component} from "react";
import {autobind} from "core-decorators";

import {Input} from "react-amazing-input";


interface AppState {
  value: string;
  inputFocused: boolean;
  inputHidden: boolean;
  enableControlState: boolean;
}

class App extends Component<{}, AppState> {

  constructor(props) {
    super(props);

    this.state = {
      value: "",
      inputFocused: false,
      inputHidden: false,
      enableControlState: true
    };
  }

  @autobind
  private onInput(str: string) {
    this.setState({value: str});
  }

  @autobind
  private onNativeFocusInput() {
    this.setState({inputFocused: true});
    console.log("Native focus");
  }

  @autobind
  private onNativeBlurInput() {
    this.setState({inputFocused: false});
    console.log("Native blur");
  }

  render() {
    
    const {value, enableControlState, inputHidden, inputFocused} = this.state;
    
    return (
      <div className={"App"}>
        <div>
          <h2>Input value:</h2>
          <h3>{value}</h3>
        </div>
        <Input onNativeFocus={this.onNativeFocusInput}
               onNativeBlur={this.onNativeBlurInput}
               onInput={this.onInput}
               focused={enableControlState ? inputFocused : null}
               hidden={inputHidden}
               value={value}/>
        <button onClick={() => this.setState({inputFocused: !inputFocused})}>Change focus</button>
        <button onClick={() => this.setState({inputHidden: !inputHidden})}>Change hidden</button>
        <button onClick={() => this.setState({value: "123"})}>Change value</button>
        <label>
          <input type='checkbox' checked={enableControlState} onClick={() => this.setState({enableControlState: !enableControlState})} />
          Enable control state
        </label>
      </div>
    );
  }

}
1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago