mirror of
https://github.com/portainer/portainer.git
synced 2025-07-20 05:49:40 +02:00
refactor(app): move react components to react codebase [EE-3179] (#6971)
This commit is contained in:
parent
212400c283
commit
18252ab854
346 changed files with 642 additions and 644 deletions
90
app/react/components/datatables/TableHeaderCell.tsx
Normal file
90
app/react/components/datatables/TableHeaderCell.tsx
Normal file
|
@ -0,0 +1,90 @@
|
|||
import clsx from 'clsx';
|
||||
import { PropsWithChildren, ReactNode } from 'react';
|
||||
import { TableHeaderProps } from 'react-table';
|
||||
|
||||
import { Button } from '@@/buttons';
|
||||
|
||||
import { useTableContext } from './TableContainer';
|
||||
import styles from './TableHeaderCell.module.css';
|
||||
|
||||
interface Props {
|
||||
canFilter: boolean;
|
||||
canSort: boolean;
|
||||
headerProps: TableHeaderProps;
|
||||
isSorted: boolean;
|
||||
isSortedDesc?: boolean;
|
||||
onSortClick: (desc: boolean) => void;
|
||||
render: () => ReactNode;
|
||||
renderFilter: () => ReactNode;
|
||||
}
|
||||
|
||||
export function TableHeaderCell({
|
||||
headerProps: { className, role, style },
|
||||
canSort,
|
||||
render,
|
||||
onSortClick,
|
||||
isSorted,
|
||||
isSortedDesc,
|
||||
canFilter,
|
||||
renderFilter,
|
||||
}: Props) {
|
||||
useTableContext();
|
||||
|
||||
return (
|
||||
<th role={role} style={style} className={className}>
|
||||
<SortWrapper
|
||||
canSort={canSort}
|
||||
onClick={onSortClick}
|
||||
isSorted={isSorted}
|
||||
isSortedDesc={isSortedDesc}
|
||||
>
|
||||
{render()}
|
||||
</SortWrapper>
|
||||
{canFilter ? renderFilter() : null}
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
interface SortWrapperProps {
|
||||
canSort: boolean;
|
||||
isSorted: boolean;
|
||||
isSortedDesc?: boolean;
|
||||
onClick: (desc: boolean) => void;
|
||||
}
|
||||
|
||||
function SortWrapper({
|
||||
canSort,
|
||||
children,
|
||||
onClick,
|
||||
isSorted,
|
||||
isSortedDesc,
|
||||
}: PropsWithChildren<SortWrapperProps>) {
|
||||
if (!canSort) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
color="link"
|
||||
type="button"
|
||||
onClick={() => onClick(!isSortedDesc)}
|
||||
className="sortable"
|
||||
>
|
||||
<span className="sortable-label">{children}</span>
|
||||
|
||||
{isSorted ? (
|
||||
<i
|
||||
className={clsx(
|
||||
'fa',
|
||||
'space-left',
|
||||
isSortedDesc ? 'fa-sort-alpha-up' : 'fa-sort-alpha-down',
|
||||
styles.sortIcon
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<div className={styles.sortIcon} />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue