react-selectrix

授权协议 MIT License
开发语言 Java
所属分类 手机/移动开发、 Android UI 组件
软件类型 开源软件
地区 不详
投 递 者 甄佐
操作系统 Android
开源组织
适用人群 未知
 软件概览

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

Name Type Default Value Description
options array [] An array of the available options ( Objects with "key", "label" pairs and optionally "disabled" property ).
multiple boolean false Whether the Select supports multiple values.
searchable boolean true Whether the Select is searchable.
noResultsMessage string No results match The message of the no results match.
materialize boolean true Whether the style of the Select should be Materialized or default.
defaultValue boolean / array / string false If you have preselected values use this property. Use an array of option keys for multiple selections, or key as a string for single selection.
checkBoxes boolean false Set this to true if you want to render Checkboxes instead of list items.
height number 190 The height of the dropdown.
placeHolderInside boolean false If the placeholder should be an option.
placeholder string Please Select The placeholder of the Select.
isOpen boolean false If the Select should be rendered open.
arrow boolean true Whether to show an arrow on Select's header.
disabled boolean false Whether the Select should be disabled.
customScrollbar boolean false A custom scrollbar ( only for Chrome )
stayOpen boolean false If the Select should stay open or not.
commaSeperated boolean false If you want the selected values to be a comma seperated string, turn this to "true". ( Available only with multiple prop set to "true". )
singleLine boolean false Where the selected values ( Select's Header ) should be contained to one line.
lifo boolean false Last In First Out Mode. The user's last selection, goes first. ( Available only with multiple prop set to "true". )
searchIndex boolean true Enable search by both Index and Value fields
selectAllButton boolean false Whether a "select all button" should be visible on Select's header.
isDropDown boolean true Set 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.
tags boolean false Whether to support custom tags.
customKeys object / boolean false Pass 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".
ajax boolean / object false Whether 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.
onRenderOption function / boolean false Use this function to render custom option items
onRenderSelection function / boolean false Use this function to render custom selected items
onChange function undefined Use this callback to catch Select's change trigger.
onOpen function undefined Use this callback to catch Select's open trigger.
onClose function undefined Use this callback to catch Select's close trigger.

Ajax prop - breakdown

Name Type Default Value Description
url string '' The url which the Select going to fetch the available options.
headers object {} Pass any headers you want to fetch api.
debounce number 200 The debounce of the ajax calls in milliseconds.
fetchOnSearch boolean false Whether 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.
q string '' 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.
nestedKey string / boolean false If your REST API returns the actual data in a deeper level, inside a nested key, let's say "articles", set nestedKey to "articles".
searchPrompt boolean true This property goes alongside with fetchOnSearch property and indicates the user how many more characters should type, before the ajax search will happen.
minLength number 1 This 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

Name Arguments Description
onChange value The selected object if the Select is single and an array of objects if the Select is multiple.
onRenderOption option, index The option which is going to be rendered and it's corresponding index.
onRenderSelection selected, settings, deselect The selected object, the Select's settings and a callback function to use for deselection.
onOpen N/A
onClose N/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.

 相关资料
  • 问题内容: 我注意到可以这样导入: …或像这样: 第一个导入模块中的所有内容(请参阅:导入整个模块的内容) 第二个仅导入模块导出(请参阅:导入默认值) 似乎这两种方法是不同的,并且根本上是不兼容的。 为什么它们都起作用? 请参考源代码并解释该机制…我有兴趣了解其工作原理。 ES6常规模块信息回答了该问题。 我在问使模块像这样工作的机制。在这里,它似乎与源代码中的 “ hacky”导出机制有关,但尚

  • 这篇快速上手指南会教你如何将TypeScript与React结合起来使用。 在最后,你将学到: 使用TypeScript和React创建工程 使用TSLint进行代码检查 使用Jest和Enzyme进行测试,以及 使用Redux管理状态 我们会使用create-react-app工具快速搭建工程环境。 这里假设你已经在使用Node.js和npm。 并且已经了解了React的基础知识。 我们之所以使

  • 我已经改用react Native制作跨平台应用程序(虽然没有制作)。我只是想要一个答案,我的问题,反应和反应之间的区别。我在网上搜索了一下,但没有找到合适的答案。

  • 问题内容: 与 哪个更好,为什么? 还是除了以后编写更少的代码外没有其他区别? 写作是否意味着只导入Component对象? 问题答案: 让您代替。它减少了React名称空间的键入和重复,这通常是一种理想的现代编码约定。 此外,Webpack 2和Rollup之类的工具会“摇晃”,这意味着任何未使用的导出都不会捆绑到您的最终代码中。使用/,您可以保证所有React的源代码都将被捆绑。使用,某些工具

  • 本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口            

  • 我正在使用“React admin”创建一个管理界面(前端)。我正在使用spring boot作为我的REST API。我的React应用程序的url是:“http://localhost:3000”。我的spring boot API的url是:“http://localhost:8080”。 下面是CORS配置的spring boot代码,它在一个单独的类中,称为CORSCONFIG: 下面是