Skip to content

Commit 19ddee7

Browse files
kmcfaulnicolethoen
andauthored
feat(DragDrop): new drag drop styling fixes (#9784)
* feat(DragDrop): introduce new package and deprecate old implementation * refactor a bunch * style fixes * fix lint errors * fix lint * update snap * update duallistselector example, try exporting interface from separate file * bump versions in dragdrop for mismatch * fix versions * pr feedback * fix versions after merge * version update after rebase * update md * move into next folder for docgen * update version after rebase * update ver after rebase * update ver after rebase * update ver after rebase * remove unused prop, update wording * move some examples to demos * update ver after rebase * update new demos text * update wording p1 * update wording p2 * update wording p3 * update wording p4 * fix links * remove beta flags since page is beta * update ver after rebase --------- Co-authored-by: nicolethoen <[email protected]>
1 parent c90c7f2 commit 19ddee7

37 files changed

+1008
-12
lines changed

packages/react-core/src/components/DataList/examples/DataList.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ import global_BorderWidth_sm from '@patternfly/react-tokens/dist/esm/global_Bord
8686

8787
### Draggable
8888

89-
Draggable data lists used to have their own HTML5-based API for drag and drop, which wasn't able to fulfill requirements such as custom styling on items being dragged. So we wrote generic `DragDrop`, `Draggable`, and `Droppable` components for this purpose. Use those new components instead of the deprecated (and buggy!) HTML5-based API.
89+
Note: There is a new recommended drag and drop implementation with full keyboard functionality, which replaces this implementation. To adhere to our new recommendations, refer to the [drag and drop demos](/components/drag-and-drop/react-next-demos).
9090

91-
Note: Keyboard accessibility and screen reader accessibility for the `DragDrop` component are still in development.
91+
Previously, draggable data lists had their own API for the [drag and drop component](/components/drag-and-drop), which wasn't flexible enough to allow custom styling for items as they are dragged. To address this disparity, `<DragDrop>`, `<Draggable>`, and `<Droppable>` components were added to replace our now deprecated HTML5-based API. Keyboard and screen reader accessibility for the `<DragDrop>` component is still in development.
9292

9393
```ts isBeta file="./DataListDraggable.tsx"
9494

packages/react-core/src/components/DragDrop/examples/DragDrop.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
id: Drag and drop
33
section: components
44
propComponents: [DragDrop, Draggable, Droppable, DraggableItemPosition]
5-
beta: true
5+
title: Drag and drop
66
---
77

8-
You can use the `DragDrop` component to move items in or between lists. The `DragDrop` component should contain `Droppable` components which contain `Draggable` components.
8+
You can use the `<DragDrop>` component to move items in or between lists. The `<DragDrop>` component should contain `<Droppable>` components which contain `<Draggable>` components.
99

1010
```ts noLive
1111
import React from 'react';
@@ -35,9 +35,11 @@ Note: Keyboard accessibility and screen reader accessibility are still in develo
3535
### Basic
3636

3737
```ts file="./DragDropBasic.tsx"
38+
3839
```
3940

4041
### Multiple lists
4142

4243
```ts file="./DragDropMultipleLists.tsx"
44+
4345
```

packages/react-core/src/components/DragDrop/examples/DragDropBasic.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const getItems = (count: number) =>
2020
}));
2121

2222
const reorder = (list: ItemType[], startIndex: number, endIndex: number) => {
23-
const result = list;
23+
const result = [...list];
2424
const [removed] = result.splice(startIndex, 1);
2525
result.splice(endIndex, 0, removed);
2626
return result;
2727
};
2828

