tabs.stories.jsx 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. import React, { useState } from 'react';
  2. import Tabs from '../index';
  3. import Button from '@douyinfe/semi-ui/button/index';
  4. import Typography from '@douyinfe/semi-ui/typography/index';
  5. import Switch from '@douyinfe/semi-ui/switch/index';
  6. import { Radio, RadioGroup, Checkbox } from '@douyinfe/semi-ui';
  7. import Icon from '../../icons';
  8. import { IconFile, IconGlobe, IconHelpCircle, IconClose } from '@douyinfe/semi-icons';
  9. const TabPane = Tabs.TabPane;
  10. const { Title } = Typography;
  11. export default {
  12. title: 'Tabs'
  13. }
  14. const style = {
  15. width: '600px',
  16. margin: '20px',
  17. };
  18. const onChange = activeKey => {
  19. console.log('onChange: activeKey =>', activeKey);
  20. };
  21. const onTabClick = (activeKey, event) => {
  22. console.log('onTabClick: onTabClick =>', activeKey);
  23. };
  24. const operations = (
  25. <Button
  26. onClick={() => {
  27. alert('you have clicked me!');
  28. }}
  29. >
  30. Extra Action
  31. </Button>
  32. );
  33. class App extends React.Component {
  34. render() {
  35. return (
  36. <div>
  37. <Tabs type="line">
  38. <TabPane tab="文档" itemKey="1">
  39. <h3>文档</h3>
  40. <p
  41. style={{
  42. lineHeight: 1.8,
  43. }}
  44. >
  45. Semi Design 是由抖音前端团队与 UED
  46. 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的
  47. Web 应用。
  48. </p>
  49. <p
  50. style={{
  51. lineHeight: 1.8,
  52. }}
  53. >
  54. 区别于其他的设计系统而言,Semi Design
  55. 以用户中心、内容优先、设计人性化为设计理念,具有以下优势:
  56. </p>
  57. <ul>
  58. <li>
  59. <p>Semi Design 以内容优先进行设计。</p>
  60. </li>
  61. <li>
  62. <p>更容易地自定义主题。</p>
  63. </li>
  64. <li>
  65. <p>适用国际化场景。</p>
  66. </li>
  67. <li>
  68. <p>效率场景加入人性化关怀。</p>
  69. </li>
  70. </ul>
  71. <h3>文档</h3>
  72. <p
  73. style={{
  74. lineHeight: 1.8,
  75. }}
  76. >
  77. Semi Design 是由抖音前端团队与 UED
  78. 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的
  79. Web 应用。
  80. </p>
  81. <p
  82. style={{
  83. lineHeight: 1.8,
  84. }}
  85. >
  86. 区别于其他的设计系统而言,Semi Design
  87. 以用户中心、内容优先、设计人性化为设计理念,具有以下优势:
  88. </p>
  89. <ul>
  90. <li>
  91. <p>Semi Design 以内容优先进行设计。</p>
  92. </li>
  93. <li>
  94. <p>更容易地自定义主题。</p>
  95. </li>
  96. <li>
  97. <p>适用国际化场景。</p>
  98. </li>
  99. <li>
  100. <p>效率场景加入人性化关怀。</p>
  101. </li>
  102. </ul>
  103. </TabPane>
  104. <TabPane tab="快速起步" itemKey="2">
  105. <h3>快速起步</h3>
  106. <p
  107. style={{
  108. lineHeight: 1.8,
  109. }}
  110. >
  111. 如果是全新的项目,建议你使用 eden 初始化项目,初始化项目类型选择 react
  112. </p>
  113. <pre
  114. style={{
  115. margin: '24px 0',
  116. padding: '20px',
  117. border: 'none',
  118. whiteSpace: 'normal',
  119. borderRadius: '6px',
  120. color: 'var(--semi-color-text-1)',
  121. backgroundColor: 'var(--semi-color-fill-0)',
  122. }}
  123. >
  124. <code></code>
  125. </pre>
  126. </TabPane>
  127. <TabPane tab="帮助" itemKey="3">
  128. <h3>帮助</h3>
  129. <p
  130. style={{
  131. lineHeight: 1.8,
  132. color: 'var(--semi-color-text-0)',
  133. fontWeight: 600,
  134. }}
  135. >
  136. Q:有新组件需求、或者现有组件feature不能满足业务需求?
  137. </p>
  138. <p
  139. style={{
  140. lineHeight: 1.8,
  141. color: 'var(--semi-color-text-1)',
  142. }}
  143. >
  144. 右上角问题反馈,提交issue,label选择Feature Request / New Component Request
  145. 我们会高优处理这些需求。
  146. </p>
  147. <p
  148. style={{
  149. lineHeight: 1.8,
  150. color: 'var(--semi-color-text-0)',
  151. fontWeight: 600,
  152. }}
  153. >
  154. Q:对组件的使用有疑惑?
  155. </p>
  156. <p
  157. style={{
  158. lineHeight: 1.8,
  159. color: 'var(--semi-color-text-1)',
  160. }}
  161. >
  162. 欢迎进我们的客服lark群进行咨询提问。
  163. </p>
  164. </TabPane>
  165. </Tabs>
  166. </div>
  167. );
  168. }
  169. }
  170. export const Level1NoIcon = () => (
  171. <div
  172. style={{
  173. width: 500,
  174. height: 500,
  175. margin: 50,
  176. }}
  177. >
  178. <App />
  179. </div>
  180. );
  181. Level1NoIcon.story = {
  182. name: 'Level 1-无图标',
  183. };
  184. export const DefaultActiveKeyDemo = () => (
  185. <Tabs style={style} defaultActiveKey="3" onChange={onChange} onTabClick={onTabClick}>
  186. <TabPane tab="文档" itemKey="1">
  187. <span>文档</span>
  188. </TabPane>
  189. <TabPane tab="快速起步" itemKey="2">
  190. 快速起步
  191. </TabPane>
  192. <TabPane tab="帮助" itemKey="3">
  193. 帮助
  194. </TabPane>
  195. <TabPane tab="关于" itemKey="4">
  196. 关于
  197. </TabPane>
  198. <TabPane tab="资源工具" itemKey="5">
  199. 资源工具
  200. </TabPane>
  201. </Tabs>
  202. );
  203. DefaultActiveKeyDemo.story = {
  204. name: '指定defaultActiveKey',
  205. };
  206. export const Level1WithIcon = () => (
  207. <Tabs style={style} defaultActiveKey="1" onChange={onChange} onTabClick={onTabClick}>
  208. <TabPane
  209. tab={
  210. <span>
  211. <IconFile />
  212. 文档
  213. </span>
  214. }
  215. itemKey="1"
  216. >
  217. 文档
  218. </TabPane>
  219. <TabPane
  220. tab={
  221. <span>
  222. <IconGlobe />
  223. 快速起步
  224. </span>
  225. }
  226. itemKey="2"
  227. >
  228. 快速起步
  229. </TabPane>
  230. <TabPane
  231. tab={
  232. <span>
  233. <IconHelpCircle />
  234. 帮助
  235. </span>
  236. }
  237. itemKey="3"
  238. >
  239. 帮助
  240. </TabPane>
  241. </Tabs>
  242. );
  243. Level1WithIcon.story = {
  244. name: 'Level 1-有图标',
  245. };
  246. export const Level1WithTabBarExtraContent = () => (
  247. <Tabs style={style} defaultActiveKey="1" tabBarExtraContent={operations}>
  248. <TabPane tab="文档" itemKey="1">
  249. 文档
  250. </TabPane>
  251. <TabPane tab="快速起步" itemKey="2">
  252. 快速起步
  253. </TabPane>
  254. <TabPane tab="帮助" itemKey="3">
  255. 帮助
  256. </TabPane>
  257. <TabPane tab="关于" itemKey="4">
  258. 关于
  259. </TabPane>
  260. <TabPane tab="资源工具" itemKey="5">
  261. 资源工具
  262. </TabPane>
  263. </Tabs>
  264. );
  265. Level1WithTabBarExtraContent.story = {
  266. name: 'Level 1-导航内容扩展',
  267. };
  268. export const RenderTabBar = () => (
  269. <Tabs
  270. style={style}
  271. defaultActiveKey="1"
  272. renderTabBar={(tabBarProps, DefaultTabBar) => {
  273. return (
  274. <div className="tab-bar-box" >
  275. 这是二次封装的Tab Bar,当前ActiveKey:{tabBarProps.activeKey}
  276. <DefaultTabBar {...tabBarProps} />
  277. </div>
  278. );
  279. }}
  280. >
  281. <TabPane tab="文档" itemKey="1">
  282. 文档
  283. </TabPane>
  284. <TabPane tab="快速起步" itemKey="2">
  285. 快速起步
  286. </TabPane>
  287. <TabPane tab="帮助" itemKey="3">
  288. 帮助
  289. </TabPane>
  290. <TabPane tab="关于" itemKey="4">
  291. 关于
  292. </TabPane>
  293. <TabPane tab="资源工具" itemKey="5">
  294. 资源工具
  295. </TabPane>
  296. </Tabs>
  297. );
  298. RenderTabBar.story = {
  299. name: 'Level 1-导航二次封装',
  300. };
  301. export const DisabledTab = () => (
  302. <Tabs style={style} defaultActiveKey="1">
  303. <TabPane tab="文档" itemKey="1">
  304. 文档
  305. </TabPane>
  306. <TabPane tab="快速起步" itemKey="2">
  307. 快速起步
  308. </TabPane>
  309. <TabPane tab="帮助" itemKey="3" disabled>
  310. 帮助
  311. </TabPane>
  312. <TabPane tab="关于" itemKey="4" disabled>
  313. 关于
  314. </TabPane>
  315. <TabPane tab="资源工具" itemKey="5">
  316. 资源工具
  317. </TabPane>
  318. </Tabs>
  319. );
  320. DisabledTab.story = {
  321. name: 'Level 1-不可点击Tab',
  322. };
  323. export const Level2Card = () => (
  324. <Tabs style={style} defaultActiveKey="1" type="card">
  325. <TabPane tab="文档" itemKey="1">
  326. 文档
  327. </TabPane>
  328. <TabPane tab="快速起步" itemKey="2">
  329. 快速起步
  330. </TabPane>
  331. <TabPane tab="帮助" itemKey="3">
  332. 帮助
  333. </TabPane>
  334. <TabPane tab="关于" itemKey="4">
  335. 关于
  336. </TabPane>
  337. <TabPane tab="资源工具" itemKey="5">
  338. 资源工具
  339. </TabPane>
  340. </Tabs>
  341. );
  342. Level2Card.story = {
  343. name: 'Level 2-卡片Tab',
  344. };
  345. export const Level3ButtonTab = () => (
  346. <Tabs style={style} defaultActiveKey="1" type="button">
  347. <TabPane tab="文档" itemKey="1">
  348. 文档
  349. </TabPane>
  350. <TabPane tab="快速起步" itemKey="2">
  351. 快速起步
  352. </TabPane>
  353. <TabPane tab="帮助" itemKey="3">
  354. 帮助
  355. </TabPane>
  356. <TabPane tab="关于" itemKey="4">
  357. 关于
  358. </TabPane>
  359. <TabPane tab="资源工具" itemKey="5">
  360. 资源工具
  361. </TabPane>
  362. </Tabs>
  363. );
  364. Level3ButtonTab.story = {
  365. name: 'Level 3-按钮Tab',
  366. };
  367. class TabDemo extends React.Component {
  368. constructor() {
  369. super();
  370. this.state = {
  371. itemKey: '1',
  372. };
  373. this.onTabClick = this.onTabClick.bind(this);
  374. }
  375. onTabClick(itemKey, type) {
  376. this.setState({
  377. [type]: itemKey,
  378. });
  379. }
  380. render() {
  381. const contentList = [
  382. <div>文档</div>,
  383. <div>快速起步</div>,
  384. <div>帮助</div>,
  385. <div>关于</div>,
  386. <div>资源工具</div>,
  387. ];
  388. const tabList = [
  389. {
  390. tab: '文档',
  391. itemKey: '1',
  392. },
  393. {
  394. tab: '快速起步',
  395. itemKey: '2',
  396. },
  397. {
  398. tab: '帮助',
  399. itemKey: '3',
  400. },
  401. {
  402. tab: '关于',
  403. itemKey: '4',
  404. },
  405. {
  406. tab: '资源工具',
  407. itemKey: '5',
  408. },
  409. ];
  410. return (
  411. <Tabs
  412. style={style}
  413. type="line"
  414. tabList={tabList}
  415. onTabClick={itemKey => {
  416. this.onTabClick(itemKey, 'itemKey');
  417. }}
  418. >
  419. {contentList[this.state.itemKey]}
  420. <span>test</span>
  421. <span>test2</span>
  422. </Tabs>
  423. );
  424. }
  425. }
  426. export const TabList = () => <TabDemo />;
  427. TabList.story = {
  428. name: 'tabList',
  429. };
  430. class TabDemo2 extends React.Component {
  431. constructor() {
  432. super();
  433. this.state = {
  434. key: '1',
  435. };
  436. this.onTabClick = this.onTabClick.bind(this);
  437. }
  438. onTabClick(val) {
  439. console.log('key', val);
  440. this.setState({
  441. key: val,
  442. });
  443. }
  444. render() {
  445. return (
  446. <Tabs type="line" activeKey={this.state.key} onChange={val => this.onTabClick(val)}>
  447. <TabPane tab="文档" itemKey="1">
  448. 文档
  449. </TabPane>
  450. <TabPane tab="快速起步" itemKey="2">
  451. 快速起步
  452. </TabPane>
  453. <TabPane tab="帮助" itemKey="3">
  454. 帮助
  455. </TabPane>
  456. <TabPane tab="关于" itemKey="4">
  457. 关于
  458. </TabPane>
  459. <TabPane tab="资源工具" itemKey="5">
  460. 资源工具
  461. </TabPane>
  462. </Tabs>
  463. );
  464. }
  465. }
  466. export const ActiveKey = () => <TabDemo2 />;
  467. ActiveKey.story = {
  468. name: 'activeKey',
  469. };
  470. class TabDemo3 extends React.Component {
  471. constructor() {
  472. super();
  473. this.state = {
  474. key: '1',
  475. type: 'here',
  476. };
  477. }
  478. onTabClick(val) {
  479. console.log('key', val);
  480. this.setState({
  481. key: val,
  482. type: 'search',
  483. });
  484. }
  485. render() {
  486. let type = this.state.type;
  487. return (
  488. <Tabs type="line" activeKey={this.state.key} onChange={val => this.onTabClick(val)}>
  489. <TabPane tab="文档" itemKey="1">
  490. 文档
  491. </TabPane>
  492. <TabPane tab="快速起步" itemKey="2">
  493. 快速起步
  494. </TabPane>
  495. {type === 'search' && (
  496. <TabPane tab="搜索" itemKey="3">
  497. 搜索
  498. </TabPane>
  499. )}
  500. </Tabs>
  501. );
  502. }
  503. }
  504. export const Dynamic = () => <TabDemo3 />;
  505. class TabDemo4 extends React.Component {
  506. constructor() {
  507. super();
  508. this.state = {
  509. loading: true,
  510. };
  511. }
  512. updateTab = () => {
  513. this.setState({
  514. loading: !this.state.loading,
  515. });
  516. this.tab = Math.random();
  517. };
  518. render() {
  519. let type = this.state.type;
  520. return (
  521. <div>
  522. <Button onClick={() => this.updateTab()}>change</Button>
  523. <Tabs type="line">
  524. <TabPane tab={this.tab} itemKey="1">
  525. 文档
  526. </TabPane>
  527. <TabPane tab="快速起步" itemKey="2">
  528. 快速起步
  529. </TabPane>
  530. {type === 'search' && (
  531. <TabPane tab="搜索" itemKey="3">
  532. 搜索
  533. </TabPane>
  534. )}
  535. </Tabs>
  536. </div>
  537. );
  538. }
  539. }
  540. export const Update = () => <TabDemo4 />;
  541. export const RenderCurrentPane = () => (
  542. <Tabs style={style} keepDOM={false}>
  543. <TabPane tab="文档" itemKey="1">
  544. <span>文档</span>
  545. </TabPane>
  546. <TabPane tab="快速起步" itemKey="2">
  547. 快速起步
  548. </TabPane>
  549. <TabPane tab="帮助" itemKey="3">
  550. 帮助
  551. </TabPane>
  552. <TabPane tab="关于" itemKey="4">
  553. 关于
  554. </TabPane>
  555. <TabPane tab="资源工具" itemKey="5">
  556. 资源工具
  557. </TabPane>
  558. </Tabs>
  559. );
  560. RenderCurrentPane.story = {
  561. name: '只渲染当前pane'
  562. }
  563. export const LazyRender = () => (
  564. <Tabs style={style} lazyRender>
  565. <TabPane tab="文档" itemKey="1">
  566. <span>文档</span>
  567. </TabPane>
  568. <TabPane tab="快速起步" itemKey="2">
  569. 快速起步
  570. </TabPane>
  571. <TabPane tab="帮助" itemKey="3">
  572. 帮助
  573. </TabPane>
  574. <TabPane tab="关于" itemKey="4">
  575. 关于
  576. </TabPane>
  577. <TabPane tab="资源工具" itemKey="5">
  578. 资源工具
  579. </TabPane>
  580. </Tabs>
  581. );
  582. LazyRender.story = {
  583. name: '懒渲染'
  584. }
  585. export const VerticalTabs = () => (
  586. <Tabs style={style} tabPosition="left">
  587. <TabPane tab="文档" itemKey="1">
  588. <span>文档</span>
  589. </TabPane>
  590. <TabPane tab="快速起步" itemKey="2">
  591. 快速起步
  592. </TabPane>
  593. <TabPane tab="帮助" itemKey="3">
  594. 帮助
  595. </TabPane>
  596. <TabPane tab="关于" itemKey="4">
  597. 关于
  598. </TabPane>
  599. <TabPane tab="资源工具" itemKey="5">
  600. 资源工具
  601. </TabPane>
  602. </Tabs>
  603. );
  604. VerticalTabs.story = {
  605. name: '垂直的tabs'
  606. }
  607. export const HorizontalTabs = () => (
  608. <Tabs style={style} tabPosition="left" type="card">
  609. <TabPane tab="文档" itemKey="1">
  610. <span>文档</span>
  611. </TabPane>
  612. <TabPane tab="快速起步" itemKey="2">
  613. 快速起步
  614. </TabPane>
  615. <TabPane tab="帮助" itemKey="3">
  616. 帮助
  617. </TabPane>
  618. <TabPane tab="关于" itemKey="4">
  619. 关于
  620. </TabPane>
  621. <TabPane tab="资源工具" itemKey="5">
  622. 资源工具
  623. </TabPane>
  624. </Tabs>
  625. );
  626. HorizontalTabs.story = {
  627. name: '垂直的tabs - 卡片',
  628. };
  629. export const VerticalTabsButton = () => (
  630. <Tabs style={style} tabPosition="left" type="button">
  631. <TabPane tab="文档" itemKey="1">
  632. <span>文档</span>
  633. </TabPane>
  634. <TabPane tab="快速起步" itemKey="2">
  635. 快速起步
  636. </TabPane>
  637. <TabPane tab="帮助" itemKey="3">
  638. 帮助
  639. </TabPane>
  640. <TabPane tab="关于" itemKey="4">
  641. 关于
  642. </TabPane>
  643. <TabPane tab="资源工具" itemKey="5">
  644. 资源工具
  645. </TabPane>
  646. </Tabs>
  647. );
  648. VerticalTabsButton.story = {
  649. name: '垂直的tabs - 按钮',
  650. };
  651. export const CollapseTabs = () => (
  652. <div>
  653. <Tabs
  654. style={{
  655. width: '60%',
  656. margin: '20px',
  657. }}
  658. type="card"
  659. collapsible
  660. >
  661. {[...Array(30).keys()].map(i => (
  662. <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={`${i}`}>
  663. Content of card tab {i}
  664. </TabPane>
  665. ))}
  666. </Tabs>
  667. <br />
  668. <br />
  669. <Tabs style={style} type="button" collapsible>
  670. {[...Array(30).keys()].map(i => (
  671. <TabPane tab={`Tab-${i}`} itemKey={`${i}`} key={`${i}`}>
  672. Content of button tab {i}
  673. </TabPane>
  674. ))}
  675. </Tabs>
  676. <br />
  677. <br />
  678. <Tabs style={style} type="line" collapsible>
  679. {[...Array(30).keys()].map(i => (
  680. <TabPane tab={`Tab-${i}`} itemKey={`${i}`} key={`${i}`}>
  681. Content of line tab {i}
  682. </TabPane>
  683. ))}
  684. </Tabs>
  685. </div>
  686. );
  687. CollapseTabs.story = {
  688. name: '折叠的tabs'
  689. }
  690. const TabSizeDemo = () => {
  691. const typeList = ['line'];
  692. const [size, setSize] = useState('large');
  693. const [vertical, setVertical] = useState(false);
  694. return (
  695. <div>
  696. <RadioGroup onChange={e => setSize(e.target.value)} value={size}>
  697. <Radio value={'small'}>small</Radio>
  698. <Radio value={'medium'}>medium</Radio>
  699. <Radio value={'large'}>large</Radio>
  700. </RadioGroup>
  701. <div
  702. style={{
  703. display: 'flex',
  704. alignItems: 'center',
  705. }}
  706. >
  707. <Title
  708. heading={6}
  709. style={{
  710. margin: 8,
  711. }}
  712. >
  713. {vertical ? '垂直' : '水平'}
  714. </Title>
  715. <Switch checked={vertical} onChange={setVertical} />
  716. </div>
  717. {typeList.map((type, index) => {
  718. return (
  719. <Tabs
  720. style={{
  721. width: '60%',
  722. margin: '20px',
  723. }}
  724. type={type}
  725. size={size}
  726. key={index}
  727. tabPosition={vertical ? 'left' : 'top'}
  728. >
  729. {[...Array(3).keys()].map(i => (
  730. <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`}>
  731. Content of {type} tab {i}
  732. </TabPane>
  733. ))}
  734. </Tabs>
  735. );
  736. })}
  737. <br />
  738. <br />
  739. </div>
  740. );
  741. };
  742. export const TabSize = () => <TabSizeDemo />;
  743. TabSize.story = {
  744. name: 'tab size',
  745. };
  746. class TabListChangeDemo extends React.Component {
  747. constructor() {
  748. super();
  749. this.state = {
  750. itemKey: '1',
  751. tabList:[
  752. {
  753. tab: '文档',
  754. itemKey: '1',
  755. },
  756. {
  757. tab: '快速起步',
  758. itemKey: '2',
  759. },
  760. {
  761. tab: '帮助',
  762. itemKey: '3',
  763. },
  764. {
  765. tab: '关于',
  766. itemKey: '4',
  767. },
  768. {
  769. tab: '资源工具',
  770. itemKey: '5',
  771. },
  772. ]
  773. };
  774. this.onTabClick = this.onTabClick.bind(this);
  775. }
  776. onTabClick(itemKey, type) {
  777. this.setState({
  778. [type]: itemKey,
  779. tabList: [{
  780. tab: '文档',
  781. itemKey: '1',
  782. }]
  783. });
  784. }
  785. render() {
  786. const contentList = [
  787. <div>文档</div>,
  788. <div>快速起步</div>,
  789. <div>帮助</div>,
  790. <div>关于</div>,
  791. <div>资源工具</div>,
  792. ];
  793. return (
  794. <Tabs
  795. style={style}
  796. type="line"
  797. tabList={this.state.tabList}
  798. onTabClick={itemKey => {
  799. this.onTabClick(itemKey, 'itemKey');
  800. }}
  801. >
  802. {contentList[this.state.itemKey]}
  803. <span>test</span>
  804. <span>test2</span>
  805. </Tabs>
  806. );
  807. }
  808. }
  809. export const TabListChange = () => <TabListChangeDemo />;
  810. TabListChange.story = {
  811. name: 'tablist change',
  812. };
  813. class TabClosableDemo extends React.Component {
  814. constructor(props){
  815. super(props);
  816. this.state = {
  817. tabList: [
  818. {tab: '文档', itemKey:'1', text:'文档', closable:true},
  819. {tab: '快速起步', itemKey:'2', text:'快速起步', closable:true},
  820. {tab: '帮助', itemKey:'3', text:'帮助'},
  821. ]
  822. }
  823. }
  824. close(key){
  825. const newTabList = [...this.state.tabList];
  826. const closeIndex = newTabList.findIndex(t=>t.itemKey===key);
  827. newTabList.splice(closeIndex, 1);
  828. this.setState({tabList:newTabList});
  829. }
  830. render() {
  831. return (
  832. <Tabs type="card" defaultActiveKey="1" onTabClose={this.close.bind(this)}>
  833. {
  834. this.state.tabList.map(t=><TabPane closable={t.closable} tab={t.tab} itemKey={t.itemKey} key={t.itemKey}>{t.text}</TabPane>)
  835. }
  836. </Tabs>
  837. );
  838. }
  839. }
  840. export const TabClosable = () => <TabClosableDemo />;
  841. TabClosable.story = {
  842. name: 'tab closable',
  843. };
  844. export const TabItem = () => {
  845. const TabItem = Tabs.TabItem;
  846. console.log('TabItem', TabItem.elementType, TabItem);
  847. const params = [
  848. // line 不同size
  849. { tab: '标签栏一', type: 'line', icon: null, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  850. { tab: '标签栏一', type: 'line', icon: null, size: 'medium', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  851. { tab: '标签栏一', type: 'line', icon: null, size: 'small', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  852. // with icon
  853. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  854. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'medium', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  855. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'small', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '1' },
  856. // button card
  857. { tab: '标签栏一', type: 'button', icon: null, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '2' },
  858. { tab: '标签栏一', type: 'card', icon: null, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '3' },
  859. { tab: '标签栏一', type: 'button', icon: <IconFile />, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '2' },
  860. { tab: '标签栏一', type: 'card', icon: <IconFile />, size: 'large', tabPosition: 'top', selected: false, closable: false, disabled: false, itemKey: '3' },
  861. // left
  862. { tab: '标签栏一', type: 'line', icon: null, size: 'large',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  863. { tab: '标签栏一', type: 'line', icon: null, size: 'medium',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  864. { tab: '标签栏一', type: 'line', icon: null, size: 'large', tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '2' },
  865. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'large',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  866. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'medium',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  867. { tab: '标签栏一', type: 'line', icon: <IconFile />, size: 'large', tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '2' },
  868. { tab: '标签栏一', type: 'card', icon: null, size: 'large', tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '3' },
  869. { tab: '标签栏一', type: 'button', icon: null, size: 'small',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  870. { tab: '标签栏一', type: 'card', icon: <IconFile />, size: 'large', tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '3' },
  871. { tab: '标签栏一', type: 'button', icon: <IconFile />, size: 'small',tabPosition: 'left', selected: false, closable: false, disabled: false, itemKey: '1' },
  872. ]
  873. return (<div style={{ minWidth: 100, minHeight: 100, border: '1px solid grey' }}>
  874. {params.map((param, index) => (
  875. <div key={`tab-item-${index}`} style={{ margin: 10 }}>
  876. <TabItem {...param} />
  877. <span style={{ marginLeft: '20px'}}></span>
  878. <TabItem {...param} selected={true}/>
  879. <span style={{ marginLeft: '20px'}}></span>
  880. <TabItem {...param} disabled={true}/>
  881. {param.type === 'card' &&
  882. <div key={`tab-item-${index}-2`} style={{ margin: 10 }}>
  883. <TabItem {...param} closable={true} />
  884. <span style={{ marginLeft: '20px'}}></span>
  885. <TabItem {...param} selected={true} closable={true} />
  886. <span style={{ marginLeft: '20px'}} closable={true} ></span>
  887. <TabItem {...param} disabled={true} closable={true} />
  888. </div>
  889. }
  890. </div>
  891. ))}
  892. </div>)
  893. }
  894. export const Fix1456 = () =>{
  895. const [key, setKey] = useState([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
  896. return (
  897. <div id='wrapper' style={{ height: 300, overflowY: 'scroll' }}>
  898. <div style={{ height: 500 }}>
  899. <Tabs style={{ width: '300px', margin: '20px' }} type="card" collapsible>
  900. {key.map(i => (
  901. <TabPane tab={`tab-${i}`} itemKey={`${i}`} key={i}>
  902. Content of card tab {i}
  903. </TabPane>
  904. ))}
  905. </Tabs>
  906. <Button onClick={()=>{setKey([8, 9, 10, 11, 12, 13, 14, 15])}}>change key</Button>
  907. </div>
  908. </div>
  909. );
  910. }
  911. Fix1456.story = {
  912. name: 'Fix-1456',
  913. };
  914. export const IconStyle = () => {
  915. return (
  916. <Tabs type="card" >
  917. <TabPane tab={<span><IconClose />文档</span> } itemKey="1" closable={true}>
  918. 用于测试图标设置为 close icon 是否正确
  919. </TabPane>
  920. <TabPane tab={<Radio defaultChecked>test2</Radio>} itemKey="2">
  921. 用于测试 tab 下的 Radio 中的 semi-icon 是否收到影响
  922. </TabPane>
  923. <TabPane tab={<Checkbox defaultChecked>test2</Checkbox>} itemKey="3">
  924. 用于测试 Checkbox 下的 Radio 中的 semi-icon 是否收到影响
  925. </TabPane>
  926. </Tabs>
  927. )
  928. }
  929. export const Fix2239 = () => {
  930. const [activeKey, setActiveKey] = useState('tab-0')
  931. return (
  932. <div>
  933. The overflow tab will also 'scrollIntoView' when the 'activeKey' changes.
  934. <Tabs
  935. style={{
  936. width: '500px',
  937. margin: '20px',
  938. }}
  939. type="card"
  940. activeKey={activeKey}
  941. collapsible
  942. onChange={(e) => {
  943. setActiveKey(e)
  944. }}
  945. >
  946. {[...Array(10).keys()].map(i => (
  947. <TabPane tab={`Tab-${i}`} itemKey={`tab-${i}`} key={i}>content of tab {i}</TabPane>
  948. ))}
  949. </Tabs>
  950. <Button onClick={() => { setActiveKey('tab-0') }}>
  951. To Tab-0
  952. </Button>
  953. <Button onClick={() => { setActiveKey('tab-7') }}>
  954. To Tab-7
  955. </Button>
  956. </div>
  957. );
  958. }
  959. Fix2239.story = {
  960. name: 'Fix 2239',
  961. };
  962. export const ShowRestInDropdownDemo = () => {
  963. return (
  964. <Tabs
  965. style={{
  966. width: '60%',
  967. margin: '20px',
  968. }}
  969. type="card"
  970. collapsible
  971. showRestInDropdown={false}
  972. >
  973. {[...Array(30).keys()].map(i => (
  974. <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={`${i}`}>
  975. Content of card tab {i}
  976. </TabPane>
  977. ))}
  978. </Tabs>
  979. )
  980. }
  981. export const Fix2415 = () => {
  982. return (
  983. <Tabs style={{ width: 250, margin: '20px' }} type="card" collapsible>
  984. {[10,2324325324324,1111].map(i => (
  985. <TabPane tab={`Tab-${i}`} itemKey={`Tab-${i}`} key={i}>
  986. Content of card tab {i}.Quickly click the right arrow and observe that the arrow is disabled correctly.
  987. </TabPane>
  988. ))}
  989. </Tabs>
  990. )
  991. }