table.stories.jsx 14 KB

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