table.stories.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. import React from 'react';
  2. import { Table } from '@douyinfe/semi-ui';
  3. import JSXColumnsSimple from './JSXColumnsSmiple';
  4. import JSXColumnsComplex from './JSXColumnsComplex';
  5. import JSXColumnPropColumn from './JSXColumnPropColumn';
  6. import ResizableColumns from './ResizableColumns';
  7. import DragableTableDemo from './DragableTable';
  8. import DynamicTableDemo from './DynamicTable';
  9. import LinkedScroll from './LinkedScroll';
  10. import ModalTable from './ModalTable';
  11. import TabsTable from './TabsTable';
  12. import EventTable from './EventTable';
  13. import FnTable from './FnTable';
  14. import DynamicFilters from './DynamicFilters';
  15. import ResizableTable from './ResizableTable';
  16. import ExpandDemo from './Expand';
  17. import PaginationDemo from './PagintaionTable';
  18. import SelectedRowsDemo from './SelectedRows';
  19. import ChildrenData from './ChildrenData';
  20. import ChildrenDataSelected from './ChildrenDataSelected';
  21. import FixedExpandedRows from './FixedExpandedRows';
  22. import FixedTable from './FixedTable';
  23. import JSXFixedTable from './JSXFixedTable';
  24. import JSXTitles from './JSXTitles';
  25. import CustomFilterDropdownItem from './CustomFilterDropdownItem';
  26. import VirtualizedDemo from './virtualized';
  27. import VirtualizedNotFixed from './VirtualizedNotFixed';
  28. import InfiniteScroll from './InfiniteScroll';
  29. import VirtualTableOnCell from './VirtualTableOnCell';
  30. import {
  31. ControlledSelection,
  32. PerfComplexRender,
  33. PerfContext,
  34. PerfOnRow,
  35. PerfRender,
  36. PerfResizableSelection,
  37. PerfVirtualized,
  38. } from './Perf';
  39. import RenderPagination from './RenderPagination';
  40. import ControlledSortOrder from './ControlledSortOrder';
  41. import FilterWithNewDataTable from './FilterWithNewDataTable';
  42. import ExpandAllRows from './ExpandAllRows';
  43. import ExpandAllGroupRows from './ExpandAllGroupRows';
  44. import ExpandRowByClick from './ExpandRowByClick';
  45. import FixAllColumnsWithoutWidth from './FixAllColumnsWithoutWidth';
  46. export default {
  47. title: 'Table'
  48. }
  49. export { default as WithSideSheet } from './WithSideSheet';
  50. export { default as InSideSheet } from './InSideSheet';
  51. export { default as GroupedCols } from './GroupedCols';
  52. export { default as GroupedColsFixed } from './GroupedColsFixed';
  53. export { default as GroupedColsFixedJSX } from './GroupedColsFixedJSX';
  54. export { default as GroupedColsFixedVirtualized } from './GroupedColsFixedVirtualized';
  55. export { default as GroupedColsFixedVirtualizedGroups } from './GroupedColsFixedVirtualizedGroups';
  56. export { default as GroupedRows } from './GroupedRows';
  57. export { default as GroupedRowsFixed } from './GroupedRowsFixed';
  58. export { default as FixedGroups } from './FixedGroups';
  59. export { default as CustomComponents } from './CustomComponents';
  60. export { default as CustomExpandIcons } from './CustomExpandIcons';
  61. export { default as VirtualizedFixedDemo } from './virtualizedFixed';
  62. export { default as VirtualizedGroupedRows } from './VirtualizedGroupedRows';
  63. export { default as VirtualizedDataSelected } from './VritualizedDataSelected';
  64. export { default as VirtualizedDynamicData } from './VirtualizedDynamicData';
  65. export { default as MassiveColumns } from './MassiveColumns';
  66. export { default as ControlledPagination } from './ControlledPagination';
  67. export { default as FulldRenderDemo } from './FullRender';
  68. export { RTLAlignScrollBar } from './RTL';
  69. export { default as JSXAsyncData } from './JSXAsyncData';
  70. export { default as ScrollBar } from './ScrollBar';
  71. export { default as TableSpan } from './TableSpan';
  72. export { default as FixRenderReturnProps } from './FixRenderReturnProps';
  73. export { default as WarnColumnWithoutDataIndex } from './WarnColumnWithoutDataIndex';
  74. export { default as FixedColumnsChange } from './v2/FixedColumnsChange';
  75. export { default as FixedZIndex } from './v2/FixedZIndex';
  76. export { default as FixedHeaderMerge } from './v2/FixedHeaderMerge';
  77. // empty table
  78. const emptyColumn = [
  79. {
  80. title: 'Name',
  81. dataIndex: 'name',
  82. fixed: 'left',
  83. render: text => <a>{text}</a>,
  84. },
  85. {
  86. title: 'Age',
  87. dataIndex: 'age',
  88. },
  89. {
  90. title: 'Address',
  91. dataIndex: 'address',
  92. },
  93. ];
  94. const emptyData = [];
  95. export const EmptyTable = () => <Table autoWidth columns={emptyColumn} dataSource={emptyData} />;
  96. EmptyTable.story = {
  97. name: 'empty table',
  98. };
  99. // basic table
  100. const columns = [
  101. {
  102. title: 'Name',
  103. dataIndex: 'name',
  104. width: '30%',
  105. render: text => <a>{text}</a>,
  106. },
  107. {
  108. title: 'combine',
  109. width: '20%',
  110. dataIndex: 'test',
  111. children: [
  112. {
  113. title: 'Age',
  114. width: '20%',
  115. children: [
  116. {
  117. title: 'Age1',
  118. width: '20%',
  119. dataIndex: 'age1',
  120. },
  121. {
  122. title: 'Age2',
  123. width: '20%',
  124. dataIndex: 'age2',
  125. },
  126. ],
  127. },
  128. {
  129. title: 'Key',
  130. width: '20%',
  131. dataIndex: 'key',
  132. },
  133. ],
  134. },
  135. {
  136. title: 'Address',
  137. width: '50%',
  138. dataIndex: 'address',
  139. },
  140. ];
  141. const data = [
  142. {
  143. key: '1',
  144. name: 'John Brown',
  145. age: 32,
  146. age1: 23,
  147. age2: 11,
  148. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  149. },
  150. {
  151. key: '2',
  152. name: 'Jim Green',
  153. age: 42,
  154. age1: 23,
  155. age2: 11,
  156. address: 'London No. 1 Lake Park',
  157. },
  158. {
  159. key: '3',
  160. name: 'Joe Black',
  161. age: 32,
  162. age1: 23,
  163. age2: 11,
  164. address: 'Sidney No. 1 Lake Park',
  165. },
  166. {
  167. key: '4',
  168. name: 'Disabled User',
  169. age: 99,
  170. age1: 23,
  171. age2: 11,
  172. address: 'Sidney No. 1 Lake Park',
  173. },
  174. ];
  175. export const BasicTable = () => <Table columns={columns} dataSource={data} />;
  176. BasicTable.story = {
  177. name: 'basic table',
  178. };
  179. export const SimpleJsx = () => <JSXColumnsSimple />;
  180. SimpleJsx.story = {
  181. name: 'simple jsx',
  182. };
  183. export const ComplexJsx = () => <JSXColumnsComplex />;
  184. ComplexJsx.story = {
  185. name: 'complex jsx',
  186. };
  187. ComplexJsx.parameters = {
  188. chromatic: { disableSnapshot: true },
  189. }
  190. // selection table
  191. // rowSelection object indicates the need for row selection
  192. const rowSelection = {
  193. onChange: (selectedRowKeys, selectedRows) => {
  194. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  195. },
  196. getCheckboxProps: record => ({
  197. disabled: record.name === 'Disabled User', // Column configuration not to be checked
  198. name: record.name,
  199. }),
  200. };
  201. export const FilterAndUpdateDataSource = () => <FilterWithNewDataTable />;
  202. FilterAndUpdateDataSource.story = {
  203. name: 'filter and update dataSource',
  204. };
  205. export const SelectionTable = () => (
  206. <Table rowSelection={rowSelection} columns={columns} dataSource={data} />
  207. );
  208. SelectionTable.story = {
  209. name: 'selection table',
  210. };
  211. function ControlledSelectionTable() {
  212. const [selected, setSelected] = React.useState([]);
  213. const columns = [
  214. {
  215. title: 'Name',
  216. dataIndex: 'name',
  217. render: text => text,
  218. },
  219. {
  220. title: 'Age',
  221. dataIndex: 'age',
  222. },
  223. {
  224. title: 'Address',
  225. dataIndex: 'address',
  226. },
  227. ];
  228. const data = [
  229. {
  230. key: '1',
  231. name: 'John Brown',
  232. age: 32,
  233. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  234. },
  235. {
  236. key: '2',
  237. name: 'Jim Green',
  238. age: 42,
  239. address: 'London No. 1 Lake Park',
  240. },
  241. {
  242. key: '3',
  243. name: 'Joe Black',
  244. age: 32,
  245. address: 'Sidney No. 1 Lake Park',
  246. },
  247. {
  248. key: '4',
  249. name: 'Michael James',
  250. age: 99,
  251. address: 'Sidney No. 1 Lake Park',
  252. },
  253. ];
  254. const rowSelection = {
  255. onChange: (selectedRowKeys, selectedRows) => {
  256. setSelected(selectedRowKeys);
  257. },
  258. getCheckboxProps: record => ({
  259. disabled: selected.length === 2 && selected.findIndex(key => key === record.key) === -1, // Column configuration not to be checked
  260. name: record.name,
  261. }),
  262. selectedRowKeys: selected,
  263. };
  264. return (
  265. <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={false} />
  266. );
  267. }
  268. export const _ControlledSelectionTable = () => <ControlledSelectionTable />;
  269. _ControlledSelectionTable.story = {
  270. name: 'controlled selection table',
  271. };
  272. _ControlledSelectionTable.parameters = {
  273. chromatic: { disableSnapshot: true },
  274. }
  275. // sortable table
  276. const sortColumns = [
  277. {
  278. title: 'Name',
  279. dataIndex: 'name',
  280. filters: [
  281. {
  282. text: 'XiaoMing',
  283. value: 'XiaoMing',
  284. },
  285. {
  286. text: 'ZhangSan',
  287. value: 'ZhangSan',
  288. },
  289. {
  290. text: 'SubMenu',
  291. value: 'SubMenu',
  292. children: [
  293. {
  294. text: 'Yellow',
  295. value: 'Yellow',
  296. },
  297. {
  298. text: 'Pink',
  299. value: 'Pink',
  300. },
  301. ],
  302. },
  303. ],
  304. onFilter: (value, record) => record.name.indexOf(value) === 0,
  305. sorter: (a, b) => a.name.length - b.name.length,
  306. sortDirections: ['descend'],
  307. sortOrder: 'descend',
  308. },
  309. {
  310. title: 'Age',
  311. dataIndex: 'age',
  312. defaultSortOrder: 'descend',
  313. sorter: (a, b) => a.age - b.age,
  314. },
  315. {
  316. title: 'Address',
  317. dataIndex: 'address',
  318. filters: [
  319. {
  320. text: 'BieJing',
  321. value: 'BeiJing',
  322. },
  323. {
  324. text: 'ShangHai',
  325. value: 'SHangHai',
  326. },
  327. ],
  328. filterMultiple: false,
  329. onFilter: (value, record) => record.address.indexOf(value) === 0,
  330. sorter: (a, b) => a.address.length - b.address.length,
  331. sortDirections: ['descend', 'ascend'],
  332. },
  333. ];
  334. const sortData = [
  335. {
  336. key: '1',
  337. name: 'ZhangSan',
  338. age: 50,
  339. address: 'BeiJing No.1 High School',
  340. },
  341. {
  342. key: '2',
  343. name: 'LiSi',
  344. age: 60,
  345. address: 'BeiJing No.2 High School',
  346. },
  347. {
  348. key: '3',
  349. name: 'WangWu',
  350. age: 20,
  351. address: 'BeiJing No.3 High School',
  352. },
  353. {
  354. key: '4',
  355. name: 'XiaoMing',
  356. age: 30,
  357. address: 'BeiJing No.5 High School',
  358. },
  359. ];
  360. export const SortTable = () => <Table columns={sortColumns} dataSource={sortData} />;
  361. SortTable.story = {
  362. name: 'sort table',
  363. };
  364. export const ControlledSortOrderTable = () => <ControlledSortOrder />;
  365. ControlledSortOrderTable.story = {
  366. name: 'controlled sortOrder table',
  367. };
  368. export const MiddleTable = () => <Table columns={columns} dataSource={data} size="middle" />;
  369. MiddleTable.story = {
  370. name: 'middle table',
  371. };
  372. export const SmallTable = () => <Table columns={columns} dataSource={data} size="small" />;
  373. SmallTable.story = {
  374. name: 'small table',
  375. };
  376. export const ExpandTable = () => <ExpandDemo />;
  377. ExpandTable.story = {
  378. name: 'expand table',
  379. };
  380. export const _ResizableColumns = () => <ResizableColumns />;
  381. _ResizableColumns.story = {
  382. name: 'resizable columns',
  383. };
  384. export const DragableTable = () => <DragableTableDemo />;
  385. DragableTable.story = {
  386. name: 'dragable table',
  387. };
  388. DragableTable.parameters = {
  389. chromatic: { disableSnapshot: true },
  390. }
  391. export const _FixedTable = () => <FixedTable />;
  392. _FixedTable.story = {
  393. name: 'fixed table',
  394. };
  395. _FixedTable.parameters = {
  396. chromatic: { disableSnapshot: true },
  397. }
  398. export const FixedJsxTable = () => <JSXFixedTable />;
  399. FixedJsxTable.story = {
  400. name: 'fixed jsx table',
  401. };
  402. export const JSXTitlesDemo = () => <JSXTitles />;
  403. JSXTitlesDemo.story = {
  404. name: 'jsx titles'
  405. };
  406. export const DynamicTable = () => (
  407. <div style={{ padding: 20 }}>
  408. <DynamicTableDemo />
  409. </div>
  410. );
  411. DynamicTable.story = {
  412. name: 'dynamic table',
  413. };
  414. export const _LinkedScroll = () => <LinkedScroll />;
  415. _LinkedScroll.story = {
  416. name: 'linked scroll',
  417. };
  418. export const _ModalTable = () => <ModalTable />;
  419. _ModalTable.story = {
  420. name: 'modal table',
  421. };
  422. export const _TabsTable = () => <TabsTable />;
  423. _TabsTable.story = {
  424. name: 'tabs table',
  425. };
  426. export const _EventTable = () => <EventTable />;
  427. _EventTable.story = {
  428. name: 'event table',
  429. };
  430. export const _FnTable = () => <FnTable />;
  431. _FnTable.story = {
  432. name: 'fn table',
  433. };
  434. export const _DynamicFilters = () => <DynamicFilters />;
  435. _DynamicFilters.story = {
  436. name: 'dynamic filters',
  437. };
  438. export const _ResizableTable = () => <ResizableTable />;
  439. _ResizableTable.story = {
  440. name: 'resizable table',
  441. };
  442. export const WithPagination = () => <PaginationDemo />;
  443. WithPagination.story = {
  444. name: 'with pagination',
  445. };
  446. export const SelectedRows = () => <SelectedRowsDemo />;
  447. SelectedRows.story = {
  448. name: 'selected rows',
  449. };
  450. export const _ChildrenData = () => <ChildrenData />;
  451. _ChildrenData.story = {
  452. name: 'children data',
  453. };
  454. export const ChildrenDataSelectedRows = () => <ChildrenDataSelected />;
  455. ChildrenDataSelectedRows.story = {
  456. name: 'children data selected rows',
  457. };
  458. export const _ExpandAllRows = () => <ExpandAllRows />;
  459. _ExpandAllRows.story = {
  460. name: 'expandAllRows',
  461. };
  462. export const _ExpandAllGroupRows = () => <ExpandAllGroupRows />;
  463. _ExpandAllGroupRows.story = {
  464. name: 'expandAllGroupRows',
  465. };
  466. export const _ExpandRowByClick = () => <ExpandRowByClick />;
  467. _ExpandRowByClick.story = {
  468. name: 'expandRowByClick',
  469. };
  470. export const RowSelectionBoolean = () => <Table columns={columns} dataSource={data} rowSelection />;
  471. RowSelectionBoolean.story = {
  472. name: 'rowSelection boolean',
  473. };
  474. export const _FixAllColumnsWithoutWidth = () => <FixAllColumnsWithoutWidth />;
  475. _FixAllColumnsWithoutWidth.story = {
  476. name: 'fix all columns without width',
  477. };
  478. export const JSXColumnPropColumnDemo = () => <JSXColumnPropColumn />;
  479. export const FixedExpandedRowsDemo = () => <FixedExpandedRows />;
  480. FixedExpandedRowsDemo.parameters = {
  481. chromatic: { disableSnapshot: true },
  482. }
  483. export const CustomFilterDropdownItemDemo = () => <CustomFilterDropdownItem />;
  484. export const Virtualized = () => <VirtualizedDemo />;
  485. export const VirtualizedNotFixedDemo = () => <VirtualizedNotFixed />;
  486. export const InfiniteScrollDemo = () => <InfiniteScroll />;
  487. export const VirtualTableOnCellDemo = () => <VirtualTableOnCell />;
  488. export const ControlledSelectionDemo = () => <ControlledSelection />;
  489. ControlledSelectionDemo.parameters = {
  490. chromatic: { disableSnapshot: true },
  491. }
  492. export const PerfComplexRenderDemo = () => <PerfComplexRender />;
  493. PerfComplexRenderDemo.parameters = {
  494. chromatic: { disableSnapshot: true },
  495. }
  496. export const PerfContextDemo = () => <PerfContext />;
  497. export const PerfOnRowDemo = () => <PerfOnRow />;
  498. PerfOnRowDemo.parameters = {
  499. chromatic: { disableSnapshot: true },
  500. }
  501. export const PerfResizableSelectionDemo = () => <PerfResizableSelection />;
  502. PerfResizableSelectionDemo.parameters = {
  503. chromatic: { disableSnapshot: true },
  504. }
  505. export const PerfVirtualizedDemo = () => <PerfVirtualized />;
  506. export const PerfRenderDemo = () => <PerfRender />;
  507. PerfRenderDemo.parameters = {
  508. chromatic: { disableSnapshot: true },
  509. }
  510. export const RenderPaginationDemo = () => <RenderPagination />;