mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-19 17:52:45 +02:00
* experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
172 lines
7.1 KiB
TypeScript
172 lines
7.1 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
import classnames from 'classnames';
|
|
import { useStyles } from './PaginationUI.styles';
|
|
|
|
import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos';
|
|
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
|
|
|
|
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
|
|
import { useMediaQuery, useTheme } from '@mui/material';
|
|
|
|
interface IPaginateUIProps {
|
|
pages: any[];
|
|
pageIndex: number;
|
|
prevPage: () => void;
|
|
setPageIndex: (idx: number) => void;
|
|
nextPage: () => void;
|
|
style?: React.CSSProperties;
|
|
}
|
|
|
|
/**
|
|
* @deprecated
|
|
*/
|
|
const PaginateUI = ({
|
|
pages,
|
|
pageIndex,
|
|
prevPage,
|
|
setPageIndex,
|
|
nextPage,
|
|
...rest
|
|
}: IPaginateUIProps) => {
|
|
const STARTLIMIT = 6;
|
|
const theme = useTheme();
|
|
const { classes: styles } = useStyles();
|
|
const [limit, setLimit] = useState(STARTLIMIT);
|
|
const [start, setStart] = useState(0);
|
|
const matches = useMediaQuery(theme.breakpoints.down('md'));
|
|
|
|
useEffect(() => {
|
|
if (matches) {
|
|
setLimit(4);
|
|
}
|
|
}, [matches]);
|
|
|
|
useEffect(() => {
|
|
if (pageIndex === 0 && start !== 0) {
|
|
setStart(0);
|
|
setLimit(STARTLIMIT);
|
|
}
|
|
}, [pageIndex, start]);
|
|
|
|
return (
|
|
<ConditionallyRender
|
|
condition={pages.length > 1}
|
|
show={
|
|
<div className={styles.pagination} {...rest}>
|
|
<div className={styles.paginationInnerContainer}>
|
|
<ConditionallyRender
|
|
condition={pageIndex > 0}
|
|
show={
|
|
<>
|
|
<button
|
|
className={classnames(
|
|
styles.idxBtn,
|
|
styles.idxBtnLeft
|
|
)}
|
|
onClick={() => {
|
|
prevPage();
|
|
if (start > 0) {
|
|
setLimit(prev => prev - 1);
|
|
setStart(prev => prev - 1);
|
|
}
|
|
}}
|
|
>
|
|
<ArrowBackIosIcon
|
|
className={styles.idxBtnIcon}
|
|
/>
|
|
</button>
|
|
<button
|
|
className={classnames(
|
|
styles.idxBtn,
|
|
styles.doubleArrowBtnLeft
|
|
)}
|
|
onClick={() => {
|
|
setPageIndex(0);
|
|
if (start > 0) {
|
|
setLimit(STARTLIMIT);
|
|
setStart(0);
|
|
}
|
|
}}
|
|
>
|
|
<DoubleArrowIcon
|
|
className={classnames(
|
|
styles.arrowIcon,
|
|
styles.arrowIconLeft
|
|
)}
|
|
/>
|
|
</button>
|
|
</>
|
|
}
|
|
/>
|
|
|
|
{pages
|
|
.map((page, idx) => {
|
|
const active = pageIndex === idx;
|
|
return (
|
|
<button
|
|
key={idx}
|
|
className={classnames(
|
|
styles.paginationButton,
|
|
{
|
|
[styles.paginationButtonActive]:
|
|
active,
|
|
}
|
|
)}
|
|
onClick={() => {
|
|
setPageIndex(idx);
|
|
}}
|
|
>
|
|
{idx + 1}
|
|
</button>
|
|
);
|
|
})
|
|
.slice(start, limit)}
|
|
<ConditionallyRender
|
|
condition={pageIndex < pages.length - 1}
|
|
show={
|
|
<>
|
|
<button
|
|
onClick={() => {
|
|
nextPage();
|
|
if (limit < pages.length) {
|
|
setLimit(prev => prev + 1);
|
|
setStart(prev => prev + 1);
|
|
}
|
|
}}
|
|
className={classnames(
|
|
styles.idxBtn,
|
|
styles.idxBtnRight
|
|
)}
|
|
>
|
|
<ArrowForwardIosIcon
|
|
className={styles.idxBtnIcon}
|
|
/>
|
|
</button>
|
|
<button
|
|
className={classnames(
|
|
styles.idxBtn,
|
|
styles.doubleArrowBtnRight
|
|
)}
|
|
onClick={() => {
|
|
setPageIndex(pages.length - 1);
|
|
setLimit(pages.length);
|
|
setStart(pages.length - STARTLIMIT);
|
|
}}
|
|
>
|
|
<DoubleArrowIcon
|
|
className={styles.arrowIcon}
|
|
/>
|
|
</button>
|
|
</>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default PaginateUI;
|