@@ -2,11 +2,10 @@ import React from 'react'
22import styled from '@emotion/styled'
33import { useTable , usePagination } from 'react-table'
44import { array } from 'prop-types'
5- import { Box , Text , Button , Stack , Select , Input } from '@chakra-ui/core '
6-
5+ import { Trans } from '@lingui/macro '
6+ import { Box , Text , Stack , Select , Input , IconButton } from '@chakra-ui/core'
77import WithPseudoBox from './withPseudoBox'
88
9- // TODO: replace with values from the theme
109const Table = styled . table `
1110 & {
1211 width: 100%;
@@ -24,6 +23,10 @@ const Table = styled.table`
2423 text-align: center;
2524 }
2625
26+ .pagination {
27+ padding: 0.5rem;
28+ }
29+
2730 .title {
2831 text-align: center;
2932 }
@@ -75,6 +78,10 @@ const Table = styled.table`
7578
7679function SummaryTable ( { ...props } ) {
7780 const { data, columns } = props
81+ const defaultPageSize = window . matchMedia ( 'screen and (max-width: 760px)' )
82+ . matches
83+ ? 5
84+ : 10
7885
7986 const {
8087 getTableProps,
@@ -96,18 +103,14 @@ function SummaryTable({ ...props }) {
96103 {
97104 columns,
98105 data,
99- initialState : { pageIndex : 0 } ,
106+ initialState : { pageIndex : 0 , pageSize : defaultPageSize } ,
100107 } ,
101108 usePagination ,
102109 )
103110
104111 return (
105- < Stack align = "center" >
106- < Box overflowX = "auto" >
107- < Text fontWeight = "bold" fontSize = "3xl" textAlign = { [ 'center' ] } >
108- Domain Summary Table
109- </ Text >
110- < br />
112+ < Box >
113+ < Box width = "100%" overflowX = "auto" >
111114 < Table { ...getTableProps ( ) } flatHeaders = { flatHeaders } >
112115 < thead >
113116 { headerGroups . map ( ( headerGroup , idx ) => (
@@ -142,46 +145,64 @@ function SummaryTable({ ...props }) {
142145 </ tbody >
143146 </ Table >
144147 </ Box >
145- < Stack className = "pagination" isInline >
146- < Button onClick = { ( ) => gotoPage ( 0 ) } disabled = { ! canPreviousPage } >
147- { '<<' }
148- </ Button > { ' ' }
149- < Button onClick = { ( ) => previousPage ( ) } disabled = { ! canPreviousPage } >
150- { '<' }
151- </ Button > { ' ' }
152- < Button onClick = { ( ) => nextPage ( ) } disabled = { ! canNextPage } >
153- { '>' }
154- </ Button > { ' ' }
155- < Button onClick = { ( ) => gotoPage ( pageCount - 1 ) } disabled = { ! canNextPage } >
156- { '>>' }
157- </ Button > { ' ' }
158- < Text fontWeight = "semibold" >
159- Page { pageIndex + 1 } of { pageOptions . length } { ' ' }
160- </ Text >
161- < Text > | Go to page: </ Text >
162- < Input
163- width = "60px"
164- type = "number"
165- onChange = { ( e ) => {
166- const page = e . target . value ? Number ( e . target . value ) - 1 : 0
167- gotoPage ( page )
168- } }
169- /> { ' ' }
170- < Select
171- w = "30"
172- value = { pageSize }
173- onChange = { ( e ) => {
174- setPageSize ( Number ( e . target . value ) )
175- } }
176- >
177- { [ 10 , 20 , 30 , 40 , 50 ] . map ( ( pageSize ) => (
178- < option key = { pageSize } value = { pageSize } >
179- Show { pageSize }
180- </ option >
181- ) ) }
182- </ Select >
183- </ Stack >
184- </ Stack >
148+ < Box className = "pagination" >
149+ < Stack isInline align = "center" flexWrap = "wrap" justify = "space-between" >
150+ < Stack spacing = "1em" isInline align = "center" flexWrap = "wrap" >
151+ < IconButton
152+ icon = "arrow-left"
153+ onClick = { ( ) => gotoPage ( 0 ) }
154+ disabled = { ! canPreviousPage }
155+ />
156+ < IconButton
157+ icon = "chevron-left"
158+ onClick = { ( ) => previousPage ( ) }
159+ disabled = { ! canPreviousPage }
160+ />
161+ < IconButton
162+ icon = "chevron-right"
163+ onClick = { ( ) => nextPage ( ) }
164+ disabled = { ! canNextPage }
165+ />
166+ < IconButton
167+ icon = "arrow-right"
168+ onClick = { ( ) => gotoPage ( pageCount - 1 ) }
169+ disabled = { ! canNextPage }
170+ />
171+ < Text fontWeight = "semibold" >
172+ < Trans > Page</ Trans > { pageIndex + 1 } < Trans > of</ Trans > { ' ' }
173+ { pageOptions . length } { ' ' }
174+ </ Text >
175+ </ Stack >
176+ < Stack spacing = "1em" isInline align = "center" flexWrap = "wrap" >
177+ < Text fontWeight = "semibold" >
178+ < Trans > Go to page: </ Trans >
179+ </ Text >
180+ < Input
181+ variant = "outline"
182+ width = "60px"
183+ type = "number"
184+ onChange = { ( e ) => {
185+ const page = e . target . value ? Number ( e . target . value ) - 1 : 0
186+ gotoPage ( page )
187+ } }
188+ /> { ' ' }
189+ < Select
190+ w = "30"
191+ value = { pageSize }
192+ onChange = { ( e ) => {
193+ setPageSize ( Number ( e . target . value ) )
194+ } }
195+ >
196+ { [ 5 , 10 , 20 ] . map ( ( pageSize ) => (
197+ < option key = { pageSize } value = { pageSize } >
198+ Show { pageSize }
199+ </ option >
200+ ) ) }
201+ </ Select >
202+ </ Stack >
203+ </ Stack >
204+ </ Box >
205+ </ Box >
185206 )
186207}
187208
0 commit comments