select.stories.jsx 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254
  1. import React, { useState, useRef, useEffect } from 'react';
  2. import './select.scss';
  3. import { Input, Select, Button, Icon, Avatar, Checkbox, Form, withField, Space, Tag, Switch } from '../../index';
  4. import CustomTrigger from './CustomTrigger';
  5. import classNames from 'classnames';
  6. const Option = Select.Option;
  7. import { IconSearch, IconGift } from '@douyinfe/semi-icons';
  8. export default {
  9. title: 'Select',
  10. parameters: {
  11. chromatic: { disableSnapshot: true },
  12. },
  13. }
  14. let Test = () => {
  15. let [options, setOptions] = useState([1, 2, 3, 4]);
  16. function add() {
  17. let newOptions = Array.from(
  18. {
  19. length: Math.floor(Math.random() * 10),
  20. },
  21. (v, i) => i + 1
  22. );
  23. setOptions(newOptions);
  24. }
  25. let style = {
  26. width: 150,
  27. margin: 20,
  28. };
  29. let slotStyle = {
  30. backgroundColor: 'whitesmoke',
  31. height: '40px',
  32. display: 'flex',
  33. justifyContent: 'center',
  34. alignItems: 'center',
  35. borderRadius: '0 0 6px 6px',
  36. };
  37. let outSlotStyle = {
  38. backgroundColor: 'whitesmoke',
  39. height: '29px',
  40. display: 'flex',
  41. justifyContent: 'center',
  42. alignItems: 'center',
  43. cursor: 'pointer',
  44. };
  45. const click = e => {};
  46. let outSlotNode = (
  47. <div onClick={e => click(e)}>
  48. <Checkbox>sendLarkNotification</Checkbox>
  49. <div>
  50. <Button theme="solid">confirm</Button>
  51. </div>
  52. </div>
  53. );
  54. return (
  55. <>
  56. <Select
  57. style={style}
  58. dropdownClassName="test-dropdown"
  59. dropdownStyle={{
  60. width: 150,
  61. }}
  62. filter
  63. placeholder="fefe"
  64. position="rightTop"
  65. innerBottomSlot={
  66. <div style={slotStyle}>
  67. <Button
  68. size="small"
  69. style={{
  70. margin: 0,
  71. }}
  72. >
  73. 申请其他地区权限
  74. </Button>
  75. </div>
  76. }
  77. >
  78. {options.map(option => (
  79. <Option value={option} key={option} className="fefe">
  80. {option}
  81. </Option>
  82. ))}
  83. </Select>
  84. <Select
  85. style={{
  86. marginTop: 20,
  87. width: 200,
  88. }}
  89. dropdownClassName="test-dropdown"
  90. dropdownStyle={{
  91. width: 150,
  92. }}
  93. filter
  94. placeholder="fefe"
  95. position="rightTop"
  96. outerBottomSlot={outSlotNode}
  97. >
  98. {options.map(option => (
  99. <Option value={option} key={option} className="fefe">
  100. {option}
  101. </Option>
  102. ))}
  103. </Select>
  104. </>
  105. );
  106. };
  107. const AutoFocusDemo = () => {
  108. return (
  109. <>
  110. <Select
  111. autoFocus
  112. style={{
  113. width: 200,
  114. }}
  115. onFocus={() => console.log('onFocus')}
  116. onBlur={() => console.log('onBlur')}
  117. >
  118. <Option value="abc">抖音</Option>
  119. <Option value="hotsoon">火山</Option>
  120. <Option value="pipixia">皮皮虾</Option>
  121. <Option value="duoshan">多闪</Option>
  122. <Option value="xigua">西瓜视频</Option>
  123. </Select>
  124. <div className="test-div">test-div</div>
  125. </>
  126. );
  127. };
  128. export const AutoFocus = () => <AutoFocusDemo />;
  129. AutoFocus.story = {
  130. name: 'autoFocus',
  131. };
  132. export const InnerBottomSlotOuterBottomSlot = () => <Test />;
  133. InnerBottomSlotOuterBottomSlot.story = {
  134. name: 'innerBottomSlot / outerBottomSlot',
  135. };
  136. export const InnerTopSlotOuterTopSlot = () => {
  137. const slot = <div>未找到应用?</div>;
  138. return (
  139. <div>
  140. innerTopSlot
  141. <div>
  142. <Select
  143. innerTopSlot={slot}
  144. style={{
  145. width: 250,
  146. }}
  147. maxHeight={150}
  148. >
  149. <Option value="abc">抖音</Option>
  150. <Option value="hotsoon">火山</Option>
  151. <Option value="pipixia">皮皮虾</Option>
  152. <Option value="duoshan">多闪</Option>
  153. <Option value="xigua">西瓜视频</Option>
  154. </Select>
  155. </div>
  156. outerTopSlot
  157. <div>
  158. <Select
  159. outerTopSlot={slot}
  160. style={{
  161. width: 250,
  162. }}
  163. maxHeight={150}
  164. >
  165. <Option value="abc">抖音</Option>
  166. <Option value="hotsoon">火山</Option>
  167. <Option value="pipixia">皮皮虾</Option>
  168. <Option value="duoshan">多闪</Option>
  169. <Option value="xigua">西瓜视频</Option>
  170. </Select>
  171. </div>
  172. </div>
  173. );
  174. };
  175. InnerTopSlotOuterTopSlot.story = {
  176. name: 'innerTopSlot / outerTopSlot',
  177. };
  178. export const OneOptionJsxWithOtherOptionArray = () => (
  179. <Select
  180. defaultValue={'all'}
  181. style={{
  182. width: 250,
  183. }}
  184. >
  185. <Option value="all" key="all">
  186. all
  187. </Option>
  188. {[1, 2, 3].map(item => (
  189. <Option value={`type${item}`} key={item}>{`type${item}`}</Option>
  190. ))}
  191. </Select>
  192. );
  193. OneOptionJsxWithOtherOptionArray.story = {
  194. name: 'one option jsx with other option array',
  195. };
  196. let options = [
  197. {
  198. value: 'all',
  199. label: '全部',
  200. otherKey: 'all semi',
  201. },
  202. {
  203. value: 'abc',
  204. label: '抖音',
  205. otherKey: 'abc semi',
  206. },
  207. {
  208. value: 'hotsoon',
  209. label: '火山小视频',
  210. otherKey: 'hostsoom semi',
  211. },
  212. {
  213. value: 'pipixia',
  214. label: '皮皮虾',
  215. otherKey: 'pif',
  216. },
  217. {
  218. value: 'toutiao',
  219. label: '今日头条',
  220. otherKey: 'toutiao semi',
  221. },
  222. {
  223. value: 'rd',
  224. label: 'rd',
  225. otherKey: 'semi rd',
  226. },
  227. {
  228. value: 'ued',
  229. label: 'ued',
  230. otherKey: 'semi ued',
  231. },
  232. {
  233. value: 'ued',
  234. label: 'japan',
  235. otherKey: 'semi ued',
  236. },
  237. {
  238. value: '+86',
  239. label: '+86',
  240. otherKey: 'semi',
  241. },
  242. ];
  243. let longOptions = options.concat({
  244. value: 'long',
  245. label: 'Semi Design 是一个设计系统,它定义了一套中后台设计与前端基础组',
  246. });
  247. export const SelectSize = () => (
  248. <div
  249. style={{
  250. margin: 20,
  251. }}
  252. >
  253. <h4>
  254. 使用方不设width时,下拉菜单根据内容自动适配宽度(不推荐这样使用,select的宽度会动态变化)
  255. </h4>
  256. <Select
  257. defaultValue={'all'}
  258. optionList={options}
  259. style={{
  260. margin: 10,
  261. }}
  262. ></Select>
  263. <Select
  264. defaultValue={'long'}
  265. optionList={longOptions}
  266. style={{
  267. margin: 10,
  268. }}
  269. ></Select>
  270. <Select
  271. defaultValue={'abc'}
  272. size="large"
  273. optionList={options}
  274. style={{
  275. margin: 10,
  276. }}
  277. ></Select>
  278. {/* <Select defaultValue={'+86'} size="large" optionList={options} style={{margin: 10}}>
  279. </Select> */}
  280. <h4>通过style设width的</h4>
  281. 90px:{' '}
  282. <Select
  283. defaultValue={'all'}
  284. style={{
  285. width: 90,
  286. marign: 10,
  287. }}
  288. optionList={options}
  289. ></Select>
  290. 120px:{' '}
  291. <Select
  292. defaultValue={'all'}
  293. style={{
  294. width: 120,
  295. margin: 10,
  296. }}
  297. optionList={options}
  298. ></Select>
  299. 400px:{' '}
  300. <Select
  301. defaultValue={'all'}
  302. style={{
  303. width: 400,
  304. margin: 10,
  305. }}
  306. optionList={options}
  307. ></Select>
  308. <br />
  309. 100%:{' '}
  310. <Select
  311. defaultValue={'all'}
  312. style={{
  313. width: '100%',
  314. margin: 10,
  315. }}
  316. optionList={options}
  317. ></Select>
  318. <br />
  319. <h4>通过css设width的</h4>
  320. <Select defaultValue={'all'} className="test-width" optionList={options}></Select>
  321. <br />
  322. <h4>dropdownMatchSelectWidth</h4>
  323. <p>当该项设为true时,下拉菜单最小宽度会等于Select宽度(默认为true)</p>
  324. <div
  325. style={{
  326. margin: 10,
  327. }}
  328. >
  329. style方式指定90px:
  330. <Select
  331. defaultValue={'all'}
  332. optionList={options}
  333. dropdownMatchSelectWidth={true}
  334. style={{
  335. width: 90,
  336. }}
  337. />
  338. </div>
  339. <div
  340. style={{
  341. margin: 10,
  342. }}
  343. >
  344. css方式声明130px:
  345. <Select
  346. defaultValue={'all'}
  347. className="test-width"
  348. optionList={options}
  349. dropdownMatchSelectWidth={true}
  350. ></Select>
  351. </div>
  352. <div>
  353. <h4>需要强制下拉菜单与select同宽的时候</h4>
  354. <p>通过dropdownStyle覆盖min-width,将其设成与select的width同样的值</p>
  355. <Select
  356. defaultValue={'all'}
  357. style={{
  358. width: 300,
  359. margin: 10,
  360. }}
  361. dropdownStyle={{
  362. width: 300,
  363. }}
  364. optionList={options}
  365. />
  366. </div>
  367. </div>
  368. );
  369. SelectSize.story = {
  370. name: 'select size',
  371. };
  372. export const WithPrefixSuffixInsetLabelShowClearShowArrow = () => (
  373. <>
  374. <h4>prefix & suffix</h4>
  375. <Select
  376. style={{
  377. width: '250px',
  378. }}
  379. motion={false}
  380. filter
  381. optionList={options}
  382. prefix={<IconSearch />}
  383. suffix={<IconGift></IconGift>}
  384. ></Select>
  385. <h4>insetLabel</h4>
  386. <Select
  387. style={{
  388. width: '250px',
  389. }}
  390. optionList={options}
  391. insetLabel={'业务线'}
  392. ></Select>
  393. <h4>showClear</h4>
  394. <Select
  395. style={{
  396. width: '250px',
  397. }}
  398. optionList={options}
  399. showClear
  400. ></Select>
  401. <h4>showArrow = false</h4>
  402. <Select
  403. style={{
  404. width: '250px',
  405. }}
  406. optionList={options}
  407. showArrow={false}
  408. ></Select>
  409. <h4>defaultValue是不存在的值</h4>
  410. <Select
  411. style={{
  412. width: '250px',
  413. }}
  414. optionList={options}
  415. defaultValue="+85"
  416. ></Select>
  417. </>
  418. );
  419. WithPrefixSuffixInsetLabelShowClearShowArrow.story = {
  420. name: 'with prefix / suffix / insetLabel, showClear, showArrow',
  421. };
  422. WithPrefixSuffixInsetLabelShowClearShowArrow.parameters = {
  423. chromatic: { disableSnapshot: false },
  424. };
  425. export const WithDefaultSelected = () => (
  426. <Select
  427. style={{
  428. width: '250px',
  429. }}
  430. defaultValue={1}
  431. >
  432. <Option value={1}>opt1</Option>
  433. <Option value={2}>opt2</Option>
  434. <Option value={3}>opt3</Option>
  435. <Option value="4">opt4</Option>
  436. </Select>
  437. );
  438. WithDefaultSelected.story = {
  439. name: 'with default selected',
  440. };
  441. export const WithScrollbar = () => (
  442. <Select
  443. style={{
  444. width: '250px',
  445. }}
  446. defaultValue={1}
  447. >
  448. <Option value={1}>opt1</Option>
  449. <Option value={2}>opt2</Option>
  450. <Option value={3}>opt3</Option>
  451. <Option value="4">opt4</Option>
  452. <Option value={5}>opt5</Option>
  453. <Option value={6}>opt6</Option>
  454. <Option value={7}>opt7</Option>
  455. <Option value="8">opt8</Option>
  456. <Option value={9}>opt9</Option>
  457. <Option value={10}>opt10dfsdfsdfdsfdsfsdf</Option>
  458. <Option value={11}>opt11</Option>
  459. <Option value="12">opt12jfldsjflsdjlfldjslfjhifsdfdsfdsffdsodsjlfhjl</Option>
  460. </Select>
  461. );
  462. WithScrollbar.story = {
  463. name: 'with scrollbar',
  464. };
  465. class Link extends React.Component {
  466. get provinces() {
  467. return ['Sichuan', 'Guangdong'];
  468. }
  469. get maps() {
  470. return {
  471. Sichuan: ['Chengdu', 'Dujiangyan'],
  472. Guangdong: ['Guangzhou', 'Shenzhen', 'Dongguan'],
  473. };
  474. }
  475. constructor() {
  476. super();
  477. this.state = {
  478. provinces: this.provinces,
  479. maps: this.maps,
  480. citys: this.maps[this.provinces[0]],
  481. city: this.maps[this.provinces[0]][0],
  482. };
  483. this.provinceChange = this.provinceChange.bind(this);
  484. this.cityChange = this.cityChange.bind(this);
  485. }
  486. provinceChange(newProvince) {
  487. const { maps } = this.state;
  488. this.setState({
  489. citys: maps[newProvince],
  490. city: maps[newProvince][0],
  491. });
  492. }
  493. cityChange(city) {
  494. this.setState({
  495. city,
  496. });
  497. }
  498. render() {
  499. const { provinces, citys, city } = this.state;
  500. return (
  501. <React.Fragment>
  502. <Select
  503. style={{
  504. width: '150px',
  505. margin: '10px',
  506. }}
  507. onChange={this.provinceChange}
  508. defaultValue={provinces[0]}
  509. >
  510. {provinces.map(pro => (
  511. <Option value={pro} key={pro}>
  512. {pro}
  513. </Option>
  514. ))}
  515. </Select>
  516. <Select
  517. style={{
  518. width: '150px',
  519. margin: '10px',
  520. }}
  521. value={city}
  522. onChange={this.cityChange}
  523. >
  524. {citys.map(c => (
  525. <Option value={c} key={c}>
  526. {c}
  527. </Option>
  528. ))}
  529. </Select>
  530. </React.Fragment>
  531. );
  532. }
  533. }
  534. export const TwoSelectChangeAtTheSameTime = () => <Link />;
  535. TwoSelectChangeAtTheSameTime.story = {
  536. name: 'two select change at the same time',
  537. };
  538. export const SelectMultiple = () => (
  539. <>
  540. <Select
  541. multiple={true}
  542. max={10}
  543. style={{
  544. width: '180px',
  545. }}
  546. placeholder="fefe"
  547. >
  548. <Option value={1}>opt1</Option>
  549. <Option value={2}>opt2</Option>
  550. <Option value={3}>opt3</Option>
  551. <Option value="4">opt4</Option>
  552. <Option value={5}>opt5</Option>
  553. <Option value={6}>opt6</Option>
  554. <Option value={7}>opt7</Option>
  555. <Option value={8}>opt8</Option>
  556. </Select>
  557. <br />
  558. <br />
  559. <Select
  560. multiple={true}
  561. style={{
  562. width: '300px',
  563. }}
  564. defaultValue={[1, 2, 3]}
  565. placeholder="fefe"
  566. >
  567. <Option value={1}>opt1</Option>
  568. <Option value={2}>opt2</Option>
  569. <Option value={3}>opt3</Option>
  570. <Option value="4">opt4</Option>
  571. <Option value={5}>opt5</Option>
  572. <Option value={6}>opt6</Option>
  573. <Option value={7}>opt7</Option>
  574. <Option value={8}>opt8</Option>
  575. </Select>
  576. <br />
  577. <br />
  578. <Select
  579. multiple={true}
  580. style={{
  581. width: '300px',
  582. }}
  583. defaultValue={[1, 2, 3]}
  584. placeholder="fefe"
  585. disabled
  586. onSelect={(...res) => console.log(res)}
  587. onDeselect={(...res) => console.log(res)}
  588. >
  589. <Option value={1}>opt1</Option>
  590. <Option value={2}>opt2</Option>
  591. <Option value={3}>opt3</Option>
  592. <Option value="4">opt4</Option>
  593. <Option value={5}>opt5</Option>
  594. <Option value={6}>opt6</Option>
  595. <Option value={7}>opt7</Option>
  596. <Option value={8}>opt8</Option>
  597. </Select>
  598. <br />
  599. <br />
  600. maxTagCount = 3
  601. <br />
  602. <Select
  603. multiple={true}
  604. maxTagCount={3}
  605. style={{
  606. width: '350px',
  607. }}
  608. defaultValue={[1, 2, 3]}
  609. placeholder="fefe"
  610. insetLabel="标签"
  611. onSelect={(...res) => console.log(res)}
  612. onDeselect={(...res) => console.log(res)}
  613. >
  614. <Option value={1}>opt1</Option>
  615. <Option value={2}>opt2</Option>
  616. <Option value={3}>opt3</Option>
  617. <Option value="4">opt4</Option>
  618. <Option value={5}>opt5</Option>
  619. <Option value={6}>opt6</Option>
  620. <Option value={7}>opt7</Option>
  621. <Option value={8}>opt8</Option>
  622. </Select>
  623. <br />
  624. <br />
  625. maxTagCount = 3, showRestTagsPopover
  626. <br />
  627. <Select
  628. multiple={true}
  629. maxTagCount={3}
  630. style={{
  631. width: '350px',
  632. }}
  633. defaultValue={[1, 2, 3]}
  634. placeholder="fefe"
  635. insetLabel="标签"
  636. onSelect={(...res) => console.log(res)}
  637. onDeselect={(...res) => console.log(res)}
  638. showRestTagsPopover={true}
  639. >
  640. <Option value={1}>opt1</Option>
  641. <Option value={2}>opt2</Option>
  642. <Option value={3}>opt3</Option>
  643. <Option value="4">opt4</Option>
  644. <Option value={5}>opt5</Option>
  645. <Option value={6}>opt6</Option>
  646. <Option value={7}>opt7</Option>
  647. <Option value={8}>opt8</Option>
  648. </Select>
  649. <br />
  650. <br />
  651. maxTagCount = 3, max=5
  652. <br />
  653. <Select
  654. multiple={true}
  655. maxTagCount={3}
  656. max={5}
  657. style={{
  658. width: '350px',
  659. }}
  660. defaultValue={[1, 2, 3]}
  661. placeholder="fefe"
  662. insetLabel="标签"
  663. onSelect={(...res) => console.log(res)}
  664. onDeselect={(...res) => console.log(res)}
  665. >
  666. <Option value={1}>opt1</Option>
  667. <Option value={2}>opt2</Option>
  668. <Option value={3}>opt3</Option>
  669. <Option value="4">opt4</Option>
  670. <Option value={5}>opt5</Option>
  671. <Option value={6}>opt6</Option>
  672. <Option value={7}>opt7</Option>
  673. <Option value={8}>opt8</Option>
  674. </Select>
  675. </>
  676. );
  677. SelectMultiple.story = {
  678. name: 'select multiple',
  679. };
  680. SelectMultiple.parameters = {
  681. chromatic: { disableSnapshot: false },
  682. };
  683. export const SelectDisabled = () => (
  684. <Select
  685. disabled
  686. multiple={true}
  687. max={10}
  688. style={{
  689. width: '250px',
  690. }}
  691. >
  692. <Option value={1}>opt1</Option>
  693. <Option value={2} disabled>
  694. opt2
  695. </Option>
  696. <Option value={3}>opt3</Option>
  697. <Option value="4">opt4</Option>
  698. </Select>
  699. );
  700. SelectDisabled.story = {
  701. name: 'select disabled',
  702. };
  703. function filter(input, option) {
  704. console.log(option);
  705. return option.label.includes(input);
  706. }
  707. const spanStyle = {
  708. display: 'inline-block',
  709. marginRight: '8px',
  710. width: '16px',
  711. height: '16px',
  712. borderRadius: '50%',
  713. border: '1px solid var(--semi-color-bg-1)',
  714. };
  715. const colorOptions = [
  716. {
  717. value: 'grey-1',
  718. spanStyle: { ...spanStyle, backgroundColor: 'rgb(107, 116, 117)' },
  719. },
  720. {
  721. value: 'purple-5',
  722. spanStyle: { ...spanStyle, backgroundColor: 'rgb(158, 40, 179)' },
  723. },
  724. {
  725. value: 'pink-2',
  726. spanStyle: { ...spanStyle, backgroundColor: 'rgb(233, 30, 99)' },
  727. },
  728. {
  729. value: 'blue-3',
  730. spanStyle: { ...spanStyle, backgroundColor: 'rgb(0, 119, 250)' },
  731. },
  732. ];
  733. const alignStyle = {
  734. display: 'flex',
  735. alignItems: 'center',
  736. };
  737. const customFilter = (input, option) => {
  738. return option.value.includes(input);
  739. };
  740. export const SelectFilterSingle = () => (
  741. <div>
  742. <h5>默认筛选</h5>
  743. <Select
  744. filter
  745. style={{
  746. width: '250px',
  747. margin: 10,
  748. }}
  749. showClear
  750. autoFocus
  751. onSearch={(val) => console.log(`onSearch:${val}`)}
  752. onFocus={() => console.log('onFocus')}
  753. onBlur={() => console.log('onBlur')}
  754. >
  755. <Option value={1}>opt1</Option>
  756. <Option value={2} disabled>
  757. disabled
  758. </Option>
  759. <Option value={3}>Lucy</Option>
  760. <Option value="4">bay</Option>
  761. <Option value="5">sert</Option>
  762. <Option value="6">wym</Option>
  763. <Option value="7" disabled>
  764. meno
  765. </Option>
  766. <Option value="8">opts</Option>
  767. </Select>
  768. <h5>自定义筛选函数</h5>
  769. <Select
  770. style={{
  771. width: '250px',
  772. margin: 10,
  773. }}
  774. filter={filter}
  775. showClear
  776. onBlur={() => console.log('onBlur')}
  777. onSearch={val => console.log(val)}
  778. onFocus={() => console.log('onFocus')}
  779. >
  780. <Option value={1}>opt1(value:1)</Option>
  781. <Option value={2}>mike(value:2)</Option>
  782. <Option value={3}>Lucy(value:3)</Option>
  783. <Option value={4}>bay(value:4)</Option>
  784. </Select>
  785. <h5>filter为true,但option label为node时</h5>
  786. <Select
  787. style={{
  788. width: '250px',
  789. margin: 10,
  790. }}
  791. showClear
  792. filter={customFilter}
  793. onChange={v => console.log(v)}
  794. insetLabel="insetLabel"
  795. onFocus={() => console.log('onFocus')}
  796. onBlur={() => console.log('onBlur')}
  797. onSearch={(val) => console.log(val)}
  798. >
  799. {colorOptions.map(option => (
  800. <Option value={option.value} key={option.value}>
  801. <div style={alignStyle}>
  802. <span style={option.spanStyle}></span>
  803. {option.value}
  804. </div>
  805. </Option>
  806. ))}
  807. </Select>
  808. </div>
  809. );
  810. SelectFilterSingle.story = {
  811. name: 'select filter single',
  812. };
  813. export const SelectFilterMultiple = () => (
  814. <>
  815. <Select
  816. filter
  817. multiple={true}
  818. style={{
  819. width: '250px',
  820. }}
  821. placeholder="fefe"
  822. >
  823. <Option value={1}>opt1</Option>
  824. <Option value={2}>opt2</Option>
  825. <Option value={3}>opt22</Option>
  826. <Option value={3}>opt3</Option>
  827. <Option value={4}>opt4</Option>
  828. <Option value={5}>opt5</Option>
  829. <Option value={6}>opt6</Option>
  830. <Option value={7}>opt7</Option>
  831. <Option value={8}>opt8</Option>
  832. </Select>
  833. <Select
  834. filter
  835. multiple={true}
  836. maxTagCount={3}
  837. style={{
  838. width: '270px',
  839. }}
  840. placeholder="fefe"
  841. >
  842. <Option value={1}>opt1</Option>
  843. <Option value={2}>opt2</Option>
  844. <Option value={3}>opt22</Option>
  845. <Option value={3}>opt3</Option>
  846. <Option value={4}>opt4</Option>
  847. <Option value={5}>opt5</Option>
  848. <Option value={6}>opt6</Option>
  849. <Option value={7}>opt7</Option>
  850. <Option value={8}>opt8</Option>
  851. </Select>
  852. </>
  853. );
  854. SelectFilterMultiple.story = {
  855. name: 'select filter multiple',
  856. };
  857. const OptionLabelProp = () => {
  858. const [value, setValue] = useState(1);
  859. return (
  860. <>
  861. 设置optionLabelProp属性(默认为'children')为'value'时,回填到选择框中的文本会是Option.value
  862. <br></br>
  863. <Select
  864. style={{
  865. width: '250px',
  866. }}
  867. defaultValue={1}
  868. optionLabelProp="value"
  869. >
  870. <Option value={1}>opt1</Option>
  871. <Option value={2}>opt2</Option>
  872. <Option value={3}>
  873. <span
  874. style={{
  875. color: 'pink',
  876. }}
  877. >
  878. opt3 Node
  879. </span>
  880. </Option>
  881. <Option value="4">
  882. <span
  883. style={{
  884. color: 'red',
  885. }}
  886. >
  887. testNode
  888. </span>
  889. </Option>
  890. </Select>
  891. <br />
  892. <br />
  893. <Select
  894. style={{
  895. width: '250px',
  896. }}
  897. value={value}
  898. optionLabelProp="value"
  899. onChange={setValue}
  900. >
  901. <Option value={1}>opt1</Option>
  902. <Option value={2}>opt2</Option>
  903. <Option value={3}>
  904. <span
  905. style={{
  906. color: 'pink',
  907. }}
  908. >
  909. opt3 Node
  910. </span>
  911. </Option>
  912. <Option value="4">
  913. <span
  914. style={{
  915. color: 'red',
  916. }}
  917. >
  918. testNode
  919. </span>
  920. </Option>
  921. </Select>
  922. <br />
  923. <br />
  924. <Select
  925. style={{
  926. width: '250px',
  927. }}
  928. defaultValue={1}
  929. >
  930. <Option value={1}>children Label Text 1</Option>
  931. <Option value={2}>opt2</Option>
  932. <Option value={3}>opt3</Option>
  933. <Option value="4">
  934. <span
  935. style={{
  936. color: 'red',
  937. }}
  938. >
  939. testNode
  940. </span>
  941. </Option>
  942. </Select>
  943. <Select
  944. style={{
  945. width: '250px',
  946. }}
  947. defaultValue={1}
  948. filter
  949. optionLabelProp="value"
  950. >
  951. <Option value={1}>children Label Text 1</Option>
  952. <Option value={2}>opt2</Option>
  953. <Option value={3}>opt3</Option>
  954. <Option value="4">
  955. <span
  956. style={{
  957. color: 'red',
  958. }}
  959. >
  960. testNode
  961. </span>
  962. </Option>
  963. </Select>
  964. <br />
  965. <br />
  966. 多选
  967. <Select
  968. style={{
  969. width: '250px',
  970. }}
  971. multiple
  972. filter
  973. optionLabelProp="value"
  974. >
  975. <Option value={1}>children Label Text 1</Option>
  976. <Option value={2}>opt2</Option>
  977. <Option value={3}>opt3</Option>
  978. <Option value="4">
  979. <span
  980. style={{
  981. color: 'red',
  982. }}
  983. >
  984. testNode
  985. </span>
  986. </Option>
  987. </Select>
  988. </>
  989. );
  990. };
  991. class CustomRender extends React.Component {
  992. constructor() {
  993. super();
  994. this.state = {
  995. list: [
  996. {
  997. name: '夏可漫',
  998. email: '[email protected]',
  999. abbr: 'XK',
  1000. color: 'amber',
  1001. },
  1002. {
  1003. name: '申悦',
  1004. email: '[email protected]',
  1005. abbr: 'SY',
  1006. color: 'indigo',
  1007. },
  1008. {
  1009. name: '曲晨一',
  1010. email: '[email protected]',
  1011. abbr: 'CY',
  1012. color: 'blue',
  1013. },
  1014. {
  1015. name: '文嘉茂',
  1016. email: '[email protected]',
  1017. abbr: 'JM',
  1018. color: 'cyan',
  1019. },
  1020. ],
  1021. };
  1022. }
  1023. renderCustomOption(item, index) {
  1024. const optionStyle = {
  1025. display: 'flex',
  1026. };
  1027. return (
  1028. <Option key={index} value={item.name} style={optionStyle} showTick={false} {...item}>
  1029. <Avatar color={item.color} size="small">
  1030. {item.abbr}
  1031. </Avatar>
  1032. <div
  1033. style={{
  1034. marginLeft: 4,
  1035. }}
  1036. >
  1037. <p
  1038. style={{
  1039. fontSize: 14,
  1040. margin: 4,
  1041. }}
  1042. >
  1043. {item.name}
  1044. </p>
  1045. <p
  1046. style={{
  1047. margin: 4,
  1048. }}
  1049. >
  1050. {item.email}
  1051. </p>
  1052. </div>
  1053. </Option>
  1054. );
  1055. }
  1056. renderSelectedItem(optionNode) {
  1057. return (
  1058. <div>
  1059. <Avatar color={optionNode.color} size="small">
  1060. {optionNode.abbr}
  1061. </Avatar>
  1062. <span
  1063. style={{
  1064. margin: 8,
  1065. }}
  1066. >
  1067. {optionNode.email}
  1068. </span>
  1069. </div>
  1070. );
  1071. }
  1072. renderMultipleSelectedItem(optionNode) {
  1073. let content = (
  1074. <div>
  1075. <Avatar color={optionNode.color} size="small">
  1076. {optionNode.abbr}
  1077. </Avatar>
  1078. </div>
  1079. );
  1080. return {
  1081. isRenderInTag: true,
  1082. content,
  1083. };
  1084. }
  1085. renderMultipleWithoutTag(optionNode) {
  1086. let content = (
  1087. <div>
  1088. <Avatar color={optionNode.color} size="small">
  1089. {optionNode.abbr}
  1090. </Avatar>
  1091. </div>
  1092. );
  1093. return {
  1094. isRenderInTag: false,
  1095. content,
  1096. };
  1097. }
  1098. render() {
  1099. const { list } = this.state;
  1100. return (
  1101. <React.Fragment>
  1102. <Select
  1103. style={{
  1104. width: 300,
  1105. height: 40,
  1106. }}
  1107. onChange={this.provinceChange}
  1108. defaultValue={'夏可漫'}
  1109. renderSelectedItem={this.renderSelectedItem}
  1110. >
  1111. {list.map((item, index) => this.renderCustomOption(item, index))}
  1112. </Select>
  1113. <Select
  1114. style={{
  1115. width: 360,
  1116. height: 60,
  1117. marginTop: 20,
  1118. }}
  1119. onChange={this.provinceChange}
  1120. defaultValue={['夏可漫', '申悦']}
  1121. multiple
  1122. renderSelectedItem={this.renderMultipleSelectedItem}
  1123. >
  1124. {list.map((item, index) => this.renderCustomOption(item, index))}
  1125. </Select>
  1126. <Select
  1127. style={{
  1128. width: 360,
  1129. height: 60,
  1130. marginTop: 20,
  1131. }}
  1132. onChange={this.provinceChange}
  1133. defaultValue={['夏可漫', '申悦']}
  1134. multiple
  1135. renderSelectedItem={this.renderMultipleWithoutTag}
  1136. >
  1137. {list.map((item, index) => this.renderCustomOption(item, index))}
  1138. </Select>
  1139. </React.Fragment>
  1140. );
  1141. }
  1142. }
  1143. export const RenderSelectedItem = () => (
  1144. <>
  1145. renderSelectedItem
  1146. <CustomRender />
  1147. <br />
  1148. <br />
  1149. OptionLabelProp
  1150. <OptionLabelProp />
  1151. </>
  1152. );
  1153. RenderSelectedItem.story = {
  1154. name: 'renderSelectedItem',
  1155. };
  1156. RenderSelectedItem.parameters = {
  1157. chromatic: { disableSnapshot: false },
  1158. };
  1159. const ControlledSelect = () => {
  1160. const [value, setValue] = useState('nick');
  1161. const [value2, setValue2] = useState('jerry');
  1162. const [value3, setValue3] = useState();
  1163. const [value4, setValue4] = useState(['nick']);
  1164. const [value5, setValue5] = useState();
  1165. return (
  1166. <>
  1167. <span>value + onChange</span>
  1168. <Select
  1169. value={value}
  1170. onChange={setValue}
  1171. style={{
  1172. width: 200,
  1173. }}
  1174. >
  1175. <Option value="nick">nick</Option>
  1176. <Option value="jerry">jerry</Option>
  1177. <Option value="mark">mark</Option>
  1178. </Select>
  1179. <br />
  1180. <br />
  1181. <span>只传value,不传onChange</span>
  1182. <Select
  1183. value={value2}
  1184. style={{
  1185. width: 200,
  1186. }}
  1187. >
  1188. <Option value="nick">nick</Option>
  1189. <Option value="jerry">jerry</Option>
  1190. <Option value="mark">mark</Option>
  1191. </Select>
  1192. <br />
  1193. <br />
  1194. <span>value + onChange , 多选</span>
  1195. <Select
  1196. value={value3}
  1197. onChange={setValue3}
  1198. multiple
  1199. style={{
  1200. width: 200,
  1201. }}
  1202. >
  1203. <Option value="nick">nick</Option>
  1204. <Option value="jerry">jerry</Option>
  1205. <Option value="mark">mark</Option>
  1206. <Option value="nick2">nick2</Option>
  1207. <Option value="jerry2">jerry2</Option>
  1208. <Option value="mark2">mark2</Option>
  1209. </Select>
  1210. <br />
  1211. <br />
  1212. <span>value, 多选</span>
  1213. <Select
  1214. value={value4}
  1215. multiple
  1216. style={{
  1217. width: 200,
  1218. }}
  1219. >
  1220. <Option value="nick">nick</Option>
  1221. <Option value="jerry">jerry</Option>
  1222. <Option value="mark">mark</Option>
  1223. </Select>
  1224. <br />
  1225. <h5>filter为true,但option label为node时</h5>
  1226. <Select
  1227. style={{
  1228. width: '250px',
  1229. }}
  1230. filter={customFilter}
  1231. insetLabel="insetLabel"
  1232. value={value5}
  1233. onChange={setValue5}
  1234. >
  1235. {colorOptions.map(option => (
  1236. <Option value={option.value} key={option.value}>
  1237. <div style={alignStyle}>
  1238. <span style={option.spanStyle}></span>
  1239. {option.value}
  1240. </div>
  1241. </Option>
  1242. ))}
  1243. </Select>
  1244. </>
  1245. );
  1246. };
  1247. export const Controlled = () => <ControlledSelect></ControlledSelect>;
  1248. Controlled.story = {
  1249. name: 'controlled',
  1250. };
  1251. const UnControlledSelect = () => {
  1252. const onChange = value => {
  1253. console.log(value);
  1254. };
  1255. return (
  1256. <>
  1257. <h5>defaultValue在list中不存在</h5>
  1258. <Select
  1259. defaultValue={90}
  1260. onChange={onChange}
  1261. style={{
  1262. width: 200,
  1263. }}
  1264. >
  1265. <Option value={20}>nick</Option>
  1266. <Option value={10}>jerry</Option>
  1267. <Option value={5}>mark</Option>
  1268. </Select>
  1269. <h5>defaultValue在list中存在</h5>
  1270. <Select
  1271. defaultValue={10}
  1272. onChange={onChange}
  1273. style={{
  1274. width: 200,
  1275. }}
  1276. >
  1277. <Option value={20}>nick</Option>
  1278. <Option value={10}>jerry</Option>
  1279. <Option value={5}>mark</Option>
  1280. </Select>
  1281. </>
  1282. );
  1283. };
  1284. export { UnControlledSelect };
  1285. UnControlledSelect.story = {
  1286. name: '非受控组件'
  1287. };
  1288. export const TestScroll = () => (
  1289. <div
  1290. style={{
  1291. marginTop: '600px',
  1292. marginBottom: '50px',
  1293. }}
  1294. >
  1295. <Select
  1296. style={{
  1297. width: '150px',
  1298. }}
  1299. >
  1300. <Option value="tony">IronMan</Option>
  1301. <Option value="Thor" disabled>
  1302. Thor
  1303. </Option>
  1304. <Option value="steve">Caption</Option>
  1305. <Option value="peter">SpiderBoy</Option>
  1306. </Select>
  1307. </div>
  1308. );
  1309. TestScroll.story = {
  1310. name: 'test scroll',
  1311. };
  1312. let optionList = [
  1313. {
  1314. value: 'tony',
  1315. label: 'Ironman',
  1316. },
  1317. {
  1318. value: 'Thor',
  1319. label: 'Thor',
  1320. },
  1321. {
  1322. value: 'steve',
  1323. label: 'Caption',
  1324. },
  1325. {
  1326. value: 'peter',
  1327. label: 'SpiderBoy',
  1328. },
  1329. ];
  1330. export const OptionList = () => (
  1331. <Select
  1332. style={{
  1333. width: '100px',
  1334. }}
  1335. optionList={optionList}
  1336. ></Select>
  1337. );
  1338. OptionList.story = {
  1339. name: 'optionList',
  1340. };
  1341. export const InsetLabel = () => (
  1342. <>
  1343. <Select
  1344. style={{
  1345. width: 300,
  1346. }}
  1347. insetLabel="主播类型"
  1348. placeholder="请选择"
  1349. optionList={optionList}
  1350. ></Select>
  1351. <Select
  1352. style={{
  1353. width: 300,
  1354. }}
  1355. multiple
  1356. insetLabel="主播类型"
  1357. optionList={optionList}
  1358. ></Select>
  1359. <Select
  1360. style={{
  1361. width: 300,
  1362. }}
  1363. filter
  1364. insetLabel="主播类型"
  1365. optionList={optionList}
  1366. ></Select>
  1367. <Select
  1368. style={{
  1369. width: 300,
  1370. }}
  1371. filter
  1372. multiple
  1373. insetLabel="主播类型"
  1374. optionList={optionList}
  1375. ></Select>
  1376. </>
  1377. );
  1378. InsetLabel.story = {
  1379. name: 'insetLabel',
  1380. };
  1381. export const ChangeOptionDynamic = () => {
  1382. function App() {
  1383. let [options, setOptions] = useState([]);
  1384. let [index, setIndex] = useState(0);
  1385. const addOption = () => {
  1386. const randomItem = optionList[index];
  1387. index = index + 1;
  1388. setIndex(index);
  1389. options = [...options, { ...randomItem }];
  1390. setOptions(options);
  1391. };
  1392. const reset = () => {
  1393. setOptions([]);
  1394. setIndex(0);
  1395. };
  1396. return (
  1397. <div>
  1398. <Select
  1399. style={{
  1400. width: '150px',
  1401. }}
  1402. defaultValue="tony"
  1403. >
  1404. {options.map((option, idx) => (
  1405. <Select.Option key={option.key || idx} value={option.value}>
  1406. {option.label}
  1407. </Select.Option>
  1408. ))}
  1409. </Select>
  1410. <h4>多选</h4>
  1411. <Select
  1412. style={{
  1413. width: '150px',
  1414. }}
  1415. multiple
  1416. defaultValue={['tony']}
  1417. >
  1418. {options.map((option, idx) => (
  1419. <Select.Option key={option.key || idx} value={option.value}>
  1420. {option.label}
  1421. </Select.Option>
  1422. ))}
  1423. </Select>
  1424. <button onClick={addOption}>add option</button>
  1425. <button onClick={reset}>reset</button>
  1426. </div>
  1427. );
  1428. }
  1429. return <App />;
  1430. };
  1431. ChangeOptionDynamic.story = {
  1432. name: 'change option dynamic',
  1433. };
  1434. let list = [
  1435. {
  1436. value: 'tony',
  1437. label: 'Ironman',
  1438. otherKey: {
  1439. role: 1,
  1440. },
  1441. },
  1442. {
  1443. value: 'Thor',
  1444. label: 'Thor',
  1445. otherKey: {
  1446. role: 2,
  1447. },
  1448. },
  1449. {
  1450. value: 'steve',
  1451. label: 'Caption',
  1452. otherKey: {
  1453. role: 3,
  1454. },
  1455. },
  1456. {
  1457. value: 'peter',
  1458. label: 'SpiderBoy',
  1459. otherKey: {
  1460. role: 4,
  1461. },
  1462. },
  1463. ];
  1464. const SearchDemo1 = () => {
  1465. const [optionList, setOptionList] = useState(list);
  1466. const [loading, setLoading] = useState(false);
  1467. const handleSearch = value => {
  1468. setLoading(true);
  1469. let length = Math.ceil(Math.random() * 10);
  1470. let result = Array.from(
  1471. {
  1472. length,
  1473. },
  1474. (v, i) => {
  1475. return {
  1476. value: value + i,
  1477. label: value + i,
  1478. otherKey: {
  1479. role: i,
  1480. },
  1481. };
  1482. }
  1483. );
  1484. setTimeout(() => {
  1485. setOptionList(result);
  1486. setLoading(false);
  1487. }, 1000);
  1488. };
  1489. const [value, setValue] = useState(optionList[0].value);
  1490. const onChange = value => {
  1491. console.log(value);
  1492. setValue(value);
  1493. };
  1494. return (
  1495. <div>
  1496. 受控:
  1497. <Select
  1498. filter
  1499. style={{
  1500. width: '150px',
  1501. }}
  1502. onSearch={v => handleSearch(v)}
  1503. optionList={optionList}
  1504. value={value}
  1505. loading={loading}
  1506. showClear
  1507. onChange={onChange}
  1508. ></Select>
  1509. 非受控:
  1510. <Select
  1511. style={{
  1512. width: '150px',
  1513. }}
  1514. filter
  1515. showClear
  1516. onSearch={v => handleSearch(v)}
  1517. optionList={optionList}
  1518. loading={loading}
  1519. onChange={onChange}
  1520. ></Select>
  1521. 多选非受控
  1522. <Select
  1523. style={{
  1524. width: '150px',
  1525. }}
  1526. showClear
  1527. filter
  1528. multiple
  1529. onSearch={v => handleSearch(v)}
  1530. optionList={optionList}
  1531. loading={loading}
  1532. onChange={onChange}
  1533. ></Select>
  1534. </div>
  1535. );
  1536. };
  1537. import debounce from 'lodash/debounce';
  1538. class SearchDemo2 extends React.Component {
  1539. constructor() {
  1540. super();
  1541. this.state = {
  1542. loading: false,
  1543. optionList: [
  1544. {
  1545. value: 'abc',
  1546. label: '抖音',
  1547. type: 1,
  1548. },
  1549. {
  1550. value: 'hotsoon',
  1551. label: '火山小视频',
  1552. type: 2,
  1553. },
  1554. {
  1555. value: 'pipixia',
  1556. label: '皮皮虾',
  1557. type: 3,
  1558. },
  1559. {
  1560. value: 'toutiao',
  1561. label: '今日头条',
  1562. type: 4,
  1563. },
  1564. ],
  1565. value: [],
  1566. };
  1567. this.handleSearch = debounce(this.handleSearch, 800).bind(this);
  1568. this.onChange = this.onChange.bind(this);
  1569. this.customRender = this.customRender.bind(this);
  1570. }
  1571. handleSearch(inputValue) {
  1572. this.setState({
  1573. loading: true,
  1574. });
  1575. let length = Math.ceil(Math.random() * 100);
  1576. let result = Array.from(
  1577. {
  1578. length,
  1579. },
  1580. (v, i) => {
  1581. return {
  1582. value: inputValue + i,
  1583. label: 'label' + i,
  1584. type: i + 1,
  1585. };
  1586. }
  1587. );
  1588. setTimeout(() => {
  1589. this.setState({
  1590. optionList: result,
  1591. loading: false,
  1592. });
  1593. }, 2000);
  1594. }
  1595. onChange(value) {
  1596. this.setState({
  1597. value,
  1598. });
  1599. console.log(value);
  1600. }
  1601. customRender(optionNode) {
  1602. return optionNode.value + optionNode.label;
  1603. }
  1604. render() {
  1605. const { loading, optionList, value } = this.state;
  1606. return (
  1607. <div>
  1608. <Select
  1609. style={{
  1610. width: 150,
  1611. }}
  1612. showClear
  1613. filter
  1614. labelInValue
  1615. onSearch={this.handleSearch}
  1616. optionList={optionList}
  1617. loading={loading}
  1618. onChange={this.onChange}
  1619. placeholder="请选择"
  1620. ></Select>
  1621. <br />
  1622. <br />
  1623. <Select
  1624. style={{
  1625. width: 180,
  1626. }}
  1627. filter // labelInValue
  1628. showClear
  1629. multiple
  1630. value={value}
  1631. renderSelectedItem={this.customRender}
  1632. onSearch={this.handleSearch}
  1633. optionList={optionList}
  1634. loading={loading}
  1635. onChange={this.onChange}
  1636. placeholder="请选择"
  1637. ></Select>
  1638. </div>
  1639. );
  1640. }
  1641. }
  1642. export const Search = () => (
  1643. <>
  1644. <SearchDemo1 />
  1645. <SearchDemo2 />
  1646. </>
  1647. );
  1648. Search.story = {
  1649. name: 'search',
  1650. };
  1651. export const IncomeDetail = ({ config = {}, params = {} }) => {
  1652. const [detailList, setDetailList] = useState([]);
  1653. const [hasMore, setHasMore] = useState(true);
  1654. const [loading, setLoading] = useState();
  1655. let lock;
  1656. const fetchData = (outParams = {}) => {
  1657. if (lock) {
  1658. return;
  1659. }
  1660. setLoading(true); // 参数
  1661. // 请求
  1662. fetch({
  1663. url: URL.user_profit,
  1664. method: 'get',
  1665. baseURL: config.webcast_host,
  1666. params,
  1667. })
  1668. .then(res => {
  1669. lock = false;
  1670. setLoading(false);
  1671. console.log('++++', data);
  1672. })
  1673. .catch(() => {
  1674. setLoading(false);
  1675. Toast.show('网络异常,请稍后重试');
  1676. });
  1677. };
  1678. useEffect(fetchData, []); // 监听滚动设置吸顶 以及加载更多
  1679. useEffect(() => {
  1680. window.addEventListener('scroll', function() {
  1681. // 加载更多
  1682. const scrollY = window.scrollY;
  1683. const scrollHeight = document.documentElement.scrollHeight;
  1684. const screenHeight = screen.height;
  1685. if (!loading && hasMore && scrollY + screenHeight + 300 > scrollHeight) {
  1686. fetchData();
  1687. }
  1688. });
  1689. }, [detailList.length]);
  1690. return (
  1691. <div>
  1692. <Select></Select>
  1693. </div>
  1694. );
  1695. };
  1696. export const AllowCreate = () => (
  1697. <Select
  1698. style={{
  1699. width: 500,
  1700. }}
  1701. optionList={optionList}
  1702. allowCreate={true}
  1703. multiple={true}
  1704. filter={true}
  1705. onChange={v => console.log(v)}
  1706. ></Select>
  1707. );
  1708. AllowCreate.story = {
  1709. name: 'allowCreate',
  1710. };
  1711. export const AllowCreateCustomRender = () => (
  1712. <Select
  1713. style={{
  1714. width: 500,
  1715. }}
  1716. optionList={optionList}
  1717. allowCreate={true}
  1718. multiple={true}
  1719. filter={true}
  1720. onChange={v => console.log(v)}
  1721. renderCreateItem={v => `semi: ${v}`}
  1722. ></Select>
  1723. );
  1724. AllowCreateCustomRender.story = {
  1725. name: 'allowCreate custom render',
  1726. };
  1727. let AllowCreateControlledDemo = () => {
  1728. let [value, setValue] = useState();
  1729. const optionList = [
  1730. {
  1731. value: 'abc',
  1732. label: '抖音',
  1733. },
  1734. {
  1735. value: 'hotsoon',
  1736. label: '火山小视频',
  1737. },
  1738. {
  1739. value: 'pipixia',
  1740. label: '皮皮虾',
  1741. },
  1742. {
  1743. value: 'toutiao',
  1744. label: '今日头条',
  1745. },
  1746. ];
  1747. const [list, setList] = useState(optionList);
  1748. const handleSelect = v => {
  1749. var lastOne = v[v.length - 1];
  1750. if (lastOne && list.findIndex(item => item.value === lastOne) == -1) {
  1751. list.push({
  1752. value: lastOne,
  1753. label: lastOne,
  1754. });
  1755. }
  1756. setList(list);
  1757. setValue(v);
  1758. };
  1759. return (
  1760. <Select
  1761. style={{
  1762. width: 400,
  1763. }}
  1764. optionList={list}
  1765. allowCreate={true}
  1766. multiple={true}
  1767. filter={true}
  1768. value={value}
  1769. onChange={handleSelect}
  1770. ></Select>
  1771. );
  1772. };
  1773. const AllowCreateDemo = () => {
  1774. let [value, setValue] = useState();
  1775. const optionList = [
  1776. {
  1777. value: 'abc',
  1778. label: '抖音',
  1779. },
  1780. {
  1781. value: 'hotsoon',
  1782. label: '火山小视频',
  1783. },
  1784. {
  1785. value: 'pipixia',
  1786. label: '皮皮虾',
  1787. },
  1788. {
  1789. value: 'toutiao',
  1790. label: '今日头条',
  1791. },
  1792. ];
  1793. const [list, setList] = useState(optionList);
  1794. const handleSelect = v => {
  1795. var lastOne = v[v.length - 1];
  1796. if (lastOne && list.findIndex(item => item.value === lastOne) == -1) {
  1797. list.push({
  1798. value: lastOne,
  1799. label: lastOne,
  1800. });
  1801. }
  1802. setList(list); // setValue(v)
  1803. };
  1804. return (
  1805. <Select
  1806. style={{
  1807. width: 400,
  1808. }}
  1809. optionList={list}
  1810. defaultValue={['abc', 'hotsoon']}
  1811. allowCreate={true}
  1812. multiple={true}
  1813. filter={true}
  1814. onChange={handleSelect}
  1815. ></Select>
  1816. );
  1817. };
  1818. export const AllowCreateWithDefaultValue = () => <AllowCreateDemo />;
  1819. AllowCreateWithDefaultValue.story = {
  1820. name: 'allowCreate with defaultValue',
  1821. };
  1822. class HideDemo extends React.Component {
  1823. constructor(props) {
  1824. super(props);
  1825. this.state = {
  1826. optionList: [
  1827. {
  1828. value: 'abc',
  1829. label: '抖音',
  1830. },
  1831. {
  1832. value: 'hotsoon',
  1833. label: '火山小视频',
  1834. },
  1835. {
  1836. value: 'pipixia',
  1837. label: '皮皮虾',
  1838. },
  1839. {
  1840. value: 'toutiao',
  1841. label: '今日头条',
  1842. },
  1843. ],
  1844. selectedItems: [],
  1845. };
  1846. this.onChange = this.onChange.bind(this);
  1847. }
  1848. onChange(selectedItems) {
  1849. this.setState({
  1850. selectedItems,
  1851. });
  1852. }
  1853. render() {
  1854. let { optionList, selectedItems } = this.state;
  1855. let filterOptions = optionList.filter(option => !selectedItems.includes(option.value));
  1856. return (
  1857. <Select
  1858. value={selectedItems}
  1859. multiple
  1860. style={{
  1861. width: 300,
  1862. }}
  1863. onChange={this.onChange}
  1864. optionList={filterOptions}
  1865. ></Select>
  1866. );
  1867. }
  1868. }
  1869. export const AutoHiddenSelectedItem = () => <HideDemo></HideDemo>;
  1870. AutoHiddenSelectedItem.story = {
  1871. name: 'auto hidden selected item',
  1872. };
  1873. class CustomCreate extends React.Component {
  1874. constructor(props) {
  1875. super(props);
  1876. this.state = {
  1877. optionList: [
  1878. {
  1879. value: 'abc',
  1880. label: '抖音',
  1881. },
  1882. {
  1883. value: 'hotsoon',
  1884. label: '火山小视频',
  1885. },
  1886. {
  1887. value: 'pipixia',
  1888. label: '皮皮虾',
  1889. },
  1890. {
  1891. value: 'toutiao',
  1892. label: '今日头条',
  1893. },
  1894. {
  1895. value: 0,
  1896. label: 0,
  1897. },
  1898. ],
  1899. selectedItems: ['fefe'],
  1900. };
  1901. this.onChange = this.onChange.bind(this);
  1902. this.customRender = this.customRender.bind(this);
  1903. this.search = this.search.bind(this);
  1904. }
  1905. onChange(selectedItems) {
  1906. console.log(selectedItems); // this.setState({ selectedItems, optionList: [] });
  1907. this.setState({
  1908. selectedItems,
  1909. }); // this.setState({ optionList: [] });
  1910. }
  1911. customRender(v) {
  1912. return (
  1913. <>
  1914. <span>label:{v.label}</span>
  1915. <span>value:{v.value}</span>
  1916. </>
  1917. );
  1918. }
  1919. customCreate(inputValue, isFocus) {
  1920. let style = {
  1921. padding: 12,
  1922. cursor: 'pointer',
  1923. backgroundColor: isFocus ? 'var(--semi-color-fill-0)' : '#FFF',
  1924. };
  1925. return <div style={style}>{'create' + inputValue}</div>;
  1926. }
  1927. search(inputValue) {
  1928. let length = Math.ceil(Math.random() * 10);
  1929. let result = Array.from(
  1930. {
  1931. length,
  1932. },
  1933. (v, i) => {
  1934. return {
  1935. value: inputValue + i,
  1936. label: inputValue + i,
  1937. type: i + 1,
  1938. };
  1939. }
  1940. );
  1941. console.log(result); // result = result.concat(selectedOption);
  1942. this.setState({
  1943. optionList: result,
  1944. });
  1945. }
  1946. render() {
  1947. let { optionList, selectedItems } = this.state;
  1948. return (
  1949. <>
  1950. <Select
  1951. defaultValue={['abc']}
  1952. filter
  1953. style={{
  1954. width: 300,
  1955. }}
  1956. multiple
  1957. optionList={optionList}
  1958. onSearch={this.search}
  1959. onChange={this.onChange}
  1960. emptyContent={null} // onChangeWithObject
  1961. ></Select>
  1962. </>
  1963. );
  1964. }
  1965. }
  1966. export const _CustomCreate = () => <CustomCreate></CustomCreate>;
  1967. _CustomCreate.story = {
  1968. name: 'CustomCreate',
  1969. };
  1970. class OptionGroupDemo extends React.Component {
  1971. constructor(props) {
  1972. super(props);
  1973. this.handleSearch = this.handleSearch.bind(this);
  1974. this.state = {
  1975. groups: [
  1976. {
  1977. label: 'Asia',
  1978. children: [
  1979. {
  1980. label: 'China',
  1981. value: 'zhongguo',
  1982. },
  1983. {
  1984. label: 'Koera',
  1985. value: 'hanguo',
  1986. },
  1987. ],
  1988. },
  1989. {
  1990. label: 'Europe',
  1991. children: [
  1992. {
  1993. label: 'Germany',
  1994. value: 'deguo',
  1995. },
  1996. {
  1997. label: 'France',
  1998. value: 'faguo',
  1999. },
  2000. ],
  2001. },
  2002. {
  2003. label: 'Other',
  2004. children: [
  2005. {
  2006. label: 'vf',
  2007. value: 'Sourth',
  2008. },
  2009. ],
  2010. },
  2011. ],
  2012. };
  2013. }
  2014. handleSearch(input) {
  2015. let groups = [1, 2, 3].map(i => {
  2016. return {
  2017. label: i,
  2018. // label: Math.random(),
  2019. children: [10, 20].map(j => {
  2020. return {
  2021. label: Math.random(),
  2022. value: Math.random(),
  2023. };
  2024. }),
  2025. };
  2026. });
  2027. this.setState({
  2028. groups,
  2029. });
  2030. }
  2031. renderGroup(group, index) {
  2032. const options = group.children.map(option => (
  2033. <Select.Option value={option.value} label={option.label} key={option.label} />
  2034. ));
  2035. return <Select.OptGroup key={`${index}-${group.label}`} label={group.label}>{options}</Select.OptGroup>;
  2036. }
  2037. render() {
  2038. const { groups } = this.state;
  2039. return (
  2040. <>
  2041. <Select
  2042. placeholder=""
  2043. style={{
  2044. width: 180,
  2045. }}
  2046. filter
  2047. onSearch={this.handleSearch}
  2048. remote
  2049. >
  2050. {groups.map((group, index) => this.renderGroup(group, index))}
  2051. </Select>
  2052. </>
  2053. );
  2054. }
  2055. }
  2056. export const SelectOptionGroup = () => <OptionGroupDemo />;
  2057. SelectOptionGroup.story = {
  2058. name: 'Select OptionGroup',
  2059. };
  2060. const BlurDemo = () => {
  2061. const onBlur = (value, e) => {
  2062. console.log(value);
  2063. console.log(e);
  2064. };
  2065. const onFocus = (value, e) => {
  2066. console.log(value);
  2067. console.log(e);
  2068. };
  2069. return (
  2070. <>
  2071. <Select
  2072. filter
  2073. placeholder=""
  2074. style={{
  2075. width: 180,
  2076. }}
  2077. onBlur={onBlur}
  2078. onFocus={onFocus}
  2079. >
  2080. <Select.Option value="zhongguo">China</Select.Option>
  2081. <Select.Option value="hanguo">Koera</Select.Option>
  2082. <Select.Option value="deguo">Germany</Select.Option>
  2083. <Select.Option value="faguo">France</Select.Option>
  2084. </Select>
  2085. </>
  2086. );
  2087. };
  2088. export const SelectOnBlurOnFocus = () => <BlurDemo></BlurDemo>;
  2089. SelectOnBlurOnFocus.story = {
  2090. name: 'Select onBlur/onFocus',
  2091. };
  2092. const AutoAdjustOverflowDemo = () => {
  2093. const [list, setList] = useState([
  2094. {
  2095. value: 'abc',
  2096. label: '1111',
  2097. },
  2098. {
  2099. value: 'hotsoon',
  2100. label: '1112',
  2101. },
  2102. {
  2103. value: 'pipixia',
  2104. label: '1113',
  2105. },
  2106. {
  2107. value: 'toutiao',
  2108. label: '1114',
  2109. },
  2110. ]);
  2111. const onSearch = () => {
  2112. let newList = Array.from(
  2113. {
  2114. length: Math.floor(Math.random() * 10),
  2115. },
  2116. (v, i) => {
  2117. return {
  2118. value: i,
  2119. label: i,
  2120. };
  2121. }
  2122. );
  2123. setList(newList);
  2124. console.log(newList);
  2125. };
  2126. return (
  2127. <div
  2128. style={{
  2129. height: 180,
  2130. margin: 250,
  2131. border: '1px solid pink',
  2132. }}
  2133. >
  2134. <Select
  2135. optionList={list}
  2136. filter={true}
  2137. remote={true}
  2138. onSearch={onSearch}
  2139. style={{
  2140. width: 200,
  2141. }}
  2142. multiple
  2143. />
  2144. </div>
  2145. );
  2146. };
  2147. export const AutoAdjustOverflow = () => <AutoAdjustOverflowDemo></AutoAdjustOverflowDemo>;
  2148. AutoAdjustOverflow.story = {
  2149. name: 'autoAdjustOverflow',
  2150. };
  2151. const AllowCreateWithFilter = () => {
  2152. const [list, setList] = useState([
  2153. {
  2154. value: 'abc',
  2155. label: 'abc',
  2156. otherKey: 'abc',
  2157. },
  2158. {
  2159. value: 'hotsoon',
  2160. label: 'hotsoon',
  2161. otherKey: 'efg',
  2162. },
  2163. {
  2164. value: 'pipixia',
  2165. label: 'pipixia',
  2166. otherKey: 'hij',
  2167. },
  2168. {
  2169. value: 'toutiao',
  2170. label: 'toutiao',
  2171. otherKey: 'klm',
  2172. },
  2173. ]);
  2174. const filter = (sugInput, option) => {
  2175. let compareKey = option.otherKey ? option.otherKey.toUpperCase() : '';
  2176. let sug = sugInput.toUpperCase();
  2177. return compareKey.includes(sug);
  2178. };
  2179. return (
  2180. <div
  2181. style={{
  2182. height: 180,
  2183. margin: 250,
  2184. }}
  2185. >
  2186. <Select
  2187. optionList={list}
  2188. multiple
  2189. filter={filter}
  2190. style={{
  2191. width: 200,
  2192. }}
  2193. allowCreate
  2194. />
  2195. </div>
  2196. );
  2197. };
  2198. export const FilterAllowCreate = () => <AllowCreateWithFilter></AllowCreateWithFilter>;
  2199. FilterAllowCreate.story = {
  2200. name: 'Filter + allowCreate',
  2201. };
  2202. const SelectRefDemo = () => {
  2203. const ref = useRef();
  2204. const secondRef = useRef();
  2205. const [open, setOpen] = useState(false);
  2206. const list = [
  2207. {
  2208. value: 'abc',
  2209. label: 'Abc',
  2210. },
  2211. {
  2212. value: 'hotsoon',
  2213. label: 'Hotsoon',
  2214. },
  2215. {
  2216. value: 'pipixia',
  2217. label: 'Pipixia',
  2218. },
  2219. {
  2220. value: 'toutiao',
  2221. label: 'TooBuzz',
  2222. },
  2223. ];
  2224. const change = () => {
  2225. if (!open) {
  2226. ref.current.open();
  2227. setOpen(true);
  2228. } else {
  2229. ref.current.close();
  2230. setOpen(false);
  2231. }
  2232. };
  2233. const focus = () => {
  2234. ref.current.focus();
  2235. };
  2236. const clearInput = () => {
  2237. ref.current.clearInput();
  2238. };
  2239. const deselectAll = () => {
  2240. ref.current.deselectAll();
  2241. };
  2242. const selectAll = () => {
  2243. ref.current.selectAll();
  2244. };
  2245. return (
  2246. <>
  2247. <h4>onChangeWithObject = false</h4>
  2248. <Select
  2249. innerBottomSlot={
  2250. <div>
  2251. <Space>
  2252. <Button onClick={change}>close</Button>
  2253. <Button onClick={clearInput}>clearInput</Button>
  2254. <Button onClick={deselectAll}>deselectAll</Button>
  2255. <Button onClick={selectAll}>selectAll</Button>
  2256. </Space>
  2257. </div>
  2258. }
  2259. ref={ref}
  2260. onChange={e => console.log(e)}
  2261. placeholder="Business line"
  2262. style={{
  2263. width: 180,
  2264. }}
  2265. optionList={list}
  2266. filter
  2267. multiple
  2268. ></Select>
  2269. <Space>
  2270. <Button onClick={change}>open</Button>
  2271. <Button onClick={focus}>focus</Button>
  2272. <Button onClick={clearInput}>clearInput</Button>
  2273. <Button onClick={deselectAll}>deselectAll</Button>
  2274. <Button onClick={selectAll}>selectAll</Button>
  2275. </Space>
  2276. <h4
  2277. style={{
  2278. marginTop: 20,
  2279. }}
  2280. >
  2281. onChangeWithObject = true
  2282. </h4>
  2283. <Select
  2284. innerBottomSlot={
  2285. <div>
  2286. <Space></Space>
  2287. </div>
  2288. }
  2289. onChange={e => console.log(e)}
  2290. onChangeWithObject
  2291. ref={secondRef}
  2292. placeholder="Business line"
  2293. style={{
  2294. width: 180,
  2295. }}
  2296. optionList={list}
  2297. filter
  2298. multiple
  2299. ></Select>
  2300. <Space>
  2301. <Button onClick={() => secondRef.current.deselectAll()}>deselectAll</Button>
  2302. <Button onClick={() => secondRef.current.selectAll()}>selectAll</Button>
  2303. </Space>
  2304. </>
  2305. );
  2306. };
  2307. export const Ref = () => <SelectRefDemo />;
  2308. Ref.story = {
  2309. name: 'ref',
  2310. };
  2311. export const CustomTriggerDemo = () => <CustomTrigger />;
  2312. CustomTriggerDemo.story = {
  2313. name: 'custom trigger'
  2314. }
  2315. class VirtualizeClassDemo extends React.Component {
  2316. constructor(props) {
  2317. super(props);
  2318. // this.handleSearch = this.handleSearch.bind(this);
  2319. let newOptions = Array.from({ length: 1000 }, (v, i) => ({ label: `o-${i}`, value: `v-${v}-${i}` }));
  2320. this.state = {
  2321. optionList: newOptions,
  2322. };
  2323. }
  2324. render() {
  2325. let { groups, optionList } = this.state;
  2326. let virtualize = {
  2327. height: 300,
  2328. widht: '100%',
  2329. itemSize: 36,
  2330. };
  2331. return (
  2332. <>
  2333. <Select
  2334. placeholder=""
  2335. style={{ width: 180 }}
  2336. filter
  2337. onSearch={this.handleSearch}
  2338. virtualize={virtualize}
  2339. optionList={optionList}
  2340. ></Select>
  2341. </>
  2342. );
  2343. }
  2344. }
  2345. export const VirtualizeDemo = () => <VirtualizeClassDemo />;
  2346. VirtualizeDemo.story = {
  2347. name: 'virtualize select'
  2348. }
  2349. const SelectPosition = () => {
  2350. return (
  2351. <div
  2352. style={{
  2353. height: 500,
  2354. border: '1px solid red',
  2355. overflow: 'auto',
  2356. }}
  2357. >
  2358. <p>p</p>
  2359. <p>p</p>
  2360. <p>p</p>
  2361. <p>p</p>
  2362. <p>p</p>
  2363. <p>p</p>
  2364. <p>p</p>
  2365. <p>p</p>
  2366. <p>p</p>
  2367. <p>p</p>
  2368. <p>p</p>
  2369. <p>p</p>
  2370. <p>p</p>
  2371. <p>p</p>
  2372. <p>p</p>
  2373. <p>p</p>
  2374. <p>p</p>
  2375. <p>p</p>
  2376. <p>p</p>
  2377. <p>p</p>
  2378. <p>p</p>
  2379. <p>p</p>
  2380. <p>p</p>
  2381. <Select
  2382. defaultValue="abc"
  2383. style={{
  2384. width: 120,
  2385. }}
  2386. >
  2387. <Option value="abc">抖音</Option>
  2388. <Option value="hotsoon">火山</Option>
  2389. <Option value="pipixia" disabled>
  2390. 皮皮虾
  2391. </Option>
  2392. <Option value="xigua">西瓜视频</Option>
  2393. </Select>
  2394. <p>p</p>
  2395. <p>p</p>
  2396. <p>p</p>
  2397. <p>p</p>
  2398. <p>p</p>
  2399. <p>p</p>
  2400. <p>p</p>
  2401. <p>p</p>
  2402. <p>p</p>
  2403. <p>p</p>
  2404. <p>p</p>
  2405. <p>p</p>
  2406. <p>p</p>
  2407. <p>p</p>
  2408. <p>p</p>
  2409. <p>p</p>
  2410. <p>p</p>
  2411. <p>p</p>
  2412. <p>p</p>
  2413. <p>p</p>
  2414. <p>p</p>
  2415. <p>p</p>
  2416. <p>p</p>
  2417. <p>p</p>
  2418. <p>p</p>
  2419. <p>p</p>
  2420. <p>p</p>
  2421. <p>p</p>
  2422. <p>p</p>
  2423. <p>p</p>
  2424. <p>p</p>
  2425. <p>p</p>
  2426. <p>p</p>
  2427. <p>p</p>
  2428. <p>p</p>
  2429. <p>p</p>
  2430. <p>p</p>
  2431. <p>p</p>
  2432. <p>p</p>
  2433. <p>p</p>
  2434. <p>p</p>
  2435. <p>p</p>
  2436. </div>
  2437. );
  2438. };
  2439. export { SelectPosition };
  2440. SelectPosition.story = {
  2441. name: 'Select position problem'
  2442. }
  2443. const RenderOptionDemo = () => {
  2444. const renderOptionItem = renderProps => {
  2445. const {
  2446. disabled,
  2447. selected,
  2448. label,
  2449. value,
  2450. focused,
  2451. className,
  2452. style,
  2453. onMouseEnter,
  2454. onClick,
  2455. empty,
  2456. emptyContent,
  2457. ...rest
  2458. } = renderProps;
  2459. const optionCls = classNames({
  2460. ['custom-option-render']: true,
  2461. ['custom-option-render-focused']: focused,
  2462. ['custom-option-render-disabled']: disabled,
  2463. ['custom-option-render-selected']: selected,
  2464. }); // Notice:
  2465. // 1.props传入的style需在wrapper dom上进行消费,否则在虚拟化场景下会无法正常使用
  2466. // 2.选中(selected)、聚焦(focused)、禁用(disabled)等状态的样式需自行加上,你可以从props中获取到相对的boolean值
  2467. // 3.onMouseEnter需在wrapper dom上绑定,否则上下键盘操作时显示会有问题
  2468. return (
  2469. <div
  2470. style={style}
  2471. className={optionCls}
  2472. onClick={() => onClick()}
  2473. onMouseEnter={e => onMouseEnter()}
  2474. >
  2475. <Checkbox checked={selected} />
  2476. <div className="option-right">{label}</div>
  2477. </div>
  2478. );
  2479. };
  2480. return (
  2481. <>
  2482. <Select
  2483. filter
  2484. dropdownClassName="components-select-demo-renderOptionItem"
  2485. optionList={optionList}
  2486. style={{
  2487. width: 300,
  2488. }}
  2489. renderOptionItem={renderOptionItem}
  2490. />
  2491. <br />
  2492. <br />
  2493. <Select
  2494. filter
  2495. multiple
  2496. dropdownClassName="components-select-demo-renderOptionItem"
  2497. optionList={optionList}
  2498. style={{
  2499. width: 450,
  2500. }}
  2501. renderOptionItem={renderOptionItem}
  2502. />
  2503. </>
  2504. );
  2505. };
  2506. export const RenderOptionItem = () => <RenderOptionDemo />;
  2507. RenderOptionItem.story = {
  2508. name: 'renderOptionItem',
  2509. };
  2510. const FilterDefaultOpen = () => {
  2511. const [value1, setValue1] = useState('a-1');
  2512. return (
  2513. <>
  2514. <Select
  2515. placeholder=""
  2516. style={{
  2517. width: 180,
  2518. }}
  2519. filter
  2520. defaultOpen
  2521. >
  2522. <Select.OptGroup label="Asia">
  2523. <Select.Option value="a-1">China</Select.Option>
  2524. <Select.Option value="a-2">Koera</Select.Option>
  2525. </Select.OptGroup>
  2526. <Select.OptGroup label="Europe">
  2527. <Select.Option value="b-1">Germany</Select.Option>
  2528. <Select.Option value="b-2">France</Select.Option>
  2529. </Select.OptGroup>
  2530. <Select.OptGroup label="South America">
  2531. <Select.Option value="c-1">Peru</Select.Option>
  2532. </Select.OptGroup>
  2533. </Select>
  2534. <Select
  2535. placeholder=""
  2536. style={{
  2537. width: 180,
  2538. marginLeft: 20,
  2539. }}
  2540. filter
  2541. defaultOpen
  2542. defaultValue="a-2"
  2543. >
  2544. <Select.OptGroup label="Asia">
  2545. <Select.Option value="a-1">China</Select.Option>
  2546. <Select.Option value="a-2">Koera</Select.Option>
  2547. </Select.OptGroup>
  2548. <Select.OptGroup label="Europe">
  2549. <Select.Option value="b-1">Germany</Select.Option>
  2550. <Select.Option value="b-2">France</Select.Option>
  2551. </Select.OptGroup>
  2552. <Select.OptGroup label="South America">
  2553. <Select.Option value="c-1">Peru</Select.Option>
  2554. </Select.OptGroup>
  2555. </Select>
  2556. <Select
  2557. placeholder=""
  2558. style={{
  2559. width: 180,
  2560. marginLeft: 20,
  2561. }}
  2562. filter
  2563. defaultOpen
  2564. value={value1}
  2565. onChange={val => setValue1(val)}
  2566. >
  2567. <Select.Option value="a-1">China</Select.Option>
  2568. <Select.Option value="a-2">Koera</Select.Option>
  2569. <Select.Option value="b-1">Germany</Select.Option>
  2570. <Select.Option value="b-2">France</Select.Option>
  2571. <Select.Option value="c-1">Peru</Select.Option>
  2572. </Select>
  2573. </>
  2574. );
  2575. };
  2576. export { FilterDefaultOpen };
  2577. FilterDefaultOpen.story = {
  2578. name: 'Filter + defaultOpen'
  2579. };
  2580. const CustomSelect = props => {
  2581. const { fieldRef, ...rest } = props;
  2582. return <Select {...rest} ref={fieldRef} />;
  2583. };
  2584. const CustomFieldSelect = withField(CustomSelect);
  2585. const RefDemo = () => {
  2586. const fieldRef = useRef(null);
  2587. const onChange = () => {
  2588. console.log(fieldRef);
  2589. fieldRef.current.open();
  2590. debugger;
  2591. };
  2592. return (
  2593. <Form>
  2594. <CustomFieldSelect field="test" initValue="se" fieldRef={fieldRef}></CustomFieldSelect>
  2595. <Button onClick={onChange}>change</Button>
  2596. </Form>
  2597. );
  2598. };
  2599. export const RefFieldDemo = () => <RefDemo />;
  2600. RefFieldDemo.story = {
  2601. name: 'Ref field demo',
  2602. };
  2603. const ValueZeroDemo = () => {
  2604. const list = [
  2605. {
  2606. value: 6,
  2607. label: '抖音小视频',
  2608. otherKey: 0,
  2609. },
  2610. {
  2611. value: 1,
  2612. label: '火山小视频',
  2613. disabled: true,
  2614. otherKey: 1,
  2615. },
  2616. {
  2617. value: 'pipixia',
  2618. label: '皮皮虾',
  2619. otherKey: 2,
  2620. },
  2621. {
  2622. value: 'toutiao',
  2623. label: '今日头条',
  2624. otherKey: 3,
  2625. },
  2626. ];
  2627. return (
  2628. <Select
  2629. placeholder="请选择业务线"
  2630. style={{
  2631. width: 180,
  2632. }}
  2633. optionList={list}
  2634. value={0}
  2635. renderSelectedItem={option => option.label + 1}
  2636. ></Select>
  2637. );
  2638. };
  2639. export const Value0 = () => <ValueZeroDemo />;
  2640. Value0.story = {
  2641. name: 'value=0',
  2642. };
  2643. export const ScrollIntoView = () => (
  2644. <div>
  2645. <p>single selection</p>
  2646. <Select defaultValue='v-11' defaultOpen style={{ width: 120, marginBottom: 300 }}>
  2647. {new Array(50).fill(null).map((item, idx) => (
  2648. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2649. ))}
  2650. </Select>
  2651. <p>single selection with no selected item</p>
  2652. <Select style={{ marginBottom: 300, width: 120 }}>
  2653. {new Array(50).fill(null).map((item, idx) => (
  2654. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2655. ))}
  2656. </Select>
  2657. <p>The selected node is the last</p>
  2658. <Select defaultValue='v-49' defaultOpen style={{ marginBottom: 300, width: 120 }}>
  2659. {new Array(50).fill(null).map((item, idx) => (
  2660. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2661. ))}
  2662. </Select>
  2663. <p>The selected node is the first</p>
  2664. <Select defaultValue='v-0' style={{ marginBottom: 300, width: 120 }}>
  2665. {new Array(50).fill(null).map((item, idx) => (
  2666. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2667. ))}
  2668. </Select>
  2669. <p>multiple selection</p>
  2670. <Select defaultValue={['v-25', 'v-9']} multiple style={{ marginBottom: 300, width: 220 }}>
  2671. {new Array(30).fill(null).map((item, idx) => (
  2672. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2673. ))}
  2674. </Select>
  2675. <p>multiple selection with no selected item</p>
  2676. <Select multiple style={{ marginBottom: 300, width: 220 }}>
  2677. {new Array(30).fill(null).map((item, idx) => (
  2678. <Option value={`v-${idx}`} key={idx}>{`option-${idx}`}</Option>
  2679. ))}
  2680. </Select>
  2681. </div>
  2682. );
  2683. ScrollIntoView.story = {
  2684. name: 'scroll into view',
  2685. };
  2686. export const SelectInputPropsDemo = () => {
  2687. const inputProps = {
  2688. className: 'ttt',
  2689. onCompositionEnd: (v) => console.log(v.target.value)
  2690. };
  2691. return (
  2692. <Select
  2693. // onSearch={(v) => console.log(v)}
  2694. optionList={list}
  2695. inputProps={inputProps}
  2696. multiple
  2697. filter
  2698. style={{ width: 200 }}
  2699. >
  2700. </Select>
  2701. )
  2702. };
  2703. SelectInputPropsDemo.story = {
  2704. name: 'inputProps',
  2705. };
  2706. export const AutoClearSearchValue = () => {
  2707. const [val, setVal] = useState(['semi1']);
  2708. const [clear, setClear] = useState(false);
  2709. const optionList = [
  2710. { label: 'semi1', value: 'semi1' },
  2711. { label: 'semi2', value: 'semi2' },
  2712. { label: 'semi3', value: 'semi3' },
  2713. { label: 'semi4', value: 'semi4' },
  2714. { label: 'semi5', value: 'semi5' },
  2715. { label: 'semi6', value: 'semi6' },
  2716. ];
  2717. const [loading, setLoading] = useState(false);
  2718. const [list, setList] = useState(optionList);
  2719. const [value, setValue] = useState('');
  2720. const handleChange = newValue => { setValue(newValue); };
  2721. const data2 = [
  2722. {
  2723. label: "Design",
  2724. value: '123456',
  2725. }
  2726. ]
  2727. const handleSearch = (inputValue) => {
  2728. setLoading(true);
  2729. if (inputValue) {
  2730. setTimeout(() => {
  2731. setLoading(false);
  2732. setList(data2);
  2733. }, 1000);
  2734. } else {
  2735. setList(optionList)
  2736. setLoading(false);
  2737. }
  2738. };
  2739. return (
  2740. <>
  2741. <h4>autoClearSearchValue</h4>
  2742. <Switch checked={clear} onChange={checked => setClear(checked)}></Switch>
  2743. <h4>Controlled mode + multiple</h4>
  2744. <Select style={{ width: 400 }} multiple optionList={optionList} filter value={val} onChange={value => setVal(value)} autoClearSearchValue={clear}></Select>
  2745. <br />
  2746. <br />
  2747. <h4>Uncontrolled mode + multiple</h4>
  2748. <Select style={{ width: 400 }} multiple optionList={optionList} filter autoClearSearchValue={clear}></Select>
  2749. <h4>Uncontrolled mode + multiple + defaultValue</h4>
  2750. <Select style={{ width: 400 }} multiple optionList={optionList} filter defaultValue={['semi2']} autoClearSearchValue={clear}></Select>
  2751. <h4>controlled mode + update optionList + remote + autoClearSearchValue = false</h4>
  2752. <Select
  2753. style={{ width: 400 }}
  2754. multiple
  2755. optionList={list}
  2756. filter
  2757. remote
  2758. className='remote-select'
  2759. loading={loading}
  2760. value={value}
  2761. onChange={handleChange}
  2762. autoClearSearchValue={clear}
  2763. onSearch={handleSearch}
  2764. >
  2765. </Select>
  2766. </>
  2767. )
  2768. }
  2769. AutoClearSearchValue.story = {
  2770. name: 'AutoClearSearchValue',
  2771. };
  2772. export const RenderSelectedItemCallCount = () => {
  2773. const list = [
  2774. { "name": "夏可漫", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/avatarDemo.jpeg" },
  2775. { "name": "申悦", "email": "[email protected]", "avatar": "https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/bag.jpeg" },
  2776. { "name": "曲晨一", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/8bd8224511db085ed74fea37205aede5.jpg" },
  2777. { "name": "文嘉茂", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/6fbafc2d-e3e6-4cff-a1e2-17709c680624.png" },
  2778. { "name": "文嘉茂2", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/6fbafc2d-e3e6-4cff-a1e2-17709c680624.png" },
  2779. { "name": "文嘉茂3", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/6fbafc2d-e3e6-4cff-a1e2-17709c680624.png" },
  2780. ]
  2781. const renderMultipleWithCustomTag = (optionNode, { onClose }) => {
  2782. console.count('rerender')
  2783. const content = (
  2784. <Tag
  2785. avatarSrc={optionNode.avatar}
  2786. avatarShape='circle'
  2787. closable={true}
  2788. onClose={onClose}
  2789. size='large'
  2790. >
  2791. {optionNode.name}
  2792. </Tag>
  2793. );
  2794. return {
  2795. isRenderInTag: false,
  2796. content
  2797. };
  2798. }
  2799. const renderCustomOption = (item, index) => {
  2800. const optionStyle = {
  2801. display: 'flex',
  2802. paddingLeft: 24,
  2803. paddingTop: 10,
  2804. paddingBottom: 10
  2805. }
  2806. return (
  2807. <Select.Option value={item.name} style={optionStyle} showTick={true} {...item} key={item.email}>
  2808. <Avatar size="small" src={item.avatar} />
  2809. <div style={{ marginLeft: 8 }}>
  2810. <div style={{ fontSize: 14 }}>{item.name}</div>
  2811. <div style={{ color: 'var(--color-text-2)', fontSize: 12, lineHeight: '16px', fontWeight: 'normal' }}>{item.email}</div>
  2812. </div>
  2813. </Select.Option>
  2814. )
  2815. }
  2816. return (
  2817. <>
  2818. <Select
  2819. placeholder='请选择'
  2820. showClear
  2821. multiple
  2822. maxTagCount={2}
  2823. style={{ width: 280, height: 40 }}
  2824. onChange={v => console.log(v)}
  2825. defaultValue={'夏可漫'}
  2826. renderSelectedItem={renderMultipleWithCustomTag}
  2827. >
  2828. {list.map((item, index) => renderCustomOption(item, index))}
  2829. </Select>
  2830. </>
  2831. );
  2832. }
  2833. RenderSelectedItemCallCount.story = {
  2834. name: 'RenderSelectedItemCallCount',
  2835. };
  2836. const RenderSelectedItemWithMaxTagCount = () => {
  2837. const list = [
  2838. { "name": "夏可漫", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/avatarDemo.jpeg" },
  2839. { "name": "申悦", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/bf8647bffab13c38772c9ff94bf91a9d.jpg" },
  2840. { "name": "曲晨一", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/8bd8224511db085ed74fea37205aede5.jpg" },
  2841. { "name": "文嘉茂", "email": "[email protected]", "avatar": "https://sf6-cdn-tos.douyinstatic.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/6fbafc2d-e3e6-4cff-a1e2-17709c680624.png" },
  2842. ];
  2843. const renderMultipleWithCustomTag = (optionNode, { onClose }) => {
  2844. const content = (
  2845. <Tag
  2846. avatarSrc={optionNode.avatar}
  2847. avatarShape='circle'
  2848. closable={true}
  2849. onClose={onClose}
  2850. size='large'
  2851. style={{ maxWidth: '100%'}}
  2852. >
  2853. {optionNode.email}
  2854. </Tag>
  2855. );
  2856. return {
  2857. isRenderInTag: false,
  2858. content
  2859. };
  2860. };
  2861. const renderMultipleWithCustomTag2 = (optionNode, { onClose }) => {
  2862. const content = (
  2863. <Tag
  2864. avatarSrc={optionNode.avatar}
  2865. avatarShape='square'
  2866. closable={true}
  2867. onClose={onClose}
  2868. size='large'
  2869. style={{ maxWidth: '100%'}}
  2870. >
  2871. {optionNode.name}
  2872. </Tag>
  2873. );
  2874. return {
  2875. isRenderInTag: false,
  2876. content
  2877. };
  2878. };
  2879. const renderCustomOption = (item, index) => {
  2880. const optionStyle = {
  2881. display: 'flex',
  2882. paddingLeft: 24,
  2883. paddingTop: 10,
  2884. paddingBottom: 10
  2885. };
  2886. return (
  2887. <Select.Option value={item.name} style={optionStyle} showTick={true} {...item} key={item.email}>
  2888. <Avatar size="small" src={item.avatar} />
  2889. <div style={{ marginLeft: 8 }}>
  2890. <div style={{ fontSize: 14 }}>{item.email}</div>
  2891. <div style={{ color: 'var(--color-text-2)', fontSize: 12, lineHeight: '16px', fontWeight: 'normal' }}>{item.email}</div>
  2892. </div>
  2893. </Select.Option>
  2894. );
  2895. };
  2896. return (
  2897. <>
  2898. renderSelectedItem + maxTagCount=10 + defaultValue.length=2
  2899. <br />
  2900. <Select
  2901. placeholder='请选择'
  2902. maxTagCount={10}
  2903. style={{ width: 350, marginTop: 20 }}
  2904. onChange={v => console.log(v)}
  2905. defaultValue={['夏可漫', '申悦']}
  2906. multiple
  2907. renderSelectedItem={renderMultipleWithCustomTag}
  2908. ellipsisTrigger
  2909. showRestTagsPopover
  2910. expandRestTagsOnClick
  2911. >
  2912. {list.map((item, index) => renderCustomOption(item, index))}
  2913. </Select>
  2914. <br />
  2915. <br />
  2916. renderSelectedItem + maxTagCount=1 + defaultValue.length=2 + filter
  2917. <br />
  2918. <Select
  2919. placeholder='请选择'
  2920. maxTagCount={1}
  2921. filter
  2922. style={{ width: 350, marginTop: 20 }}
  2923. onChange={v => console.log(v)}
  2924. defaultValue={['夏可漫', '申悦']}
  2925. multiple
  2926. renderSelectedItem={renderMultipleWithCustomTag2}
  2927. ellipsisTrigger
  2928. showRestTagsPopover
  2929. expandRestTagsOnClick
  2930. >
  2931. {list.map((item, index) => renderCustomOption(item, index))}
  2932. </Select>
  2933. </>
  2934. );
  2935. };
  2936. export const NPlusTruncationStrategy = () => {
  2937. const shortVal = ['semi11', 'semi1']
  2938. const val = ['semi11', 'semi1', 'semi3', 'semi4', 'semi10']
  2939. const allSelect = ['semi11', 'semi1', 'semi2', 'semi3', 'semi4', 'semi5', 'semi6', 'semi7', 'semi8', 'semi9', 'semi10']
  2940. const options = [
  2941. { label: 'semi1semi1', value: 'semi1' },
  2942. { label: 'semi2semi2semi2', value: 'semi2' },
  2943. { label: 'semi3semi3semi3semi3', value: 'semi3' },
  2944. { label: 'semi4semi4semi4semi4semi4', value: 'semi4' },
  2945. { label: 'semi5semi5semi5semi5semi5semi5', value: 'semi5' },
  2946. { label: 'semi6semi6semi6semi6semi6semi6semi6', value: 'semi6' },
  2947. { label: 'semi7semi7semi7semi7semi7semi7semi7', value: 'semi7' },
  2948. { label: 'semi8semi8semi8semi8semi8semi8semi8', value: 'semi8' },
  2949. { label: 'semi9semi9semi9semi9semi9semi9semi9', value: 'semi9' },
  2950. { label: 'semi10semi10semi10semi10semi10semi10', value: 'semi10' },
  2951. { label: '我是中文超长选项我真的真的真的真的真的真的超级长', value: 'semi11' },
  2952. ];
  2953. // expandRestTagsOnClick
  2954. return (
  2955. <>
  2956. <h4>未设置宽度 和 maxTagCount </h4>
  2957. defaultValue.length = 5
  2958. <br /><br />
  2959. <Select multiple optionList={options} defaultValue={val} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2960. <br /><br /><br />
  2961. <h4>未设置宽度</h4>
  2962. maxTagCount = 2 + defaultValue.length = 5
  2963. <br /><br />
  2964. <Select maxTagCount={2} multiple optionList={options} defaultValue={val} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2965. <br /><br />
  2966. maxTagCount = 2 + defaultValue.length = 5 + expandRestTagsOnClick=false
  2967. <br /><br />
  2968. <Select maxTagCount={2} multiple optionList={options} defaultValue={val} expandRestTagsOnClick={false} ellipsisTrigger showRestTagsPopover></Select>
  2969. <br /><br />
  2970. maxTagCount = 6 + defaultValue.length = 5
  2971. <br /><br />
  2972. <Select maxTagCount={6} multiple optionList={options} defaultValue={val} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2973. <br /><br />
  2974. maxTagCount = 6 + defaultValue.length = 5 + filter
  2975. <br /><br />
  2976. <Select maxTagCount={6} multiple optionList={options} defaultValue={val} filter ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2977. <br /><br /><br />
  2978. <h4>定宽</h4>
  2979. maxTagCount = 2 + defaultValue.length = 2
  2980. <br /><br />
  2981. <Select style={{ width: '350px' }} maxTagCount={2} multiple optionList={options} defaultValue={shortVal} showClear ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2982. <br /><br />
  2983. maxTagCount = 5 + defaultValue.length = 5
  2984. <br /><br />
  2985. <Select style={{ width: '550px' }} maxTagCount={5} multiple optionList={options} defaultValue={val} showClear ellipsisTrigger showRestTagsPopove expandRestTagsOnClick></Select>
  2986. <br /><br />
  2987. maxTagCount = 10 + defaultValue.length = 11
  2988. <br /><br />
  2989. <Select style={{ width: '550px' }} maxTagCount={10} multiple optionList={options} defaultValue={allSelect} showClear ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2990. <br /><br />
  2991. maxTagCount = 10 + defaultValue.length = 11 + filter
  2992. <br /><br />
  2993. <Select style={{ width: '550px' }} maxTagCount={10} multiple optionList={options} defaultValue={allSelect} filter showClear ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  2994. <br /><br />
  2995. maxTagCount = 10 + defaultValue.length = 11 + expandRestTagsOnClick=false
  2996. <br /><br />
  2997. <Select style={{ width: '550px' }} maxTagCount={10} multiple optionList={options} defaultValue={allSelect} expandRestTagsOnClick={false} showClear ellipsisTrigger showRestTagsPopover></Select>
  2998. <br /><br /><br />
  2999. <h4>能保证正常渲染的最小宽度至少是120px</h4>
  3000. <Select style={{ width: '120px' }} maxTagCount={10} multiple optionList={options} defaultValue={val} showClear ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  3001. <br /><br /><br />
  3002. <h4>前缀/后缀/insetLabel</h4>
  3003. maxTagCount = 2 + defaultValue.length = 2 + prefix
  3004. <br /><br />
  3005. <Select style={{ width: '500px' }} maxTagCount={2} prefix={<IconSearch />} multiple optionList={options} defaultValue={shortVal} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  3006. <br /><br />
  3007. maxTagCount = 6 + defaultValue.length = 5 + suffix
  3008. <br /><br />
  3009. <Select style={{ width: '500px' }} maxTagCount={6} suffix={<IconSearch />} multiple optionList={options} defaultValue={val} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  3010. <br /><br />
  3011. maxTagCount = 6 + defaultValue.length = 11 + insetLabel
  3012. <br /><br />
  3013. <Select style={{ width: '500px' }} maxTagCount={6} insetLabel={<IconSearch />} multiple optionList={options} defaultValue={allSelect} ellipsisTrigger showRestTagsPopover expandRestTagsOnClick></Select>
  3014. <br /><br /><br />
  3015. <h4>renderSelectedItem</h4>
  3016. <RenderSelectedItemWithMaxTagCount />
  3017. <br />
  3018. </>
  3019. )
  3020. }
  3021. NPlusTruncationStrategy.story = {
  3022. name: 'NPlusTruncationStrategy',
  3023. };
  3024. export const emptyContent = () => {
  3025. const list = null;
  3026. return (
  3027. <Select placeholder='请选择业务线' emptyContent={null} style={{ width: 180 }} optionList={list} defaultOpen={true}/>
  3028. )
  3029. }