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`
|
2019-08-09 07:57:12 +00:00
|
|
|
|
2019-07-18 13:40:50 +00:00
|
|
|
`;
|
|
|
|
|
2019-08-01 09:59:59 +00:00
|
|
|
const previousAction = () => {
|
|
|
|
console.log('Prev action');
|
|
|
|
};
|
|
|
|
|
|
|
|
const nextAction = () => {
|
|
|
|
console.log('Next action');
|
|
|
|
};
|
|
|
|
|
2019-07-18 13:40:50 +00:00
|
|
|
const Paging = props => {
|
2019-07-29 14:25:04 +00:00
|
|
|
//console.log("Paging render");
|
2019-08-05 12:53:32 +00:00
|
|
|
const { previousLabel, nextLabel, previousAction, nextAction, pageItems, countItems, openDirection, disablePrevious, disableNext, selectedPage, selectedCount } = props;
|
2019-07-29 14:25:04 +00:00
|
|
|
|
2019-07-30 13:49:33 +00:00
|
|
|
const onSelectPageAction = (option) => {
|
|
|
|
props.onSelectPage(option);
|
|
|
|
}
|
|
|
|
|
2019-08-05 12:53:32 +00:00
|
|
|
const onSelectCountAction = (option) => {
|
|
|
|
props.onSelectCount(option)
|
2019-07-30 13:49:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 14:25:04 +00:00
|
|
|
return (
|
|
|
|
<StyledPaging>
|
|
|
|
<Button size='medium' label={previousLabel} onClick={previousAction} isDisabled={disablePrevious} />
|
|
|
|
{pageItems &&
|
|
|
|
<StyledPage>
|
2019-08-09 07:57:12 +00:00
|
|
|
<ComboBox directionY={openDirection} options={pageItems} onSelect={onSelectPageAction} selectedOption={selectedPage} dropDownMaxHeight="200px" />
|
2019-07-29 14:25:04 +00:00
|
|
|
</StyledPage>
|
|
|
|
}
|
|
|
|
<Button size='medium' label={nextLabel} onClick={nextAction} isDisabled={disableNext} />
|
2019-08-06 07:40:19 +00:00
|
|
|
{countItems &&
|
|
|
|
<StyledOnPage>
|
|
|
|
<ComboBox directionY={openDirection} options={countItems} onSelect={onSelectCountAction} selectedOption={selectedCount} />
|
|
|
|
</StyledOnPage>
|
2019-07-29 14:25:04 +00:00
|
|
|
}
|
|
|
|
</StyledPaging>
|
|
|
|
);
|
2019-07-18 13:40:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Paging.propTypes = {
|
2019-07-29 14:25:04 +00:00
|
|
|
previousLabel: PropTypes.string,
|
2019-08-05 12:53:32 +00:00
|
|
|
previousAction: PropTypes.func,
|
2019-07-29 14:25:04 +00:00
|
|
|
disablePrevious: PropTypes.bool,
|
2019-08-05 12:53:32 +00:00
|
|
|
nextLabel: PropTypes.string,
|
|
|
|
nextAction: PropTypes.func,
|
2019-07-29 14:25:04 +00:00
|
|
|
disableNext: PropTypes.bool,
|
2019-08-06 07:40:19 +00:00
|
|
|
selectedPage: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number
|
|
|
|
]),
|
|
|
|
selectedCount: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number
|
|
|
|
]),
|
2019-07-30 11:37:25 +00:00
|
|
|
onSelectPage: PropTypes.func,
|
2019-08-05 12:53:32 +00:00
|
|
|
onSelectCount: PropTypes.func
|
2019-07-18 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Paging.defaultProps = {
|
2019-08-01 09:59:59 +00:00
|
|
|
previousAction: previousAction,
|
|
|
|
nextAction: nextAction,
|
2019-07-29 14:25:04 +00:00
|
|
|
disablePrevious: false,
|
|
|
|
disableNext: false
|
2019-07-18 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Paging;
|