Socket
Socket
Sign inDemoInstall

react-selectrix

Package Overview
Dependencies
8
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-selectrix

A beautiful, clean coded select replacement for React.js


Version published
Weekly downloads
144
decreased by-66.36%
Maintainers
1
Install size
959 kB
Created
Weekly downloads
 

Readme

Source

React Selectrix

A beautiful, materialized, easy to use and flexible React Select replacement

Demo

Check out the demo and use examples here!

Installing

npm i --save-dev react-selectrix

Documentation

https://github.com/stratos-vetsos/react-selectrix/

Import to your project

import Selectrix from "react-selectrix";

Basic Example

<Selectrix
	multiple={true}
	materialize={true}
	options={[
		{
			key: "javascript",
			label: "Javascript"
		},
		{
			key: "go",
			label: "Go"
		},
		{
			key: "ruby",
			label: "Ruby On Rails"
		},
		{
			key: "php",
			label: "PHP"
		}
	]}
	onChange={ value => console.log( value ) }
/>

Props

NameTypeDefault ValueDescription
optionsarray[]An array of the available options ( Objects with "key", "label" pairs and optionally "disabled" property ).
multiplebooleanfalseWhether the Select supports multiple values.
searchablebooleantrueWhether the Select is searchable.
materializebooleantrueWhether the style of the Select should be Materialized or default.
defaultValueboolean / array / stringfalseIf you have preselected values use this property. Use an array of option keys for multiple selections, or key as a string for single selection.
checkBoxesbooleanfalseSet this to true if you want to render Checkboxes instead of list items.
heightnumber190The height of the dropdown.
placeHolderInsidebooleanfalseIf the placeholder should be an option.
placeholderstringPlease SelectThe placeholder of the Select.
isOpenbooleanfalseIf the Select should be rendered open.
arrowbooleantrueWhether to show an arrow on Select's header.
disabledbooleanfalseWhether the Select should be disabled.
customScrollbarbooleanfalseA custom scrollbar ( only for Chrome )
stayOpenbooleanfalseIf the Select should stay open or not.
commaSeperatedbooleanfalseIf you want the selected values to be a comma seperated string, turn this to "true". ( Available only with multiple prop set to "true". )
singleLinebooleanfalseWhere the selected values ( Select's Header ) should be contained to one line.
lifobooleanfalseLast In First Out Mode. The user's last selection, goes first. ( Available only with multiple prop set to "true". )
searchIndexbooleantrueEnable search by both Index and Value fields
selectAllButtonbooleanfalseWhether a "select all button" should be visible on Select's header.
isDropDownbooleantrueSet this to true if you want to use the Select as a Dropdown. When you select an option, the Select collapses and the header continue to have the placeholder as a value.
tagsbooleanfalseWhether to support custom tags.
customKeysobject / booleanfalsePass an object to change the default option keys ( key, label ). Example Syntax: { key: "url", label: "title" } , to change the key to "url" and the label to "title".
ajaxboolean / objectfalseWhether to enable ajax. The library supports asynchronous calls through fetch API. Available default properties of ajax object: { url: '', headers: {}, debounce: 200, fetchOnSearch: false, q: "", nestedKey: false, searchPrompt: true, minLength: 1 }. You can find details for all the ajax object properties, in the next section and in our demo page.
onRenderOptionfunction / booleanfalseUse this function to render custom option items
onRenderSelectionfunction / booleanfalseUse this function to render custom selected items
onChangefunctionundefinedUse this callback to catch Select's change trigger.
onOpenfunctionundefinedUse this callback to catch Select's open trigger.
onClosefunctionundefinedUse this callback to catch Select's close trigger.

Ajax prop - breakdown

NameTypeDefault ValueDescription
urlstring''The url which the Select going to fetch the available options.
headersobject{}Pass any headers you want to fetch api.
debouncenumber200The debounce of the ajax calls in milliseconds.
fetchOnSearchbooleanfalseWhether you don't want to have the options prepopulated, when the Select opens, but you want to query them based on user's search value.
qstring''This property goes alongside with fetchOnSearch property, setted to "true". Depending the REST API providing you with options, you have to change this value accordingly. e.g. "&search={q}". Wherever you use the pseudo variable {q}, the user's search query will injected in the final request.
nestedKeystring / booleanfalseIf your REST API returns the actual data in a deeper level, inside a nested key, let's say "articles", set nestedKey to "articles".
searchPromptbooleantrueThis property goes alongside with fetchOnSearch property and indicates the user how many more characters should type, before the ajax search will happen.
minLengthnumber1This property goes alongside with fetchOnSearch property and searchPrompt setted to "true". It is the min length of characters the user should type, before the ajax call search takes place.

Callbacks - breakdown

NameArgumentsDescription
onChangevalueThe selected object if the Select is single and an array of objects if the Select is multiple.
onRenderOptionoption, indexThe option which is going to be rendered and it's corresponding index.
onRenderSelectionselected, settings, deselectThe selected object, the Select's settings and a callback function to use for deselection.
onOpenN/A
onCloseN/A

Ajax Example

Many thanks to newsapi.org for their great api. Check this example in action, in our demo page.

<Selectrix
	customKeys={{
		key: "url",
		label: "title"
	}}
	ajax={{
		url: "https://newsapi.org/v2/everything?q=bitcoin&sortBy=publishedAt&apiKey=9342a9a707ca49c4b2da34e9ea238ea6",
		nestedKey: "articles"
	}}
/>

Ajax Example with fetchOnSearch

Check this example in action, in our demo page.

<Selectrix
	multiple={true}
	stayOpen={true}
	materialize={true}
	customKeys={{
		key: "url",
		label: "title"
	}}
	ajax={{
		url: "https://newsapi.org/v2/top-headlines?apiKey=9342a9a707ca49c4b2da34e9ea238ea6",
		fetchOnSearch: true,
		q: "&q={q}",
		nestedKey: "articles",
		minLength: 3,
		debounce: 300
	}}
/>

Tags Example

Check this example in action, in our demo page.

<Selectrix
	multiple={true}
	materialize={true}
	tags={true}
	options={[
		{
			key: "hotdog",
			label: "Hot Dog"
		},
		{
			key: "pizza",
			label: "Pizza"
		}
	]}
	onChange={ value => console.log( value ) }
/>

Custom Render Example

Check this example in action, in our demo page.

<Selectrix
	multiple={true}
	materialize={true}
	options={[
		{
			key: "javascript",
			label: "Javascript"
		},
		{
			key: "go",
			label: "Go"
		},
		{
			key: "ruby",
			label: "Ruby On Rails"
		},
		{
			key: "php",
			label: "PHP"
		}
	]}
	onRenderOption={onRenderOption}
	onRenderSelection={onRenderSelection}
	onChange={ value => console.log( value ) }
/>

const onRenderOption = ( option, index ) => (
	<span><i className="fa fa-laptop"></i>{ option.label }</span>
)

const onRenderSelection = ( selected, settings, deselect ) => (
	<span style={{ marginRight: 10, border: "1px solid #eee", padding: 5 }}>
		{ selected.label }
		<i style={{ paddingLeft: 5, cursor: "pointer" }} onClick={ deselect } className="fa fa-window-close"></i>
	</span>
)

License

MIT Licensed. Stratos Vetsos.

Contributions

Contributions are more than welcome. Run npm install && npm start on master and you are good to go! The CONTRIBUTING.md is going to be published soon.

Keywords

FAQs

Last updated on 27 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc