2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import PropTypes from "prop-types";
|
2019-07-18 13:40:50 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
import Button from "../button";
|
|
|
|
import ComboBox from "../combobox";
|
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;
|
2019-09-13 08:06:48 +00:00
|
|
|
max-width: 110px;
|
2019-08-12 08:20:52 +00:00
|
|
|
}
|
2019-12-24 11:14:47 +00:00
|
|
|
|
|
|
|
.buttonCustomStyle {
|
|
|
|
padding: 6px 8px 10px;
|
|
|
|
}
|
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-12-24 11:14:47 +00:00
|
|
|
.hideDisabled {
|
|
|
|
div[disabled] {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 08:06:48 +00:00
|
|
|
@media (max-width: 450px) {
|
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-12-24 11:14:47 +00:00
|
|
|
|
|
|
|
.manualWidth {
|
|
|
|
> div:last-of-type {
|
|
|
|
width: 120%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 13:40:50 +00:00
|
|
|
`;
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
const Paging = (props) => {
|
2019-07-29 14:25:04 +00:00
|
|
|
//console.log("Paging render");
|
2020-10-16 13:16:01 +00:00
|
|
|
const {
|
|
|
|
previousLabel,
|
|
|
|
nextLabel,
|
|
|
|
previousAction,
|
|
|
|
nextAction,
|
|
|
|
pageItems,
|
|
|
|
countItems,
|
|
|
|
openDirection,
|
|
|
|
disablePrevious,
|
|
|
|
disableNext,
|
|
|
|
selectedPageItem,
|
|
|
|
selectedCountItem,
|
|
|
|
id,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
} = props;
|
2019-07-29 14:25:04 +00:00
|
|
|
|
2019-07-30 13:49:33 +00:00
|
|
|
const onSelectPageAction = (option) => {
|
|
|
|
props.onSelectPage(option);
|
2020-10-16 13:16:01 +00:00
|
|
|
};
|
2019-07-30 13:49:33 +00:00
|
|
|
|
2019-08-05 12:53:32 +00:00
|
|
|
const onSelectCountAction = (option) => {
|
2020-10-16 13:16:01 +00:00
|
|
|
props.onSelectCount(option);
|
|
|
|
};
|
2019-07-30 13:49:33 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
const setDropDownMaxHeight =
|
|
|
|
pageItems && pageItems.length > 6 ? { dropDownMaxHeight: 200 } : {};
|
2019-08-13 11:14:32 +00:00
|
|
|
|
2019-07-29 14:25:04 +00:00
|
|
|
return (
|
2020-10-16 13:16:01 +00:00
|
|
|
<StyledPaging id={id} className={className} style={style}>
|
2019-12-03 12:25:17 +00:00
|
|
|
<Button
|
2019-12-24 11:14:47 +00:00
|
|
|
className="buttonCustomStyle"
|
2020-10-16 13:16:01 +00:00
|
|
|
size="medium"
|
2019-12-03 12:25:17 +00:00
|
|
|
scale={true}
|
|
|
|
label={previousLabel}
|
|
|
|
onClick={previousAction}
|
2020-10-16 13:16:01 +00:00
|
|
|
isDisabled={disablePrevious}
|
|
|
|
/>
|
|
|
|
{pageItems && (
|
2019-07-29 14:25:04 +00:00
|
|
|
<StyledPage>
|
2019-12-03 12:25:17 +00:00
|
|
|
<ComboBox
|
2019-12-24 11:14:47 +00:00
|
|
|
className="manualWidth"
|
2019-12-03 12:25:17 +00:00
|
|
|
directionY={openDirection}
|
|
|
|
options={pageItems}
|
2019-09-26 09:08:39 +00:00
|
|
|
onSelect={onSelectPageAction}
|
|
|
|
scaledOptions={pageItems.length > 6}
|
2019-08-14 14:24:01 +00:00
|
|
|
selectedOption={selectedPageItem}
|
2020-10-16 13:16:01 +00:00
|
|
|
{...setDropDownMaxHeight}
|
|
|
|
/>
|
2019-07-29 14:25:04 +00:00
|
|
|
</StyledPage>
|
2020-10-16 13:16:01 +00:00
|
|
|
)}
|
2019-12-03 12:25:17 +00:00
|
|
|
<Button
|
2019-12-24 11:14:47 +00:00
|
|
|
className="buttonCustomStyle"
|
2020-10-16 13:16:01 +00:00
|
|
|
size="medium"
|
2019-12-03 12:25:17 +00:00
|
|
|
scale={true}
|
|
|
|
label={nextLabel}
|
|
|
|
onClick={nextAction}
|
2020-10-16 13:16:01 +00:00
|
|
|
isDisabled={disableNext}
|
|
|
|
/>
|
|
|
|
{countItems && (
|
2019-08-06 07:40:19 +00:00
|
|
|
<StyledOnPage>
|
2019-12-03 12:25:17 +00:00
|
|
|
<ComboBox
|
2019-12-24 11:14:47 +00:00
|
|
|
className="hideDisabled"
|
2019-09-18 13:25:22 +00:00
|
|
|
directionY={openDirection}
|
2020-10-16 13:16:01 +00:00
|
|
|
directionX="right"
|
2019-12-03 12:25:17 +00:00
|
|
|
options={countItems}
|
|
|
|
onSelect={onSelectCountAction}
|
2020-10-16 13:16:01 +00:00
|
|
|
selectedOption={selectedCountItem}
|
|
|
|
/>
|
2019-08-06 07:40:19 +00:00
|
|
|
</StyledOnPage>
|
2020-10-16 13:16:01 +00:00
|
|
|
)}
|
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-09-09 14:32:47 +00:00
|
|
|
onSelectCount: PropTypes.func,
|
|
|
|
|
|
|
|
pageItems: PropTypes.array,
|
|
|
|
countItems: PropTypes.array,
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
openDirection: PropTypes.oneOf(["bottom", "top"]),
|
2019-12-03 12:25:17 +00:00
|
|
|
|
|
|
|
className: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
|
|
};
|
2019-07-18 13:40:50 +00:00
|
|
|
|
|
|
|
Paging.defaultProps = {
|
2019-07-29 14:25:04 +00:00
|
|
|
disablePrevious: false,
|
2020-10-16 13:16:01 +00:00
|
|
|
disableNext: false,
|
|
|
|
};
|
2019-07-18 13:40:50 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
export default Paging;
|