Simple and awesome react select component for rendering Select with options, complete with react ^14.0 Search inside options supported. Writing by ES2015.
$ npm install react-select-item --save
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>
);
}
}
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",
},
];
Property | Type | Description |
---|---|---|
LabelComponent | component | component for rendering label |
OptionComponent | component | component for rendering option |
getOptionProps | function | pass props to Option component |
getLabelProps | function | pass props to Label component |
closeOnChange | boolean | close options menu after item click |
placeholder | string | default placeholder text |
value | array | selected values |
onChange | function | change handler function |
onSearch | function | filter options by search input text |
highlightTextGetter | function | get the highlight text from compound option object |
highlightTextSetter | function | set the output compound object to the option label after search filter |
search | boolean | enable or disable search |
searchText | string | current search text value |
multiple | boolean | enable or disable multiple select |
searchEmptyPlaceholder | string | no items found text |
searchPlaceholder | string | search placeholder text |
className | classnames | class name, may be string or object, classnames inside |
clearText | string | clear items button popup text |
open | boolean | options menu statement flag |
customLabelsRender | function | custom render for selected items |
$ npm run serve$ npm run example
Defaults to port 4444
, check the localhost:4444 to view the library usage
;;; Component static propTypes = placeholder: PropTypesstring isLoading: PropTypesbool label: PropTypesstring value: PropTypesarray options: onChange: PropTypesfn className: PropTypesstring wrapperClassName: PropTypesstring ; 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 */ { super props; thisstate = values: thispropsvalue ; } { this; thisprops; }; { return <div className=thispropswrapperClassName> <div className="form-group"> <label>thispropslabel</label> <SelectItem label=thispropslabel onChange=thishandleMultiChange value=thisstatevalues closeText=false className="form-control" multiple=true> thispropsoptions </SelectItem> </div> </div> ; }}