Skip to content

Commit ec41040

Browse files
kmcfaulnicolethoen
andauthored
feat(Table): add draggable table rows demo (#5921)
* most of it is there * update class name * add draggable event handlers * remove extra click handler * remove extra click handler * revert table.md, reapply draggable table example * update example name, update default of className * add draggable button style * move draggable style to Td * add dragover class to ghost row * moved class to table Co-authored-by: nicolethoen <[email protected]>
1 parent 28c1513 commit ec41040

File tree

8 files changed

+499
-177
lines changed

8 files changed

+499
-177
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as React from 'react';
2+
import GripVerticalIcon from '@patternfly/react-icons/dist/js/icons/grip-vertical-icon';
3+
import { Button } from '@patternfly/react-core/dist/js/components/Button/Button';
4+
5+
export interface DraggableCellProps {
6+
id: string;
7+
className?: string;
8+
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
9+
'aria-label'?: string;
10+
}
11+
12+
export const DraggableCell: React.FunctionComponent<DraggableCellProps> = ({
13+
className,
14+
onClick,
15+
'aria-label': ariaLabel,
16+
id,
17+
...props
18+
}: DraggableCellProps) => (
19+
<Button
20+
id={id}
21+
variant="plain"
22+
className={className}
23+
type="button"
24+
aria-label={ariaLabel || `Draggable row draggable button`}
25+
onClick={onClick}
26+
{...props}
27+
>
28+
<GripVerticalIcon aria-hidden />
29+
</Button>
30+
);
31+
32+
DraggableCell.displayName = 'DraggableCell';
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from 'react';
2+
import { css } from '@patternfly/react-styles';
3+
import styles from '@patternfly/react-styles/css/components/Table/table';
4+
import stylesTreeView from '@patternfly/react-styles/css/components/Table/table-tree-view';
5+
import { RowWrapperProps } from './RowWrapper';
6+
import { Tr } from '../TableComposable';
7+
8+
export const DraggableRowWrapper: React.FunctionComponent<RowWrapperProps> = ({
9+
className,
10+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11+
rowProps,
12+
row,
13+
...props
14+
}: RowWrapperProps) => {
15+
const {
16+
'aria-level': level,
17+
'aria-posinset': posinset,
18+
'aria-setsize': setsize,
19+
isExpanded,
20+
isDetailsExpanded,
21+
isHidden
22+
} = row.props;
23+
return (
24+
<Tr
25+
aria-level={level}
26+
aria-posinset={posinset}
27+
aria-setsize={setsize}
28+
aria-expanded={!!isExpanded}
29+
isHidden={isHidden}
30+
className={css(
31+
className,
32+
isExpanded && styles.modifiers.expanded,
33+
isDetailsExpanded && stylesTreeView.modifiers.treeViewDetailsExpanded
34+
)}
35+
{...props}
36+
/>
37+
);
38+
};
39+
DraggableRowWrapper.displayName = 'DraggableRowWrapper';

packages/react-table/src/components/Table/TableTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type OnFavorite = (
6969
rowData: IRowData,
7070
extraData: IExtraData
7171
) => void;
72+
7273
export type OnTreeRowCollapse = (event: any, rowIndex: number, title: React.ReactNode, rowData: IRowData) => void;
7374
export type OnToggleRowDetails = (event: any, rowIndex: number, title: React.ReactNode, rowData: IRowData) => void;
7475
export type OnCheckChange = (
@@ -112,6 +113,7 @@ export interface IColumn {
112113
export interface IExtraRowData {
113114
rowIndex?: number;
114115
rowKey?: RowKeyType;
116+
id?: string;
115117
}
116118

117119
export interface IExtraColumnData {

0 commit comments

Comments
 (0)