pagination.stories.jsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import React, { useState } from 'react';
  2. // import 'normalize.css';
  3. import { Button } from '../../index';
  4. import Pagination from '../index';
  5. export default {
  6. title: 'Pagination'
  7. }
  8. export const PaginationSmall = () => (
  9. <>
  10. <Pagination total={90} size="small"></Pagination>
  11. <Pagination total={200000000} size="small" hoverShowPageSelect></Pagination>
  12. </>
  13. );
  14. PaginationSmall.story = {
  15. name: 'Pagination small',
  16. };
  17. export const PaginationDefault = () => (
  18. <div>
  19. <Pagination total={1}></Pagination>
  20. <Pagination total={0}></Pagination>
  21. <Pagination total={9}></Pagination>
  22. <Pagination total={30}></Pagination>
  23. <Pagination total={80}></Pagination>
  24. <Pagination total={200}></Pagination>
  25. <Pagination total={80} pageSize={30}></Pagination>
  26. <Pagination total={1000000000}></Pagination>
  27. </div>
  28. );
  29. PaginationDefault.story = {
  30. name: 'Pagination default',
  31. };
  32. export const PaginationHideOnSinglePage = () => (
  33. <div>
  34. <Pagination total={1} hideOnSinglePage></Pagination>
  35. <Pagination total={0} hideOnSinglePage></Pagination>
  36. <Pagination total={9} hideOnSinglePage></Pagination>
  37. <Pagination total={30} hideOnSinglePage></Pagination>
  38. </div>
  39. );
  40. PaginationHideOnSinglePage.story = {
  41. name: 'Pagination hideOnSinglePage',
  42. };
  43. export const DefaultCurrentPageDemo = () => (
  44. <div>
  45. <Pagination total={20000} defaultCurrentPage={2}></Pagination>
  46. </div>
  47. );
  48. DefaultCurrentPageDemo.story = {
  49. name: 'Pagination 指定当前页',
  50. };
  51. const ControlPage = () => {
  52. const [page, setPage] = useState(3);
  53. function onPageChange(currentPage) {
  54. setPage(currentPage);
  55. }
  56. return (
  57. <div>
  58. <Pagination total={200} currentPage={page} onPageChange={onPageChange}></Pagination>
  59. </div>
  60. );
  61. };
  62. export const ControlledPageDemo = () => <ControlPage />;
  63. ControlledPageDemo.story = {
  64. name: 'Pagination 页码受控',
  65. };
  66. export const PaginationShowPageSizeChanger = () => (
  67. <div>
  68. <Pagination total={100} showSizeChanger showTotal></Pagination>
  69. <Pagination total={200}></Pagination>
  70. <Pagination
  71. total={300}
  72. showSizeChanger
  73. pageSizeOpts={[10, 20, 50, 200]}
  74. onPageChange={(page, pageSize) => console.log(`pageChange:${page},pageSize:${pageSize}`)}
  75. onPageSizeChange={pageSize => console.log(`pageSizeChange${pageSize}`)}
  76. ></Pagination>
  77. <Pagination total={300} showSizeChanger></Pagination>
  78. </div>
  79. );
  80. PaginationShowPageSizeChanger.story = {
  81. name: 'Pagination showPageSizeChanger',
  82. };
  83. export const PaginationPageSizeOpts = () => (
  84. <div>
  85. <Pagination total={80} showSizeChanger></Pagination>
  86. <Pagination total={200}></Pagination>
  87. <Pagination total={300} showSizeChanger pageSizeOpts={[50, 80, 90, 200]}></Pagination>
  88. </div>
  89. );
  90. PaginationPageSizeOpts.story = {
  91. name: 'Pagination pageSizeOpts',
  92. };
  93. export const PaginationShowQuickJumper = () => (
  94. <div>
  95. <Pagination total={1} showSizeChanger showQuickJumper></Pagination>
  96. <Pagination total={80} showSizeChanger showQuickJumper></Pagination>
  97. <Pagination total={200} showQuickJumper></Pagination>
  98. <Pagination
  99. total={300}
  100. showSizeChanger
  101. pageSizeOpts={[50, 80, 90, 200]}
  102. showQuickJumper
  103. ></Pagination>
  104. </div>
  105. );
  106. PaginationShowQuickJumper.story = {
  107. name: 'Pagination showQuickJumper',
  108. };
  109. const DynamicPageSize = () => {
  110. const [pageSize, setPageSize] = useState(10);
  111. function changePageSize() {
  112. let map = {
  113. 10: 40,
  114. 40: 100,
  115. 100: 20,
  116. 100: 10,
  117. };
  118. setPageSize(map[pageSize]);
  119. }
  120. return (
  121. <>
  122. <Pagination total={200} showSizeChanger pageSize={pageSize}></Pagination>
  123. <br />
  124. <Button onClick={changePageSize}>change</Button>
  125. </>
  126. );
  127. };
  128. export const PaginationDynamicUpdatePageSize = () => <DynamicPageSize />;
  129. PaginationDynamicUpdatePageSize.story = {
  130. name: 'Pagination dynamic update pageSize',
  131. };
  132. export const HideOnSingePageAndShowChanger = () => {
  133. return (
  134. <Pagination total={10} hideOnSinglePage showSizeChanger style={{ marginBottom: 12 }}></Pagination>
  135. )
  136. }
  137. HideOnSingePageAndShowChanger.story = {
  138. name: 'hideOnSingelePage & showSizeChanger at same time',
  139. };
  140. export const DisabledPagination = () => {
  141. return (
  142. <div>
  143. <Pagination total={100} disabled style={{ marginBottom: 12 }} size='small'></Pagination>
  144. <Pagination total={100} disabled style={{ marginBottom: 12 }} showQuickJumper size='small'></Pagination>
  145. <Pagination total={100} disabled style={{ marginBottom: 12 }} size='small' hoverShowPageSelect></Pagination>
  146. <Pagination total={100} disabled style={{ marginBottom: 12 }} showQuickJumper></Pagination>
  147. <Pagination total={100} disabled style={{ marginBottom: 12 }} showSizeChanger></Pagination>
  148. <Pagination total={100} disabled style={{ marginBottom: 12 }} showTotal></Pagination>
  149. <Pagination total={100} disabled style={{ marginBottom: 12 }} showTotal showSizeChanger showQuickJumper></Pagination>
  150. </div>
  151. )
  152. }