0.7.18 • Published 6 years ago

rc-inputs v0.7.18

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

rc-inputs

Installation

npm i rc-inputs --save

EmailInput

import { EmailInput } from "rc-inputs";

<EmailInput
  className={"some-class"}
  placeholder={"Please enter a valid email address."}
  value={"some value"}
  onChange={(element) => console.log("value", element.target.value)}
  onValid={(valid, element) => console.log("valid", valid, "value", element.target.value)}
  onEnter={(value) => console.log(value)}
  autofill={true}
  autoComplete={"email"}     
/>
PropertyTypeDescription
classNamestringCSS classes of the input.
placeholderstringDefault placeholder of the input.
valuestringValue of the input.
onChangefunctionThe function returns the same as onChange of an average input.
onValidfunctionThe first argument returns bool (true if the email is valid). The second argument returns the same as onChange of an average input.
onPastefunctionHandler of paste event.
onEnterfunctionHandling enter button.
onFocusfunctionThe function called after focus event.
onBlurfunctionThe function called after blur (unfocus) event.
autofillboolTurn off, turn on autofill. You can fetch "remembers" of a browser.
autoCompletestringDefault autoComplete of the input.
clickableKeysarray of intThis is keyCodes of keyboard events
onKeyClickfunctionOnclicks handler of clickableKeys

PasswordInput

import { PasswordInput } from "rc-inputs";

<PasswordInput
  className={"some-class"}
  placeholder={"Password must be at least 6 characters"}
  value={"qwerty123"}
  onChange={(element) => console.log("value", element.target.value)}
  pattern={"^.{6,}$"}
  onValid={(valid, element) => console.log("valid", valid, "value", element.target.value)}
  onEnter={(value) => console.log(value)}
  autofill={true}
  autoComplete={"password"}     
/>
PropertyTypeDescription
classNamestringCSS classes of the input.
placeholderstringDefault placeholder of the input.
valuestringValue of the input.
onChangefunctionThe function returns the same as onChange of an average input.
patternstringYou can use RegExp for handle input value.
onValidfunctionThe first argument of the function returns bool (true if the password is valid according to your pattern). The second argument returns the same as onChange of an average input. Without pattern property onValid doesn't work.
onEnterfunctionHandling enter button.
onPastefunctionHandler of paste event.
onFocusfunctionThe function called after focus event.
onBlurfunctionThe function called after blur (unfocus) event.
autofillboolTurn off, turn on autofill. You can fetch "remembers" of a browser.
autoCompletestringDefault autoComplete of the input.
clickableKeysarray of intThis is keyCodes of keyboard events
onKeyClickfunctionOnclicks handler of clickableKeys

Select

import { Select } from "rc-inputs";
import "rc-inputs/styles/select.css" // or select.less or select.scss

<Select
  className="some-class"
  options={[
    {option: "item 1", className: "test-1", style: {backgroundColor: "red"}},
    {option: "item 2", className: "test-2", style: {backgroundColor: "green"}},
    {option: "item 3", className: "test-3", style: {backgroundColor: "yellow"}},
    {option: "item 4", className: "test-4", style: {backgroundColor: "blue"}}
  ]}
  placeholder={"placeholder"}
  listPlaceholder={"the list is empty"}
  onChange={(e) => console.log("e", e)}
  selected={{option: "item 2"}}
  customeArrow={<i className="my-arrow" />}
/>
PropertyTypeDescription
classNamestringCSS classes of the Select.
dropdownClassNamestringCSS classes for dropdown list of the Select.
activeClassstringCSS class for the active option
optionsarray of string, or array of objectsIn the case of using Objects, the tag requires a field option and in this case possible use to className and style. It is possible to to put the component in the field option. Example of the option like an Object {option: <i className="some-class" />} or {option: "item 1", className: "some-class", style: {backgroundColor: "red"}}.
listPlaceholderstring or ObjectThis item will be shown if the list will be empty.
onChangefunctionThe function returns selected option and index of this option.
activeIndexIntIf you are using jsx like a option {option: <i className="some-class" />}, you have to use activeIndex. Example bellow.
class App extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      activeIndex: 0,
      option: <span>test 1</span>
    };
    this.handleSelect = this.handleSelect.bind(this);
  }
  handleSelect(option, index) {
    this.setState({
      activeIndex: index,
      option: option
    });
  }
  render() {
    return (
     <Select
       onChange={this.handleSelect}
       activeClass={"active"}
       activeIndex={this.state.activeIndex}
       selected={this.state.option}
       options={[
        {option: <span>item 1</span>, className: "some-class"},
        {option: <span>item 2</span>, className: "some-class"},
        {option: <span>item 3</span>, className: "some-class"},
        {option: <span>item 4</span>, className: "some-class"}
      ]}/>
    );
  }
}

