3.1.0 • Published 6 years ago

react-select-item v3.1.0

Weekly downloads
376
License
ISC
Repository
github
Last release
6 years ago

React Select Item

Build Status npm version Donate License

Simple and awesome react select component for rendering Select with options, complete with react ^14.0 Search inside options supported. Writing by ES2015.

Version 3.1.0 released CHANGELOG

Demo

Installation

$ npm install react-select-item --save

Features

  1. Very customizable components, you can see very different usage in Demo Just extend default option or label and re-define render function by you own needed
class CustomOption extends Option<IOptionProps, {}> {
    /**
     * Available props:
     *
     * getOptionProps: (option: any) => {};
     * onClick: (value: any) => void;
     * selected: boolean;
     * option: any;
     * @param props
     */
    constructor(props) {
        super(props);
    }

    public render() {
        const {option} = this.props;
        return (
            <div {...this.getOptionProps()}>
                <span className="option-name"> {option.name}</span>
                <span className="option-date"> {option.value.creationTs || option.creationTs} </span>
            </div>
        );
    }
}
  1. Adaptive options format You can use value as object with "id" key or plaint value with text or number, in one time it works!
 const optionsList = [
            {
                disabled: true,
                name: "Red",
                value: {id: "red", creationTs: "20.01.2017 - 16:53:24"},
            },
            {
                name: "Blue",
                value: {id: "blue", creationTs: "20.01.2017 - 16:53:24"},
            },
            {
                name: "Yellow",
                value: {id: "yellow", creationTs: "20.01.2017 - 16:53:24"},
            },
            {
                creationTs: "20.01.2017 - 16:53:24",
                name: "Orange",
                value: "orange",
            },
        ];
  1. Customizable search with text highlighting. You can use highlightTestSetter/Getter for highlight complaint objects ot customize text passed from different places.

Props Guide

PropertyTypeDescription
LabelComponentcomponentcomponent for rendering label
OptionComponentcomponentcomponent for rendering option
getOptionPropsfunctionpass props to Option component
getLabelPropsfunctionpass props to Label component
closeOnChangebooleanclose options menu after item click
placeholderstringdefault placeholder text
valuearrayselected values
onChangefunctionchange handler function
onSearchfunctionfilter options by search input text
highlightTextGetterfunctionget the highlight text from compound option object
highlightTextSetterfunctionset the output compound object to the option label after search filter
searchbooleanenable or disable search
searchTextstringcurrent search text value
multiplebooleanenable or disable multiple select
searchEmptyPlaceholderstringno items found text
searchPlaceholderstringsearch placeholder text
classNameclassnamesclass name, may be string or object, classnames inside
clearTextstringclear items button popup text
openbooleanoptions menu statement flag
customLabelsRenderfunctioncustom render for selected items

Development

Start the dev server

$ npm run serve
$ npm run example

Defaults to port 4444, check the localhost:4444 to view the library usage

Example

import React, { PropTypes } from "react";
import { noop } from "lodash";
import SelectItem from "react-select-item";

export default class MultiSelectFilter extends React.Component {

  static propTypes = {
    placeholder: PropTypes.string,
    isLoading: PropTypes.bool,
    label: PropTypes.string,
    value: PropTypes.array,
    options: [],
    onChange: PropTypes.fn,
    className: PropTypes.string,
    wrapperClassName: PropTypes.string
  };

  static defaultProps = {
    placeholder: "",
    isLoading: false,
    label: "",
    value: [],
    options: [],
    onChange: noop,
    className: ""
  };

  /**
   * Component constructor
   * The component is depended from Bootstrap 3.x (styles only)
   * @param props
   */
  constructor(props) {
    super(props);
    this.state = {
      values: this.props.value
    };
  }

  handleMultiChange = (value) => {
    this.setState({ values: value });
    this.props.onChange(value);
  };

  render() {
    return (
      <div className={this.props.wrapperClassName}>
        <div className="form-group">
          <label>{this.props.label}</label>
          <SelectItem label={this.props.label}
                     onChange={this.handleMultiChange}
                     value={this.state.values}
                     closeText={false}
                     className="form-control"
                     multiple={true}>
            { this.props.options.map((item, index) => (
                <option key={index} value={item}>{item.name}</option>
              )
            )}
          </SelectItem>
        </div>
      </div>
    );
  }
}
3.1.0

6 years ago

3.0.10-a

7 years ago

3.0.10

7 years ago

3.0.9

7 years ago

3.0.8

7 years ago

3.0.7

7 years ago

3.0.6

7 years ago

3.0.5

7 years ago

3.0.1-a

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0-g

7 years ago

3.0.0-f

7 years ago

3.0.0-e

7 years ago

3.0.0-d

7 years ago

3.0.0-c

7 years ago

3.0.0-b

7 years ago

3.0.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.0.0

7 years ago