-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pager service and EuiTablePagination component (#178)
* Add Pager service and tests. * Add EuiTablePagination component and document it.
- Loading branch information
Showing
15 changed files
with
521 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/components/table/table_pagination/__snapshots__/table_pagination.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiTablePagination is rendered 1`] = ` | ||
<div | ||
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--justifyContentSpaceBetween euiFlexGroup--responsive" | ||
> | ||
<div | ||
class="euiFlexItem euiFlexItem--flexGrowZero" | ||
> | ||
<div | ||
class="euiPopover euiPopover--anchorUpRight euiPopover--withTitle" | ||
> | ||
<button | ||
aria-controls="customizablePagination" | ||
aria-expanded="false" | ||
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--small euiButtonEmpty--iconRight" | ||
type="button" | ||
> | ||
<span | ||
class="euiButtonEmpty__content" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="euiIcon euiButtonEmpty__icon euiIcon--medium" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
width="16" | ||
xlink="http://www.w3.org/1999/xlink" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<defs> | ||
<path | ||
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z" | ||
id="arrow_down-a" | ||
/> | ||
</defs> | ||
<use | ||
fill-rule="nonzero" | ||
href="#arrow_down-a" | ||
/> | ||
</svg> | ||
<span> | ||
Rows per page: 50 | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
<div | ||
class="euiFlexItem euiFlexItem--flexGrowZero" | ||
> | ||
<div | ||
class="euiPagination" | ||
> | ||
<button | ||
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--small euiPaginationButton" | ||
type="button" | ||
> | ||
<span | ||
class="euiButtonEmpty__content" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="euiIcon euiButtonEmpty__icon euiIcon--medium" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
width="16" | ||
xlink="http://www.w3.org/1999/xlink" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<defs> | ||
<path | ||
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z" | ||
id="arrow_left-a" | ||
/> | ||
</defs> | ||
<use | ||
fill-rule="nonzero" | ||
href="#arrow_left-a" | ||
transform="rotate(90 8 8)" | ||
/> | ||
</svg> | ||
<span> | ||
Previous | ||
</span> | ||
</span> | ||
</button> | ||
<button | ||
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--small euiButtonEmpty--iconRight euiPaginationButton" | ||
type="button" | ||
> | ||
<span | ||
class="euiButtonEmpty__content" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="euiIcon euiButtonEmpty__icon euiIcon--medium" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
width="16" | ||
xlink="http://www.w3.org/1999/xlink" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<defs> | ||
<path | ||
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z" | ||
id="arrow_right-a" | ||
/> | ||
</defs> | ||
<use | ||
fill-rule="nonzero" | ||
href="#arrow_right-a" | ||
transform="matrix(0 1 1 0 0 0)" | ||
/> | ||
</svg> | ||
<span> | ||
Next | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { EuiTablePagination } from './table_pagination'; |
111 changes: 111 additions & 0 deletions
111
src/components/table/table_pagination/table_pagination.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
EuiButtonEmpty, | ||
EuiContextMenuItem, | ||
EuiContextMenuPanel, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPagination, | ||
EuiPopover, | ||
} from '../../../../src/components'; | ||
|
||
export class EuiTablePagination extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
isPopoverOpen: false, | ||
}; | ||
} | ||
|
||
onButtonClick = () => { | ||
this.setState({ | ||
isPopoverOpen: !this.state.isPopoverOpen, | ||
}); | ||
}; | ||
|
||
closePopover = () => { | ||
this.setState({ | ||
isPopoverOpen: false, | ||
}); | ||
}; | ||
|
||
render() { | ||
const { | ||
activePage, | ||
itemsPerPage, | ||
itemsPerPageOptions, | ||
onChangeItemsPerPage, | ||
onChangePage, | ||
pageCount, | ||
} = this.props; | ||
|
||
const button = ( | ||
<EuiButtonEmpty | ||
size="s" | ||
color="text" | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={this.onButtonClick} | ||
> | ||
{`Rows per page: ${itemsPerPage}`} | ||
</EuiButtonEmpty> | ||
); | ||
|
||
const items = itemsPerPageOptions.map(itemsPerPageOption => ( | ||
<EuiContextMenuItem | ||
key={itemsPerPageOption} | ||
icon={itemsPerPageOption === itemsPerPage ? 'check' : 'empty'} | ||
onClick={() => { this.closePopover(); onChangeItemsPerPage(itemsPerPageOption); }} | ||
> | ||
{`${itemsPerPageOption} rows`} | ||
</EuiContextMenuItem> | ||
)); | ||
|
||
return ( | ||
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiPopover | ||
id="customizablePagination" | ||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover} | ||
panelPaddingSize="none" | ||
withTitle | ||
anchorPosition="upRight" | ||
> | ||
<EuiContextMenuPanel | ||
items={items} | ||
/> | ||
</EuiPopover> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiPagination | ||
pageCount={pageCount} | ||
activePage={activePage} | ||
onPageClick={onChangePage} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
} | ||
|
||
EuiTablePagination.propTypes = { | ||
activePage: PropTypes.number, | ||
itemsPerPage: PropTypes.number, | ||
itemsPerPageOptions: PropTypes.arrayOf(PropTypes.number), | ||
onChangeItemsPerPage: PropTypes.func, | ||
onChangePage: PropTypes.func, | ||
pageCount: PropTypes.number, | ||
}; | ||
|
||
EuiTablePagination.defaultProps = { | ||
itemsPerPage: 50, | ||
itemsPerPageOptions: [10, 20, 50, 100], | ||
}; |
Oops, something went wrong.