tabs.stories.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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 } from '@douyinfe/semi-ui';
  7. import Icon from '../../icons';
  8. import { IconFile, IconGlobe, IconHelpCircle } 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" itemKey="bar">
  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}`}>
  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}`}>
  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}`}>
  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. };