Skip to content

Commit 5265599

Browse files
feat: added drag handle icon when reordering
1 parent 25f2c73 commit 5265599

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/DataTable/TableCol.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CellExtended, CellProps } from './Cell';
44
import NativeSortIcon from '../icons/NativeSortIcon';
55
import { equalizeId } from './util';
66
import { TableColumn, SortAction, SortOrder } from './types';
7+
import NativeReorderIcon from '../icons/NativeReorderIcon';
78

89
interface ColumnStyleProps extends CellProps {
910
isDragging?: boolean;
@@ -175,6 +176,8 @@ function TableCol<T>({
175176
<span className={[sortDirection, '__rdt_custom_sort_icon__'].join(' ')}>{sortIcon}</span>
176177
);
177178

179+
const renderNativeReorderIcon = () => <NativeReorderIcon />;
180+
178181
const sortActive = !!(column.sortable && equalizeId(selectedColumn.id, column.id));
179182
const disableSort = !column.sortable || disabled;
180183
const nativeSortIconLeft = column.sortable && !sortIcon && !column.right;
@@ -217,6 +220,7 @@ function TableCol<T>({
217220
sortActive={!disableSort && sortActive}
218221
disabled={disableSort}
219222
>
223+
{column.reorder && renderNativeReorderIcon()}
220224
{!disableSort && customSortIconRight && renderCustomSortIcon()}
221225
{!disableSort && nativeSortIconRight && renderNativeSortIcon(sortActive)}
222226

src/icons/NativeReorderIcon.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
const Icon = styled.span`
5+
padding: 0px;
6+
color: inherit;
7+
flex-grow: 0;
8+
flex-shrink: 0;
9+
opacity: 0;
10+
&:hover {
11+
opacity: 1;
12+
}
13+
`;
14+
15+
// SVG taken from https://fontawesome.com/icons/grip-vertical?f=classic&s=solid
16+
const NativeReorderIcon: React.FC = ({}) => (
17+
<Icon>
18+
<svg width="10px" height="10px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
19+
<path d="M40 352l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zm192 0l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zM40 320c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0zM232 192l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zM40 160c-22.1 0-40-17.9-40-40L0 72C0 49.9 17.9 32 40 32l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0zM232 32l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40z" />
20+
</svg>
21+
</Icon>
22+
);
23+
24+
export default NativeReorderIcon;

0 commit comments

Comments
 (0)