table.stories.jsx 15 KB

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