From 91816fcc0129d1a7f6a74d9ebfe9ccd73f2f967b Mon Sep 17 00:00:00 2001 From: AllenFang Date: Fri, 21 Dec 2018 17:48:20 +0800 Subject: [PATCH] add stories for custom pagination --- .../examples/pagination/custom-page-button.js | 106 +++++++++++ .../examples/pagination/custom-page-list.js | 78 ++++++++ .../pagination/custom-size-per-page-option.js | 96 ++++++++++ .../pagination/custom-size-per-page.js | 89 ++++++++++ .../pagination/fully-custom-pagination.js | 166 ++++++++++++++++++ .../pagination/standalone-pagination-list.js | 102 +++++++++++ .../pagination/standalone-size-per-page.js | 102 +++++++++++ .../stories/index.js | 16 +- 8 files changed, 754 insertions(+), 1 deletion(-) create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/custom-page-button.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/custom-page-list.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page-option.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/fully-custom-pagination.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-list.js create mode 100644 packages/react-bootstrap-table2-example/examples/pagination/standalone-size-per-page.js diff --git a/packages/react-bootstrap-table2-example/examples/pagination/custom-page-button.js b/packages/react-bootstrap-table2-example/examples/pagination/custom-page-button.js new file mode 100644 index 0000000..4898f60 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/custom-page-button.js @@ -0,0 +1,106 @@ +/* eslint react/prefer-stateless-function: 0 */ +/* eslint react/prop-types: 0 */ +/* eslint jsx-a11y/href-no-hash: 0 */ +/* eslint no-unused-vars: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +// ... + +const pageButtonRenderer = ({ + page, + active, + disable, + title, + onPageChange +}) => { + const handleClick = (e) => { + e.preventDefault(); + onPageChange(page); + }; + const activeStyle = {}; + if (active) { + activeStyle.backgroundColor = 'black'; + activeStyle.color = 'white'; + } else { + activeStyle.backgroundColor = 'gray'; + activeStyle.color = 'black'; + } + if (typeof page === 'string') { + activeStyle.backgroundColor = 'white'; + activeStyle.color = 'black'; + } + return ( +
  • + { page } +
  • + ); +}; + +const options = { + pageButtonRenderer +}; + + +`; + +const pageButtonRenderer = ({ + page, + active, + disable, + title, + onPageChange +}) => { + const handleClick = (e) => { + e.preventDefault(); + onPageChange(page); + }; + const activeStyle = {}; + if (active) { + activeStyle.backgroundColor = 'black'; + activeStyle.color = 'white'; + } else { + activeStyle.backgroundColor = 'gray'; + activeStyle.color = 'black'; + } + if (typeof page === 'string') { + activeStyle.backgroundColor = 'white'; + activeStyle.color = 'black'; + } + return ( +
  • + { page } +
  • + ); +}; + +const options = { + pageButtonRenderer +}; + +export default () => ( +
    + + { sourceCode } +
    +); diff --git a/packages/react-bootstrap-table2-example/examples/pagination/custom-page-list.js b/packages/react-bootstrap-table2-example/examples/pagination/custom-page-list.js new file mode 100644 index 0000000..2198aa5 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/custom-page-list.js @@ -0,0 +1,78 @@ +/* eslint react/prefer-stateless-function: 0 */ +/* eslint react/prop-types: 0 */ +/* eslint jsx-a11y/href-no-hash: 0 */ +/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +// ... + +const pageListRenderer = ({ + pages, + onPageChange +}) => { + const pageWithoutIndication = pages.filter(p => typeof p.page !== 'string'); + return ( +
    + { + pageWithoutIndication.map(p => ( + + )) + } +
    + ); +}; + +const options = { + pageListRenderer +}; + + +`; + +const pageListRenderer = ({ + pages, + onPageChange +}) => { + const pageWithoutIndication = pages.filter(p => typeof p.page !== 'string'); + return ( +
    + { + pageWithoutIndication.map(p => ( + + )) + } +
    + ); +}; + +const options = { + pageListRenderer +}; + +export default () => ( +
    + + { sourceCode } +
    +); diff --git a/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page-option.js b/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page-option.js new file mode 100644 index 0000000..362bee6 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page-option.js @@ -0,0 +1,96 @@ +/* eslint react/prop-types: 0 */ +/* eslint jsx-a11y/href-no-hash: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +// ... + +const sizePerPageOptionRenderer = ({ + text, + page, + onSizePerPageChange +}) => ( +
  • + { + e.preventDefault(); + onSizePerPageChange(page); + } } + style={ { color: 'red' } } + > + { text } + +
  • +); + +const options = { + sizePerPageOptionRenderer +}; + + +`; + +const sizePerPageOptionRenderer = ({ + text, + page, + onSizePerPageChange +}) => ( +
  • + { + e.preventDefault(); + onSizePerPageChange(page); + } } + style={ { color: 'red' } } + > + { text } + +
  • +); + +const options = { + sizePerPageOptionRenderer +}; + +export default () => ( +
    + + { sourceCode } +
    +); diff --git a/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page.js b/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page.js new file mode 100644 index 0000000..a8bbf42 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/custom-size-per-page.js @@ -0,0 +1,89 @@ +/* eslint react/prop-types: 0 */ +/* eslint jsx-a11y/href-no-hash: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; +// ... + +const sizePerPageRenderer = ({ + options, + currSizePerPage, + onSizePerPageChange +}) => ( +
    + { + options.map((option) => { + const isSelect = currSizePerPage === \`$\{option.page}\`; + return ( + + ); + }) + } +
    +); + +const options = { + sizePerPageRenderer +}; + +s +`; + +const sizePerPageRenderer = ({ + options, + currSizePerPage, + onSizePerPageChange +}) => ( +
    + { + options.map(option => ( + + )) + } +
    +); + +const options = { + sizePerPageRenderer +}; + +export default () => ( +
    + + { sourceCode } +
    +); diff --git a/packages/react-bootstrap-table2-example/examples/pagination/fully-custom-pagination.js b/packages/react-bootstrap-table2-example/examples/pagination/fully-custom-pagination.js new file mode 100644 index 0000000..a2aa739 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/fully-custom-pagination.js @@ -0,0 +1,166 @@ +/* eslint react/prefer-stateless-function: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory, { PaginationProvider } from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory from 'react-bootstrap-table2-paginator'; + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const options = { + custom: true, + totalSize: products.length +}; + +class FullyCustomPagination extends React.Component { + handleNextPage = ({ + page, + onPageChange + }) => () => { + onPageChange(page + 1); + } + + handlePrevPage = ({ + page, + onPageChange + }) => () => { + onPageChange(page - 1); + } + + handleSizePerPage = ({ + page, + onSizePerPageChange + }, newSizePerPage) => { + onSizePerPageChange(newSizePerPage, page); + } + + render() { + return ( +
    + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    +
    +

    Current Page: { paginationProps.page }

    +

    Current SizePerPage: { paginationProps.sizePerPage }

    +
    +
    + + + + +
    + +
    + ) + } +
    + { sourceCode } +
    + ); + } +} +`; + +const options = { + custom: true, + totalSize: products.length +}; + +export default class FullyCustomPagination extends React.Component { + handleNextPage = ({ + page, + onPageChange + }) => () => { + onPageChange(page + 1); + } + + handlePrevPage = ({ + page, + onPageChange + }) => () => { + onPageChange(page - 1); + } + + handleSizePerPage = ({ + page, + onSizePerPageChange + }, newSizePerPage) => { + onSizePerPageChange(newSizePerPage, page); + } + + render() { + return ( +
    + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    +
    +

    Current Page: { paginationProps.page }

    +

    Current SizePerPage: { paginationProps.sizePerPage }

    +
    +
    + + + + +
    + +
    + ) + } +
    + { sourceCode } +
    + ); + } +} diff --git a/packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-list.js b/packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-list.js new file mode 100644 index 0000000..bec241e --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/standalone-pagination-list.js @@ -0,0 +1,102 @@ +/* eslint react/prefer-stateless-function: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator'; + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const options = { + custom: true, + totalSize: products.length +}; + + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    + + +
    + ) + } +
    +`; + +const options = { + custom: true, + totalSize: products.length +}; +// const pagination = paginationFactory(options); + +export default class StandalonePaginationList extends React.Component { + render() { + return ( +
    + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    + + +
    + ) + } +
    + { sourceCode } +
    + ); + } +} diff --git a/packages/react-bootstrap-table2-example/examples/pagination/standalone-size-per-page.js b/packages/react-bootstrap-table2-example/examples/pagination/standalone-size-per-page.js new file mode 100644 index 0000000..66ecb6f --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/pagination/standalone-size-per-page.js @@ -0,0 +1,102 @@ +/* eslint react/prefer-stateless-function: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory, { PaginationProvider, SizePerPageDropdownStandalone } from 'react-bootstrap-table2-paginator'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(87); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import paginationFactory, { PaginationProvider, SizePerPageDropdownStandalone } from 'react-bootstrap-table2-paginator'; + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const options = { + custom: true, + totalSize: products.length +}; + + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    + + +
    + ) + } +
    +`; + +const options = { + custom: true, + totalSize: products.length +}; +// const pagination = paginationFactory(options); + +export default class StandaloneSizePerPage extends React.Component { + render() { + return ( +
    + + { + ({ + paginationProps, + paginationBaseProps + }) => ( +
    + + +
    + ) + } +
    + { sourceCode } +
    + ); + } +} diff --git a/packages/react-bootstrap-table2-example/stories/index.js b/packages/react-bootstrap-table2-example/stories/index.js index fe2eecd..ef20d12 100644 --- a/packages/react-bootstrap-table2-example/stories/index.js +++ b/packages/react-bootstrap-table2-example/stories/index.js @@ -147,6 +147,13 @@ import ExpandHooks from 'examples/row-expand/expand-hooks'; import PaginationTable from 'examples/pagination'; import PaginationHooksTable from 'examples/pagination/pagination-hooks'; import CustomPaginationTable from 'examples/pagination/custom-pagination'; +import CustomPageButtonTable from 'examples/pagination/custom-page-button'; +import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option'; +import CustomSizePerPageTable from 'examples/pagination/custom-size-per-page'; +import CustomPageListTable from 'examples/pagination/custom-page-list'; +import StandalonePaginationList from 'examples/pagination/standalone-pagination-list'; +import StandaloneSizePerPage from 'examples/pagination/standalone-size-per-page'; +import FullyCustomPaginationTable from 'examples/pagination/fully-custom-pagination'; // search import SearchTable from 'examples/search'; @@ -345,7 +352,14 @@ storiesOf('Pagination', module) .addDecorator(bootstrapStyle()) .add('Basic Pagination Table', () => ) .add('Pagination Hooks', () => ) - .add('Custom Pagination', () => ); + .add('Custom Pagination', () => ) + .add('Custom Page Button', () => ) + .add('Custom Page List', () => ) + .add('Custom SizePerPage Option', () => ) + .add('Custom SizePerPage', () => ) + .add('Standalone Pagination List', () => ) + .add('Standalone SizePerPage Dropdown', () => ) + .add('Fully Custom Pagination', () => ); storiesOf('Table Search', module) .addDecorator(bootstrapStyle())