react-selectrix

我要开发同款
匿名用户2021年11月23日
14阅读
开发技术Java
所属分类AndroidUI组件、手机/移动开发、Android UI 组件
授权协议MIT License

作品详情

ReactSelectrix

Abeautiful,materialized,easytouseandflexibleReactSelectreplacement

Demo

Checkoutthedemoanduseexampleshere!

Installingnpmi--save-devreact-selectrixDocumentation

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

ImporttoyourprojectimportSelectrixfrom"react-selectrix";BasicExample<Selectrixmultiple={true}materialize={true}options={[{key:"javascript",label:"Javascript"},{key:"go",label:"Go"},{key:"ruby",label:"RubyOnRails"},{key:"php",label:"PHP"}]}onChange={value=>console.log(value)}/>PropsNameTypeDefaultValueDescriptionoptionsarray[]Anarrayoftheavailableoptions(Objectswith"key","label"pairsandoptionally"disabled"property).multiplebooleanfalseWhethertheSelectsupportsmultiplevalues.searchablebooleantrueWhethertheSelectissearchable.noResultsMessagestringNoresultsmatchThemessageofthenoresultsmatch.materializebooleantrueWhetherthestyleoftheSelectshouldbeMaterializedordefault.defaultValueboolean/array/stringfalseIfyouhavepreselectedvaluesusethisproperty.Useanarrayofoptionkeysformultipleselections,orkeyasastringforsingleselection.checkBoxesbooleanfalseSetthistotrueifyouwanttorenderCheckboxesinsteadoflistitems.heightnumber190Theheightofthedropdown.placeHolderInsidebooleanfalseIftheplaceholdershouldbeanoption.placeholderstringPleaseSelectTheplaceholderoftheSelect.isOpenbooleanfalseIftheSelectshouldberenderedopen.arrowbooleantrueWhethertoshowanarrowonSelect'sheader.disabledbooleanfalseWhethertheSelectshouldbedisabled.customScrollbarbooleanfalseAcustomscrollbar(onlyforChrome)stayOpenbooleanfalseIftheSelectshouldstayopenornot.commaSeperatedbooleanfalseIfyouwanttheselectedvaluestobeacommaseperatedstring,turnthisto"true".(Availableonlywithmultiplepropsetto"true".)singleLinebooleanfalseWheretheselectedvalues(Select'sHeader)shouldbecontainedtooneline.lifobooleanfalseLastInFirstOutMode.Theuser'slastselection,goesfirst.(Availableonlywithmultiplepropsetto"true".)searchIndexbooleantrueEnablesearchbybothIndexandValuefieldsselectAllButtonbooleanfalseWhethera"selectallbutton"shouldbevisibleonSelect'sheader.isDropDownbooleantrueSetthistotrueifyouwanttousetheSelectasaDropdown.Whenyouselectanoption,theSelectcollapsesandtheheadercontinuetohavetheplaceholderasavalue.tagsbooleanfalseWhethertosupportcustomtags.customKeysobject/booleanfalsePassanobjecttochangethedefaultoptionkeys(key,label).ExampleSyntax:{key:"url",label:"title"},tochangethekeyto"url"andthelabelto"title".ajaxboolean/objectfalseWhethertoenableajax.ThelibrarysupportsasynchronouscallsthroughfetchAPI.Availabledefaultpropertiesofajaxobject:{url:'',headers:{},debounce:200,fetchOnSearch:false,q:"",nestedKey:false,searchPrompt:true,minLength:1}.Youcanfinddetailsforalltheajaxobjectproperties,inthenextsectionandinourdemopage.onRenderOptionfunction/booleanfalseUsethisfunctiontorendercustomoptionitemsonRenderSelectionfunction/booleanfalseUsethisfunctiontorendercustomselecteditemsonChangefunctionundefinedUsethiscallbacktocatchSelect'schangetrigger.onOpenfunctionundefinedUsethiscallbacktocatchSelect'sopentrigger.onClosefunctionundefinedUsethiscallbacktocatchSelect'sclosetrigger.Ajaxprop-breakdownNameTypeDefaultValueDescriptionurlstring''TheurlwhichtheSelectgoingtofetchtheavailableoptions.headersobject{}Passanyheadersyouwanttofetchapi.debouncenumber200Thedebounceoftheajaxcallsinmilliseconds.fetchOnSearchbooleanfalseWhetheryoudon'twanttohavetheoptionsprepopulated,whentheSelectopens,butyouwanttoquerythembasedonuser'ssearchvalue.qstring''ThispropertygoesalongsidewithfetchOnSearchproperty,settedto"true".DependingtheRESTAPIprovidingyouwithoptions,youhavetochangethisvalueaccordingly.e.g."&search={q}".Whereveryouusethepseudovariable{q},theuser'ssearchquerywillinjectedinthefinalrequest.nestedKeystring/booleanfalseIfyourRESTAPIreturnstheactualdatainadeeperlevel,insideanestedkey,let'ssay"articles",setnestedKeyto"articles".searchPromptbooleantrueThispropertygoesalongsidewithfetchOnSearchpropertyandindicatestheuserhowmanymorecharactersshouldtype,beforetheajaxsearchwillhappen.minLengthnumber1ThispropertygoesalongsidewithfetchOnSearchpropertyandsearchPromptsettedto"true".Itistheminlengthofcharacterstheusershouldtype,beforetheajaxcallsearchtakesplace.Callbacks-breakdownNameArgumentsDescriptiononChangevalueTheselectedobjectiftheSelectissingleandanarrayofobjectsiftheSelectismultiple.onRenderOptionoption,indexTheoptionwhichisgoingtoberenderedandit'scorrespondingindex.onRenderSelectionselected,settings,deselectTheselectedobject,theSelect'ssettingsandacallbackfunctiontousefordeselection.onOpenN/AonCloseN/AAjaxExample

Manythankstonewsapi.orgfortheirgreatapi.Checkthisexampleinaction,inourdemopage.

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

Checkthisexampleinaction,inourdemopage.

<Selectrixmultiple={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}}/>TagsExample

Checkthisexampleinaction,inourdemopage.

<Selectrixmultiple={true}materialize={true}tags={true}options={[{key:"hotdog",label:"HotDog"},{key:"pizza",label:"Pizza"}]}onChange={value=>console.log(value)}/>CustomRenderExample

Checkthisexampleinaction,inourdemopage.

<Selectrixmultiple={true}materialize={true}options={[{key:"javascript",label:"Javascript"},{key:"go",label:"Go"},{key:"ruby",label:"RubyOnRails"},{key:"php",label:"PHP"}]}onRenderOption={onRenderOption}onRenderSelection={onRenderSelection}onChange={value=>console.log(value)}/>constonRenderOption=(option,index)=>(<span><iclassName="fafa-laptop"></i>{option.label}</span>)constonRenderSelection=(selected,settings,deselect)=>(<spanstyle={{marginRight:10,border:"1pxsolid#eee",padding:5}}>{selected.label}<istyle={{paddingLeft:5,cursor:"pointer"}}onClick={deselect}className="fafa-window-close"></i></span>)License

MITLicensed.StratosVetsos.

Contributions

Contributionsaremorethanwelcome.Runnpminstall&&npmstartonmasterandyouaregoodtogo!TheCONTRIBUTING.mdisgoingtobepublishedsoon.

查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论