2929
export const DragDropBasic: React.FunctionComponent = () => {
30-
const [items, setItems] = React.useState(getItems(10));
30+
const [items, setItems] = React.useState<ItemType[]>(getItems(10));
3131

3232
function onDrop(source: SourceType, dest: DestinationType) {
3333
if (dest) {
@@ -42,8 +42,8 @@ export const DragDropBasic: React.FunctionComponent = () => {
4242
return (
4343
<DragDrop onDrop={onDrop}>
4444
<Droppable>
45-
{items.map(({ content }, i) => (
46-
<Draggable key={i} style={{ padding: '8px' }}>
45+
{items.map(({ id, content }) => (
46+
<Draggable key={id} style={{ padding: '8px' }}>
4747
{content}
4848
</Draggable>
4949
))}

packages/react-core/src/components/DragDrop/examples/DragDropMultipleLists.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ interface SourceType {
1111
index: number;
1212
}
1313

14+
interface MultipleListState {
15+
items1: ItemType[];
16+
items2: ItemType[];
17+
}
18+
1419
interface DestinationType extends SourceType {}
1520

1621
const getItems = (count: number, startIndex: number) =>
@@ -35,7 +40,7 @@ const move = (source: ItemType[], destination: ItemType[], sourceIndex: number,
3540
};
3641

3742
export const DragDropMultipleLists: React.FunctionComponent = () => {
38-
const [items, setItems] = React.useState({
43+
const [items, setItems] = React.useState<MultipleListState>({
3944
items1: getItems(10, 0),
4045
items2: getItems(5, 10)
4146
});
@@ -84,7 +89,7 @@ export const DragDropMultipleLists: React.FunctionComponent = () => {
8489
{Object.entries(items).map(([key, subitems]) => (
8590
<SplitItem key={key} style={{ flex: 1 }}>
8691
<Droppable zone="multizone" droppableId={key}>
87-
{subitems.map(({ id, content }) => (
92+
{(subitems as ItemType[]).map(({ id, content }) => (
8893
<Draggable key={id} style={{ padding: '8px' }}>
8994
{content}
9095
</Draggable>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './DragDrop';
22
export * from './Draggable';
33
export * from './Droppable';
4+
export * from './DroppableContext';

packages/react-core/src/components/DualListSelector/examples/DualListSelector.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ The dual list selector can also be built in a composable manner to make customiz
8787

8888
### Composable with drag and drop
8989

90+
Note: There is a new recommended drag and drop implementation with full keyboard functionality, which replaces this implementation. To adhere to our new recommendations, refer to the [drag and drop demos](/components/drag-and-drop/react-next-demos).
91+
9092
This example only allows reordering the contents of the "chosen" pane with drag and drop. To make a pane able to be reordered:
9193

9294
- wrap the `DualListSelectorPane` in a `DragDrop` component
@@ -99,7 +101,7 @@ This example only allows reordering the contents of the "chosen" pane with drag
99101
- define an `onDrag` callback which ensures that the drag event will not cross hairs with the `onOptionSelect` click
100102
event set on the option. Note: the `ignoreNextOptionSelect` state value is used to prevent selection while dragging.
101103

102-
Note: Keyboard accessibility and screen reader accessibility for the `DragDrop` component are still in development.
104+
Keyboard and screen reader accessibility for the `<DragDrop>` component is still in development.
103105

104106
```ts file="DualListSelectorComposableDragDrop.tsx"
105107

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export * from './DualListSelector';
2+
export * from './DualListSelectorContext';
23
export * from './DualListSelectorControl';
34
export * from './DualListSelectorControlsWrapper';
45
export * from './DualListSelectorPane';
56
export * from './DualListSelectorList';
67
export * from './DualListSelectorListItem';
78
export * from './DualListSelectorTree';
9+
export * from './DualListSelectorContext';

packages/react-core/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export * from './DataList';
2222
export * from './DatePicker';
2323
export * from './DescriptionList';
2424
export * from './Divider';
25+
export * from './DragDrop';
2526
export * from './Drawer';
2627
export * from './Dropdown';
2728
export * from './DualListSelector';
@@ -76,7 +77,6 @@ export * from './Tooltip';
7677
export * from './NumberInput';
7778
export * from './TreeView';
7879
export * from './Wizard';
79-
export * from './DragDrop';
8080
export * from './TextInputGroup';
8181
export * from './Panel';
8282
export * from './Truncate';

packages/react-docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@patternfly/react-icons": "^5.2.0-prerelease.9",
3030
"@patternfly/react-styles": "^5.2.0-prerelease.6",
3131
"@patternfly/react-table": "^5.2.0-prerelease.41",
32+
"@patternfly/react-drag-drop": "^5.2.0-prelease.0",
3233
"@patternfly/react-tokens": "^5.2.0-prerelease.7"
3334
},
3435
"devDependencies": {

packages/react-docs/patternfly-docs/patternfly-docs.source.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ module.exports = (baseSourceMD, sourceProps) => {
1616
const reactCodeEditorPath = require
1717
.resolve('@patternfly/react-code-editor/package.json')
1818
.replace('package.json', 'src');
19+
const reactDragDropPath = require.resolve('@patternfly/react-drag-drop/package.json').replace('package.json', 'src');
1920
const reactPropsIgnore = '**/*.test.tsx';
2021

2122
sourceProps(path.join(reactCorePath, '/**/*.tsx'), reactPropsIgnore);
2223
sourceProps(path.join(reactTablePath, '/**/*.tsx'), reactPropsIgnore);
2324
sourceProps(path.join(reactChartsPath, '/**/*.tsx'), reactPropsIgnore);
2425
sourceProps(path.join(reactCodeEditorPath, '/**/*.tsx'), reactPropsIgnore);
26+
sourceProps(path.join(reactDragDropPath, '/**/*.tsx'), reactPropsIgnore);
2527

2628
// React MD
2729
sourceMD(path.join(reactCorePath, '/components/**/examples/*.md'), 'react');
@@ -41,6 +43,9 @@ module.exports = (baseSourceMD, sourceProps) => {
4143
// Code Editor MD
4244
sourceMD(path.join(reactCodeEditorPath, '/**/examples/*.md'), 'react');
4345

46+
// Drag drop MD
47+
sourceMD(path.join(reactDragDropPath, '/**/examples/*.md'), 'react-next');
48+
4449
// OUIA MD
4550
sourceMD(path.join(reactCorePath, 'helpers/OUIA/OUIA.md'), 'react');
4651
};

packages/react-drag-drop/package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "@patternfly/react-drag-drop",
3+
"version": "5.2.0-prelease.0",
4+
"description": "PatternFly drag and drop solution",
5+
"main": "dist/js/index.js",
6+
"module": "dist/esm/index.js",
7+
"types": "dist/esm/index.d.ts",
8+
"sideEffects": false,
9+
"publishConfig": {
10+
"access": "public"
11+
},
12+
"patternfly:src": "src/",
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/patternfly/patternfly-react.git"
16+
},
17+
"keywords": [
18+
"react",
19+
"patternfly",
20+
"drag-drop"
21+
],
22+
"author": "Red Hat",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/patternfly/patternfly-react/issues"
26+
},
27+
"homepage": "https://github.com/patternfly/patternfly-react/tree/main/packages/react-drag-drop#readme",
28+
"scripts": {
29+
"clean": "rimraf dist"
30+
},
31+
"dependencies": {
32+
"@dnd-kit/core": "^6.0.8",
33+
"@dnd-kit/modifiers": "^6.0.1",
34+
"@dnd-kit/sortable": "^7.0.2",
35+
"@patternfly/react-core": "^5.2.0-prerelease.41",
36+
"@patternfly/react-icons": "^5.2.0-prerelease.9",
37+
"@patternfly/react-styles": "^5.2.0-prerelease.6",
38+
"memoize-one": "^5.1.0",
39+
"resize-observer-polyfill": "^1.5.1"
40+
},
41+
"peerDependencies": {
42+
"react": "^17 || ^18",
43+
"react-dom": "^17 || ^18"
44+
},
45+
"devDependencies": {
46+
"rimraf": "^2.6.2",
47+
"typescript": "^4.7.4"
48+
}
49+
}

packages/react-drag-drop/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './next';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import { css } from '@patternfly/react-styles';
3+
import dragButtonStyles from '@patternfly/react-styles/css/components/DataList/data-list';
4+
import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
5+
import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon';
6+
7+
export interface DragButtonProps extends React.HTMLProps<HTMLButtonElement> {
8+
/** Additional classes added to the drag button */
9+
className?: string;
10+
/** Sets button type */
11+
type?: 'button' | 'submit' | 'reset';
12+
/** Flag indicating if drag is disabled for the item */
13+
isDisabled?: boolean;
14+
}
15+
16+
export const DragButton: React.FunctionComponent<DragButtonProps> = ({ className, ...props }: DragButtonProps) => (
17+
<button
18+
className={css(className, buttonStyles.button, buttonStyles.modifiers.plain)}
19+
aria-label="Drag button"
20+
{...props}
21+
>
22+
<span className={css(dragButtonStyles.dataListItemDraggableIcon)}>
23+
<GripVerticalIcon />
24+
</span>
25+
</button>
26+
);
27+
DragButton.displayName = 'DragButton';

0 commit comments

Comments
 (0)