2019-07-18 13:40:50 +00:00
|
|
|
import React from 'react'
|
2019-08-14 12:54:16 +00:00
|
|
|
import styled from 'styled-components'
|
2019-07-18 13:40:50 +00:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import Button from '../button'
|
|
|
|
import ComboBox from '../combobox'
|
2019-09-04 10:29:32 +00:00
|
|
|
import { mobile } from '../../utils/device'
|
2019-07-18 13:40:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
const StyledPaging = styled.div`
|
2019-08-12 08:20:52 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
2019-07-18 13:40:50 +00:00
|
|
|
|
2019-08-12 08:20:52 +00:00
|
|
|
& > button {
|
|
|
|
margin-right: 8px;
|
|
|
|
width: 110px;
|
|
|
|
}
|
2019-07-18 13:40:50 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledOnPage = styled.div`
|
2019-08-12 08:20:52 +00:00
|
|
|
margin-left: auto;
|
|
|
|
margin-right: 0px;
|
2019-07-18 13:40:50 +00:00
|
|
|
|
2019-09-04 10:29:32 +00:00
|
|
|
@media ${mobile} {
|
2019-08-12 08:20:52 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2019-07-18 13:40:50 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledPage = styled.div`
|
2019-08-12 08:20:52 +00:00
|
|
|
margin-right: 8px;
|
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-12 11:12:41 +00:00
|
|
|
const { previousLabel, nextLabel, previousAction, nextAction, pageItems, countItems,
|
2019-08-14 14:24:01 +00:00
|
|
|
openDirection, disablePrevious, disableNext, selectedPageItem, selectedCountItem} = 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-08-13 11:14:32 +00:00
|
|
|
const setDropDownMaxHeight = pageItems && pageItems.length > 6 ? { dropDownMaxHeight: 200 } : {};
|
|
|
|
|
2019-07-29 14:25:04 +00:00
|
|
|
return (
|
|
|
|
<StyledPaging>
|
2019-08-12 11:12:41 +00:00
|
|
|
<Button
|
|
|
|
size='medium'
|
|
|
|
scale={true}
|
|
|
|
label={previousLabel}
|
|
|
|
onClick={previousAction}
|
|
|
|
isDisabled={disablePrevious} />
|
2019-07-29 14:25:04 +00:00
|
|
|
{pageItems &&
|
|
|
|
<StyledPage>
|
2019-08-12 11:12:41 +00:00
|
|
|
<ComboBox
|
|
|
|
directionY={openDirection}
|
|
|
|
options={pageItems}
|
|
|
|
onSelect={onSelectPageAction}
|
2019-08-14 14:24:01 +00:00
|
|
|
selectedOption={selectedPageItem}
|
2019-08-14 12:54:16 +00:00
|
|
|
{...setDropDownMaxHeight} />
|
2019-07-29 14:25:04 +00:00
|
|
|
</StyledPage>
|
|
|
|
}
|
2019-08-12 11:12:41 +00:00
|
|
|
<Button
|
|
|
|
size='medium'
|
|
|
|
scale={true}
|
|
|
|
label={nextLabel}
|
|
|
|
onClick={nextAction}
|
|
|
|
isDisabled={disableNext} />
|
2019-08-06 07:40:19 +00:00
|
|
|
{countItems &&
|
|
|
|
<StyledOnPage>
|
2019-08-12 11:12:41 +00:00
|
|
|
<ComboBox
|
|
|
|
directionY={openDirection}
|
|
|
|
options={countItems}
|
|
|
|
onSelect={onSelectCountAction}
|
2019-08-14 14:24:01 +00:00
|
|
|
selectedOption={selectedCountItem}/>
|
2019-08-06 07:40:19 +00:00
|
|
|
</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
|
|
|
nextLabel: PropTypes.string,
|
2019-08-14 12:54:16 +00:00
|
|
|
|
|
|
|
previousAction: PropTypes.func,
|
2019-08-05 12:53:32 +00:00
|
|
|
nextAction: PropTypes.func,
|
2019-08-14 12:54:16 +00:00
|
|
|
|
|
|
|
disablePrevious: PropTypes.bool,
|
2019-07-29 14:25:04 +00:00
|
|
|
disableNext: PropTypes.bool,
|
2019-08-14 12:54:16 +00:00
|
|
|
|
2019-08-14 14:24:01 +00:00
|
|
|
selectedPageItem: PropTypes.object,
|
|
|
|
selectedCountItem: PropTypes.object,
|
2019-08-14 12:54:16 +00:00
|
|
|
|
2019-07-30 11:37:25 +00:00
|
|
|
onSelectPage: PropTypes.func,
|
2019-08-14 12:54:16 +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,
|
2019-08-14 12:54:16 +00:00
|
|
|
disableNext: false
|
2019-07-18 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Paging;
|