2019-07-18 13:40:50 +00:00
|
|
|
import React from 'react'
|
|
|
|
import styled, { css } from 'styled-components'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import Button from '../button'
|
|
|
|
import ComboBox from '../combobox'
|
|
|
|
import device from '../device'
|
|
|
|
|
|
|
|
|
|
|
|
const StyledPaging = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
& > button, div:not(:last-of-type) {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledOnPage = styled.div`
|
|
|
|
width: 120px;
|
|
|
|
margin-left: auto;
|
|
|
|
|
|
|
|
@media ${device.mobile} {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledPage = styled.div`
|
|
|
|
width: 80px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Paging = props => {
|
2019-07-29 14:25:04 +00:00
|
|
|
//console.log("Paging render");
|
|
|
|
const { previousLabel, nextLabel, previousAction, nextAction, pageItems, perPageItems, openDirection, disablePrevious, disableNext } = props;
|
|
|
|
|
2019-07-30 13:49:33 +00:00
|
|
|
const onSelectPageAction = (option) => {
|
|
|
|
props.onSelectPage(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
const onSelectPerPageAction = (option) => {
|
|
|
|
props.onSelectPerPage(option)
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:25:04 +00:00
|
|
|
return (
|
|
|
|
<StyledPaging>
|
|
|
|
<Button size='medium' label={previousLabel} onClick={previousAction} isDisabled={disablePrevious} />
|
|
|
|
{pageItems &&
|
|
|
|
<StyledPage>
|
2019-07-30 13:49:33 +00:00
|
|
|
<ComboBox directionY={openDirection} options={pageItems} onSelect={onSelectPageAction} />
|
2019-07-29 14:25:04 +00:00
|
|
|
</StyledPage>
|
|
|
|
}
|
|
|
|
<Button size='medium' label={nextLabel} onClick={nextAction} isDisabled={disableNext} />
|
|
|
|
{perPageItems &&
|
|
|
|
<StyledOnPage>
|
2019-07-30 13:49:33 +00:00
|
|
|
<ComboBox directionY={openDirection} options={perPageItems} onSelect={onSelectPerPageAction} />
|
2019-07-29 14:25:04 +00:00
|
|
|
</StyledOnPage>
|
|
|
|
}
|
|
|
|
</StyledPaging>
|
|
|
|
);
|
2019-07-18 13:40:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Paging.propTypes = {
|
2019-07-29 14:25:04 +00:00
|
|
|
previousAction: PropTypes.func,
|
|
|
|
nextAction: PropTypes.func,
|
|
|
|
previousLabel: PropTypes.string,
|
|
|
|
nextLabel: PropTypes.string,
|
|
|
|
disablePrevious: PropTypes.bool,
|
|
|
|
disableNext: PropTypes.bool,
|
2019-07-30 11:37:25 +00:00
|
|
|
onSelectPage: PropTypes.func,
|
|
|
|
onSelectPerPage: PropTypes.func
|
2019-07-18 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Paging.defaultProps = {
|
2019-07-29 14:25:04 +00:00
|
|
|
previousAction: () => console.log('Prev action'),
|
|
|
|
nextAction: () => console.log('Next action'),
|
|
|
|
disablePrevious: false,
|
|
|
|
disableNext: false
|
2019-07-18 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Paging;
|