TagInput

import { TagInput } from "rc-inputs";
import "rc-inputs/styles/tag-input.css" // or tag-input.less or tag-input.scss

<TagInput
  tags={[{name: "some name", href: "https://www.some...", className: "some-tag-class", style: {color: "#fff"}}]}
  onAdd={(tag) => console.log(tag)}
  onDelete={(tagIndex, tag, tags) => console.log(tagIndex, tag, tags)}
  onChange={(tags) => console.log(tags)}
  disableInput={false}
  createTagOnKeys={[13, 32]}
  createTagOnPress={[","]}
/>
PropertyTypeDescription
classNamestringCSS classes of the tag list element.
classNameWrapstringCSS classes of the element wrapper.
tagsarray of string, or array of objectsIn the case of using Objects, the tag requires a name and in this case possible use to className and style. Example of the tag like an Object {name: "tag name", className: "some-class", style: {color: "#fff"}}.
onAddfunctionThe function returns new tag created by a user.
onDeletefunctionThe first argument of the function returns deleted tag. The second argument returns tag's index of deleted tag in the tags array. The third argument returns the tags.
onChangefunctionThe function returns the array of current tags.
onInputChangefunctionHandler of own input typing.
onPastefunctionHandler of paste event.
onFocusfunctionThe function called after focus event.
onBlurfunctionThe function called after blur (unfocus) event.
createTagOnKeysarray (int)Array of keyCodes. When you press this character on the keyboard, a tag will be created and functions onAdd and onChange will be called
createTagOnPressarrayArray of characters. When you press this character on the keyboard, a tag will be created and functions onAdd and onChange will be called
disableInputboolYou can hide input. In this case TagInput will be just for reading.
dynamicInputWidthboolThe prop makes any inner input(custom or default) stretched on all remaining width. The default is false.
autocompleteobjectSpecial data for autocomplete. See schema below.
inputValuestringValue setter. Use only with autocomplete and included input. This prop required if you want to use autocomplete.
onSelectfunctionThe function returns selected tag from autocomplete and all used tags

Autocomplete Schema

PropertyTypeDescription
itemsarrayDisplayed items of autocomplete
searchKeystringIf you are using objects in items you will have to select key of an object on which will be searched.
searchPathstringCompletely the same as searchKey but works for the deep key. Use dots for going deeper. For exemple key for object {test: {abc: 123}} will be test.abc. Attention! It doesn't work with searchKey.
labelstringtext in the begin of the autocomplete list.

Also exist posobility include some elements into TagInput. In this way, the elements will be added after all elements of TagInput. If you are using autocomplete, don't forget inputValue. Usage example: Add EmailInput Component with handling valid emails.

class SomeComponent extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      emails: [],
      isValid: false,
      inputValue: ""
    };
    this.addTag = this.addTag.bind(this);
    this.handleValidity = this.handleValidity.bind(this);
  }
  addTag(value) {
    if (this.state.isValid) {
      const emails = this.state.emails.concat([value]);
      this.setState({
        emails: emails,
        inputValue: ""
      });
    }
  }
  handleValidity(isValid, e) {
    this.setState({
      isValid: isValid,
      inputValue: e.target.value
    });
  }
  render() {
    return (
      <TagInput disableInput={true}
        inputValue={this.state.inputValue}
        autocomplete={{
          items: [{userData: {email: "test@test.co"}, name: "jo"},
          {userData: {email: "tom@gmail.com"}, name: "tom"},
          {userData: {email: "mark@mark.net"}, name: "mark"},
          {userData: {email: "al@amazon.com"}, name: "alice"},
          {userData: {email: "al@al.co"}, name: "alex"}],
          searchPath: "userData.email",
          className: "list",
          label: "this is label:"
        }}
        tags={this.state.emails}>
        <EmailInput value={this.state.inputValue}
          onEnter={this.addTag}
          onValid={this.handleValidity} />
       </TagInput>
      );
   }
}
0.7.18

6 years ago

0.7.17

6 years ago

0.7.16

6 years ago

0.7.15

6 years ago

0.7.14

6 years ago

0.7.13

6 years ago

0.7.12

6 years ago

0.7.11

6 years ago

0.7.10

6 years ago

0.7.9

6 years ago

0.7.8

6 years ago

0.7.7

6 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago