GithubHelp home page GithubHelp logo

kasbah / react-search-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from enkidevs/react-search-input

0.0 3.0 0.0 23 KB

Simple react.js component for a search input, providing a filter function.

HTML 51.55% CSS 8.47% JavaScript 39.98%

react-search-input's Introduction

react-search-input

Simple React component for a search input, providing a filter function.

Install

npm install react-search-input --save

or

bower install react-search-input --save

Example

var SearchInput = require('react-search-input');

var App = React.createClass({
  render() {
    var mails = [{
      user: {
        name: 'Mathieu',
        job: 'Software Engineer',
        company: 'Enki'
      },
      subject: 'Hi!'
    }, {
      user: {
        name: 'foo'
      },
      subject: 'bar'
    }, {
      user: {
        name: 'bar'
      },
      subject: 'foo'
    }];

    if (this.refs.search) {
      var filters = ['user.name', 'subject'];
      mails = mails.filter(this.refs.search.filter(filters));
    }

    return (
      <div>
        <SearchInput ref='search' onChange={this.searchUpdated} />
        {mails.map(function(mail) {
          return (
            <div className='mail'>
              <div className='from'>{mail.user.name}</div>
              <div className='subject'>{mail.subject}</div>
            </div>
          )
        })}
      </div>
    );
  },

  searchUpdated(term) {
    this.setState({searchTerm: term}); // needed to force re-render
  }
});

API

Props

All props are optional. All other props will be passed to the DOM input.

className

Class of the Component (in addition of search-input).

onChange

Function called when the search term is changed (will be passed as an argument).

filterKeys

Either an [String] or a String. Will be use by the filter method if no argument is passed there.

throttle

Reduce call frequency to the onChange function (in ms). Default is 200.

caseSensitive

Define if the search should be case sensitive. Default is false

value

Define the value of the input.

Methods

filter([keys])

Return a function which can be used to filter an array. keys can be String, [String] or null.

If an array keys is an array, the function will return true if at least one of the keys of the item matches the serch term.

Static Methods

filter(searchTerm, [keys], [caseSensitive])

Return a function which can be used to filter an array. searchTerm can be a regex or a String. keys can be String, [String] or null.

If an array keys is an array, the function will return true if at least one of the keys of the item matches the serch term.

Styles

Look at react-search-input.css for an idea on how to style this component.


MIT Licensed

react-search-input's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.