@patternfly/react-core 4.157.2 → 4.157.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/esm/components/DataList/DataList.d.ts +7 -5
- package/dist/esm/components/DataList/DataList.d.ts.map +1 -1
- package/dist/esm/components/DataList/DataList.js +11 -10
- package/dist/esm/components/DataList/DataList.js.map +1 -1
- package/dist/esm/components/DragDrop/DragDrop.d.ts +3 -0
- package/dist/esm/components/DragDrop/DragDrop.d.ts.map +1 -1
- package/dist/esm/components/DragDrop/DragDrop.js +2 -1
- package/dist/esm/components/DragDrop/DragDrop.js.map +1 -1
- package/dist/esm/components/DragDrop/Draggable.d.ts +2 -0
- package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -1
- package/dist/esm/components/DragDrop/Draggable.js +27 -18
- package/dist/esm/components/DragDrop/Draggable.js.map +1 -1
- package/dist/esm/components/DragDrop/Droppable.d.ts +2 -0
- package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/esm/components/DragDrop/Droppable.js +3 -3
- package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
- package/dist/esm/components/Nav/Nav.d.ts +1 -5
- package/dist/esm/components/Nav/Nav.d.ts.map +1 -1
- package/dist/esm/components/Nav/Nav.js +3 -7
- package/dist/esm/components/Nav/Nav.js.map +1 -1
- package/dist/esm/components/Nav/NavItem.d.ts +0 -4
- package/dist/esm/components/Nav/NavItem.d.ts.map +1 -1
- package/dist/esm/components/Nav/NavItem.js +6 -98
- package/dist/esm/components/Nav/NavItem.js.map +1 -1
- package/dist/esm/components/Nav/NavList.d.ts +0 -2
- package/dist/esm/components/Nav/NavList.d.ts.map +1 -1
- package/dist/esm/components/Sidebar/Sidebar.d.ts +4 -0
- package/dist/esm/components/Sidebar/Sidebar.d.ts.map +1 -1
- package/dist/esm/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/esm/components/Sidebar/SidebarContent.d.ts +1 -0
- package/dist/esm/components/Sidebar/SidebarContent.d.ts.map +1 -1
- package/dist/esm/components/Sidebar/SidebarContent.js.map +1 -1
- package/dist/esm/components/Sidebar/SidebarPanel.d.ts +3 -0
- package/dist/esm/components/Sidebar/SidebarPanel.d.ts.map +1 -1
- package/dist/esm/components/Sidebar/SidebarPanel.js.map +1 -1
- package/dist/js/components/DataList/DataList.d.ts +7 -5
- package/dist/js/components/DataList/DataList.d.ts.map +1 -1
- package/dist/js/components/DataList/DataList.js +11 -10
- package/dist/js/components/DataList/DataList.js.map +1 -1
- package/dist/js/components/DragDrop/DragDrop.d.ts +3 -0
- package/dist/js/components/DragDrop/DragDrop.d.ts.map +1 -1
- package/dist/js/components/DragDrop/DragDrop.js +2 -1
- package/dist/js/components/DragDrop/DragDrop.js.map +1 -1
- package/dist/js/components/DragDrop/Draggable.d.ts +2 -0
- package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -1
- package/dist/js/components/DragDrop/Draggable.js +27 -18
- package/dist/js/components/DragDrop/Draggable.js.map +1 -1
- package/dist/js/components/DragDrop/Droppable.d.ts +2 -0
- package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/js/components/DragDrop/Droppable.js +3 -3
- package/dist/js/components/DragDrop/Droppable.js.map +1 -1
- package/dist/js/components/Nav/Nav.d.ts +1 -5
- package/dist/js/components/Nav/Nav.d.ts.map +1 -1
- package/dist/js/components/Nav/Nav.js +3 -7
- package/dist/js/components/Nav/Nav.js.map +1 -1
- package/dist/js/components/Nav/NavItem.d.ts +0 -4
- package/dist/js/components/Nav/NavItem.d.ts.map +1 -1
- package/dist/js/components/Nav/NavItem.js +6 -98
- package/dist/js/components/Nav/NavItem.js.map +1 -1
- package/dist/js/components/Nav/NavList.d.ts +0 -2
- package/dist/js/components/Nav/NavList.d.ts.map +1 -1
- package/dist/js/components/Sidebar/Sidebar.d.ts +4 -0
- package/dist/js/components/Sidebar/Sidebar.d.ts.map +1 -1
- package/dist/js/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/js/components/Sidebar/SidebarContent.d.ts +1 -0
- package/dist/js/components/Sidebar/SidebarContent.d.ts.map +1 -1
- package/dist/js/components/Sidebar/SidebarContent.js.map +1 -1
- package/dist/js/components/Sidebar/SidebarPanel.d.ts +3 -0
- package/dist/js/components/Sidebar/SidebarPanel.d.ts.map +1 -1
- package/dist/js/components/Sidebar/SidebarPanel.js.map +1 -1
- package/dist/umd/react-core.css +9715 -9715
- package/dist/umd/react-core.js +52 -135
- package/dist/umd/react-core.min.css +15301 -15301
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +2 -2
- package/src/components/DataList/DataList.tsx +19 -15
- package/src/components/DataList/examples/DataList.md +78 -111
- package/src/components/DragDrop/DragDrop.tsx +7 -1
- package/src/components/DragDrop/Draggable.tsx +49 -41
- package/src/components/DragDrop/Droppable.tsx +21 -7
- package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +1 -0
- package/src/components/Nav/Nav.tsx +7 -17
- package/src/components/Nav/NavItem.tsx +3 -127
- package/src/components/Nav/__tests__/Generated/__snapshots__/Nav.test.tsx.snap +0 -2
- package/src/components/Nav/__tests__/Generated/__snapshots__/NavItem.test.tsx.snap +0 -1
- package/src/components/Nav/__tests__/__snapshots__/Nav.test.tsx.snap +0 -49
- package/src/components/Nav/examples/Nav.md +0 -63
- package/src/components/Nav/examples/nav.css +1 -6
- package/src/components/Page/__tests__/__snapshots__/Page.test.tsx.snap +0 -15
- package/src/components/Sidebar/Sidebar.tsx +4 -0
- package/src/components/Sidebar/SidebarContent.tsx +1 -0
- package/src/components/Sidebar/SidebarPanel.tsx +3 -0
- package/src/components/Sidebar/examples/Sidebar.md +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.157.
|
|
3
|
+
"version": "4.157.6",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "d013adc9687d5873a6733b63ff6bc2d93a2b5915"
|
|
64
64
|
}
|
|
@@ -29,13 +29,13 @@ export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, '
|
|
|
29
29
|
'aria-label': string;
|
|
30
30
|
/** Optional callback to make DataList selectable, fired when DataListItem selected */
|
|
31
31
|
onSelectDataListItem?: (id: string) => void;
|
|
32
|
-
/** Optional callback to make DataList draggable, fired when dragging ends */
|
|
32
|
+
/** @deprecated Optional callback to make DataList draggable, fired when dragging ends */
|
|
33
33
|
onDragFinish?: (newItemOrder: string[]) => void;
|
|
34
|
-
/** Optional informational callback for dragging, fired when dragging starts */
|
|
34
|
+
/** @deprecated Optional informational callback for dragging, fired when dragging starts */
|
|
35
35
|
onDragStart?: (id: string) => void;
|
|
36
|
-
/** Optional informational callback for dragging, fired when an item moves */
|
|
36
|
+
/** @deprecated Optional informational callback for dragging, fired when an item moves */
|
|
37
37
|
onDragMove?: (oldIndex: number, newIndex: number) => void;
|
|
38
|
-
/** Optional informational callback for dragging, fired when dragging is cancelled */
|
|
38
|
+
/** @deprecated Optional informational callback for dragging, fired when dragging is cancelled */
|
|
39
39
|
onDragCancel?: () => void;
|
|
40
40
|
/** Id of DataList item currently selected */
|
|
41
41
|
selectedDataListItemId?: string;
|
|
@@ -45,7 +45,7 @@ export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, '
|
|
|
45
45
|
gridBreakpoint?: 'none' | 'always' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
46
46
|
/** Determines which wrapping modifier to apply to the DataList */
|
|
47
47
|
wrapModifier?: DataListWrapModifier | 'nowrap' | 'truncate' | 'breakWord';
|
|
48
|
-
/** Order of items in a draggable DataList */
|
|
48
|
+
/** @deprecated Order of items in a draggable DataList */
|
|
49
49
|
itemOrder?: string[];
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -93,6 +93,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
|
|
|
93
93
|
wrapModifier: null
|
|
94
94
|
};
|
|
95
95
|
dragFinished: boolean = false;
|
|
96
|
+
html5DragDrop: boolean = false;
|
|
96
97
|
arrayCopy: React.ReactElement[] = React.Children.toArray(this.props.children) as React.ReactElement[];
|
|
97
98
|
ref = React.createRef<HTMLUListElement>();
|
|
98
99
|
|
|
@@ -103,6 +104,16 @@ export class DataList extends React.Component<DataListProps, DataListState> {
|
|
|
103
104
|
dragging: false
|
|
104
105
|
};
|
|
105
106
|
|
|
107
|
+
constructor(props: DataListProps) {
|
|
108
|
+
super(props);
|
|
109
|
+
|
|
110
|
+
this.html5DragDrop = Boolean(props.onDragFinish || props.onDragStart || props.onDragMove || props.onDragCancel);
|
|
111
|
+
if (this.html5DragDrop) {
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.warn("DataList's onDrag API is deprecated. Use DragDrop instead.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
106
117
|
componentDidUpdate(oldProps: DataListProps) {
|
|
107
118
|
if (this.dragFinished) {
|
|
108
119
|
this.dragFinished = false;
|
|
@@ -242,13 +253,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
|
|
|
242
253
|
|
|
243
254
|
handleDragButtonKeys = (evt: React.KeyboardEvent) => {
|
|
244
255
|
const { dragging } = this.state;
|
|
245
|
-
if (
|
|
246
|
-
evt.key !== ' ' &&
|
|
247
|
-
evt.key !== 'Escape' &&
|
|
248
|
-
evt.key !== 'Enter' &&
|
|
249
|
-
evt.key !== 'ArrowUp' &&
|
|
250
|
-
evt.key !== 'ArrowDown'
|
|
251
|
-
) {
|
|
256
|
+
if (![' ', 'Escape', 'Enter', 'ArrowUp', 'ArrowDown'].includes(evt.key) || !this.html5DragDrop) {
|
|
252
257
|
if (dragging) {
|
|
253
258
|
evt.preventDefault();
|
|
254
259
|
}
|
|
@@ -308,13 +313,12 @@ export class DataList extends React.Component<DataListProps, DataListState> {
|
|
|
308
313
|
} = this.props;
|
|
309
314
|
const { dragging } = this.state;
|
|
310
315
|
const isSelectable = onSelectDataListItem !== undefined;
|
|
311
|
-
const isDraggable = onDragFinish !== undefined;
|
|
312
316
|
|
|
313
317
|
const updateSelectedDataListItem = (id: string) => {
|
|
314
318
|
onSelectDataListItem(id);
|
|
315
319
|
};
|
|
316
320
|
|
|
317
|
-
const dragProps =
|
|
321
|
+
const dragProps = this.html5DragDrop && {
|
|
318
322
|
onDragOver: this.dragOver,
|
|
319
323
|
onDrop: this.dragOver,
|
|
320
324
|
onDragLeave: this.dragLeave
|
|
@@ -326,7 +330,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
|
|
|
326
330
|
isSelectable,
|
|
327
331
|
selectedDataListItemId,
|
|
328
332
|
updateSelectedDataListItem,
|
|
329
|
-
isDraggable,
|
|
333
|
+
isDraggable: this.html5DragDrop,
|
|
330
334
|
dragStart: this.dragStart,
|
|
331
335
|
dragEnd: this.dragEnd,
|
|
332
336
|
drop: this.drop,
|
|
@@ -1125,6 +1125,8 @@ import {
|
|
|
1125
1125
|
|
|
1126
1126
|
### Draggable
|
|
1127
1127
|
|
|
1128
|
+
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.
|
|
1129
|
+
|
|
1128
1130
|
```js
|
|
1129
1131
|
import React from 'react';
|
|
1130
1132
|
import {
|
|
@@ -1135,129 +1137,94 @@ import {
|
|
|
1135
1137
|
DataListCheck,
|
|
1136
1138
|
DataListControl,
|
|
1137
1139
|
DataListDragButton,
|
|
1138
|
-
DataListItemCells
|
|
1140
|
+
DataListItemCells,
|
|
1141
|
+
DragDrop,
|
|
1142
|
+
Draggable,
|
|
1143
|
+
Droppable
|
|
1139
1144
|
} from '@patternfly/react-core';
|
|
1140
1145
|
|
|
1146
|
+
const getItems = count =>
|
|
1147
|
+
Array.from({ length: count }, (v, k) => k).map(k => ({
|
|
1148
|
+
id: `item-${k}`,
|
|
1149
|
+
content: `item ${k} `.repeat(k === 4 ? 20 : 1)
|
|
1150
|
+
}));
|
|
1151
|
+
|
|
1152
|
+
const reorder = (list, startIndex, endIndex) => {
|
|
1153
|
+
const result = Array.from(list);
|
|
1154
|
+
const [removed] = result.splice(startIndex, 1);
|
|
1155
|
+
result.splice(endIndex, 0, removed);
|
|
1156
|
+
return result;
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1141
1159
|
DraggableDataList = () => {
|
|
1142
|
-
const [
|
|
1143
|
-
const [
|
|
1144
|
-
const [ itemOrder, setItemOrder ] = React.useState(['data1', 'data2', 'data3', 'data4']);
|
|
1160
|
+
const [items, setItems] = React.useState(getItems(10));
|
|
1161
|
+
const [liveText, setLiveText] = React.useState('');
|
|
1145
1162
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1163
|
+
function onDrag(source) {
|
|
1164
|
+
setLiveText(`Started dragging ${items[source.index].content}`);
|
|
1165
|
+
// Return true to allow drag
|
|
1166
|
+
return true;
|
|
1167
|
+
}
|
|
1150
1168
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1169
|
+
function onDragMove(source, dest) {
|
|
1170
|
+
const newText = dest
|
|
1171
|
+
? `Move ${items[source.index].content} to ${items[dest.index].content}`
|
|
1172
|
+
: 'Invalid drop zone';
|
|
1173
|
+
if (newText !== liveText) {
|
|
1174
|
+
setLiveText(newText);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1154
1177
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1178
|
+
function onDrop(source, dest) {
|
|
1179
|
+
if (dest) {
|
|
1180
|
+
const newItems = reorder(
|
|
1181
|
+
items,
|
|
1182
|
+
source.index,
|
|
1183
|
+
dest.index
|
|
1184
|
+
);
|
|
1185
|
+
setItems(newItems);
|
|
1158
1186
|
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1187
|
+
setLiveText('Dragging finished.');
|
|
1188
|
+
return true; // Signal that this is a valid drop and not to animate the item returning home.
|
|
1189
|
+
} else {
|
|
1190
|
+
setLiveText('Dragging cancelled. List unchanged.');
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1163
1193
|
|
|
1164
1194
|
return (
|
|
1165
|
-
|
|
1166
|
-
<
|
|
1167
|
-
aria-label="draggable data list example"
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
</DataListItemRow>
|
|
1195
|
-
</DataListItem>
|
|
1196
|
-
<DataListItem aria-labelledby="simple-item2" id="data2" key="2">
|
|
1197
|
-
<DataListItemRow>
|
|
1198
|
-
<DataListControl>
|
|
1199
|
-
<DataListDragButton
|
|
1200
|
-
aria-label="Reorder"
|
|
1201
|
-
aria-labelledby="simple-item2"
|
|
1202
|
-
aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
|
|
1203
|
-
aria-pressed="false"
|
|
1204
|
-
/>
|
|
1205
|
-
<DataListCheck aria-labelledby="simple-item2" name="check2" otherControls />
|
|
1206
|
-
</DataListControl>
|
|
1207
|
-
<DataListItemCells
|
|
1208
|
-
dataListCells={[
|
|
1209
|
-
<DataListCell key="item2">
|
|
1210
|
-
<span id="simple-item2">Item 2</span>
|
|
1211
|
-
</DataListCell>
|
|
1212
|
-
]}
|
|
1213
|
-
/>
|
|
1214
|
-
</DataListItemRow>
|
|
1215
|
-
</DataListItem>
|
|
1216
|
-
<DataListItem aria-labelledby="simple-item3" id="data3" key="3">
|
|
1217
|
-
<DataListItemRow>
|
|
1218
|
-
<DataListControl>
|
|
1219
|
-
<DataListDragButton
|
|
1220
|
-
aria-label="Reorder"
|
|
1221
|
-
aria-labelledby="simple-item3"
|
|
1222
|
-
aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
|
|
1223
|
-
aria-pressed="false"
|
|
1224
|
-
/>
|
|
1225
|
-
<DataListCheck aria-labelledby="simple-item3" name="check3" otherControls />
|
|
1226
|
-
</DataListControl>
|
|
1227
|
-
<DataListItemCells
|
|
1228
|
-
dataListCells={[
|
|
1229
|
-
<DataListCell key="item3">
|
|
1230
|
-
<span id="simple-item3">Item 3</span>
|
|
1231
|
-
</DataListCell>
|
|
1232
|
-
]}
|
|
1233
|
-
/>
|
|
1234
|
-
</DataListItemRow>
|
|
1235
|
-
</DataListItem>
|
|
1236
|
-
<DataListItem aria-labelledby="simple-item4" id="data4" key="4">
|
|
1237
|
-
<DataListItemRow>
|
|
1238
|
-
<DataListControl>
|
|
1239
|
-
<DataListDragButton
|
|
1240
|
-
aria-label="Reorder"
|
|
1241
|
-
aria-labelledby="simple-item4"
|
|
1242
|
-
aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
|
|
1243
|
-
aria-pressed="false"
|
|
1244
|
-
/>
|
|
1245
|
-
<DataListCheck aria-labelledby="simple-item4" name="check4" otherControls />
|
|
1246
|
-
</DataListControl>
|
|
1247
|
-
<DataListItemCells
|
|
1248
|
-
dataListCells={[
|
|
1249
|
-
<DataListCell key="item4">
|
|
1250
|
-
<span id="simple-item4">Item 4</span>
|
|
1251
|
-
</DataListCell>
|
|
1252
|
-
]}
|
|
1253
|
-
/>
|
|
1254
|
-
</DataListItemRow>
|
|
1255
|
-
</DataListItem>
|
|
1256
|
-
</DataList>
|
|
1195
|
+
<DragDrop onDrag={onDrag} onDragMove={onDragMove} onDrop={onDrop}>
|
|
1196
|
+
<Droppable hasNoWrapper>
|
|
1197
|
+
<DataList aria-label="draggable data list example" isCompact>
|
|
1198
|
+
{items.map(({id, content}) =>
|
|
1199
|
+
<Draggable key={id} hasNoWrapper>
|
|
1200
|
+
<DataListItem aria-labelledby={id} ref={React.createRef()}>
|
|
1201
|
+
<DataListItemRow>
|
|
1202
|
+
<DataListControl>
|
|
1203
|
+
<DataListDragButton
|
|
1204
|
+
aria-label="Reorder"
|
|
1205
|
+
aria-labelledby={id}
|
|
1206
|
+
aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
|
|
1207
|
+
aria-pressed="false"
|
|
1208
|
+
/>
|
|
1209
|
+
<DataListCheck aria-labelledby={id} name={id} otherControls />
|
|
1210
|
+
</DataListControl>
|
|
1211
|
+
<DataListItemCells
|
|
1212
|
+
dataListCells={[
|
|
1213
|
+
<DataListCell key={id}>
|
|
1214
|
+
<span id={id}>{content}</span>
|
|
1215
|
+
</DataListCell>
|
|
1216
|
+
]}
|
|
1217
|
+
/>
|
|
1218
|
+
</DataListItemRow>
|
|
1219
|
+
</DataListItem>
|
|
1220
|
+
</Draggable>
|
|
1221
|
+
)}
|
|
1222
|
+
</DataList>
|
|
1223
|
+
</Droppable>
|
|
1257
1224
|
<div className="pf-screen-reader" aria-live="assertive">
|
|
1258
1225
|
{liveText}
|
|
1259
1226
|
</div>
|
|
1260
|
-
|
|
1227
|
+
</DragDrop>
|
|
1261
1228
|
);
|
|
1262
1229
|
};
|
|
1263
1230
|
```
|
|
@@ -9,6 +9,7 @@ interface DraggableItemPosition {
|
|
|
9
9
|
|
|
10
10
|
export const DragDropContext = React.createContext({
|
|
11
11
|
onDrag: (_source: DraggableItemPosition) => true as boolean,
|
|
12
|
+
onDragMove: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => {},
|
|
12
13
|
onDrop: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => false as boolean
|
|
13
14
|
});
|
|
14
15
|
|
|
@@ -17,6 +18,8 @@ interface DragDropProps {
|
|
|
17
18
|
children?: React.ReactNode;
|
|
18
19
|
/** Callback for drag event. Return true to allow drag, false to disallow. */
|
|
19
20
|
onDrag?: (source: DraggableItemPosition) => boolean;
|
|
21
|
+
/** Callback on mouse move while dragging. */
|
|
22
|
+
onDragMove?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => void;
|
|
20
23
|
/** Callback for drop event. Return true to allow drop, false to disallow. */
|
|
21
24
|
onDrop?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => boolean;
|
|
22
25
|
}
|
|
@@ -24,6 +27,9 @@ interface DragDropProps {
|
|
|
24
27
|
export const DragDrop: React.FunctionComponent<DragDropProps> = ({
|
|
25
28
|
children,
|
|
26
29
|
onDrag = () => true,
|
|
30
|
+
onDragMove = () => {},
|
|
27
31
|
onDrop = () => false
|
|
28
|
-
}: DragDropProps) =>
|
|
32
|
+
}: DragDropProps) => (
|
|
33
|
+
<DragDropContext.Provider value={{ onDrag, onDragMove, onDrop }}>{children}</DragDropContext.Provider>
|
|
34
|
+
);
|
|
29
35
|
DragDrop.displayName = 'DragDrop';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
2
|
import { DroppableContext } from './DroppableContext';
|
|
4
3
|
import { DragDropContext } from './DragDrop';
|
|
5
4
|
|
|
6
5
|
export interface DraggableProps extends React.HTMLProps<HTMLDivElement> {
|
|
7
6
|
/** Content rendered inside DragDrop */
|
|
8
7
|
children?: React.ReactNode;
|
|
8
|
+
/** Don't wrap the component in a div. Requires passing a single child. */
|
|
9
|
+
hasNoWrapper?: boolean;
|
|
9
10
|
/** Class to add to outer div */
|
|
10
11
|
className?: string;
|
|
11
12
|
}
|
|
@@ -32,7 +33,7 @@ function getInheritedBackgroundColor(el: HTMLElement): string {
|
|
|
32
33
|
return getInheritedBackgroundColor(el.parentElement);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
function removeBlankDiv(node:
|
|
36
|
+
function removeBlankDiv(node: HTMLElement) {
|
|
36
37
|
if (node.getAttribute('blankDiv') === 'true') {
|
|
37
38
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
38
39
|
for (let i = 0; i < node.children.length; i++) {
|
|
@@ -47,10 +48,10 @@ function removeBlankDiv(node: HTMLDivElement) {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
interface DroppableItem {
|
|
50
|
-
node:
|
|
51
|
+
node: HTMLElement;
|
|
51
52
|
rect: DOMRect;
|
|
52
53
|
isDraggingHost: boolean;
|
|
53
|
-
draggableNodes:
|
|
54
|
+
draggableNodes: HTMLElement[];
|
|
54
55
|
draggableNodesRects: DOMRect[];
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -74,7 +75,8 @@ function overlaps(ev: MouseEvent, rect: DOMRect) {
|
|
|
74
75
|
export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
75
76
|
className,
|
|
76
77
|
children,
|
|
77
|
-
style: styleProp,
|
|
78
|
+
style: styleProp = {},
|
|
79
|
+
hasNoWrapper = false,
|
|
78
80
|
...props
|
|
79
81
|
}: DraggableProps) => {
|
|
80
82
|
/* eslint-disable prefer-const */
|
|
@@ -82,14 +84,13 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
82
84
|
/* eslint-enable prefer-const */
|
|
83
85
|
const [isDragging, setIsDragging] = React.useState(false);
|
|
84
86
|
const { zone, droppableId } = React.useContext(DroppableContext);
|
|
85
|
-
const { onDrag, onDrop } = React.useContext(DragDropContext);
|
|
86
|
-
const ref = React.createRef<HTMLDivElement>();
|
|
87
|
+
const { onDrag, onDragMove, onDrop } = React.useContext(DragDropContext);
|
|
87
88
|
// Some state is better just to leave as vars passed around between various callbacks
|
|
88
89
|
// You can only drag around one item at a time anyways...
|
|
89
90
|
let startX = 0;
|
|
90
91
|
let startY = 0;
|
|
91
92
|
let index: number = null; // Index of this draggable
|
|
92
|
-
let hoveringDroppable:
|
|
93
|
+
let hoveringDroppable: HTMLElement;
|
|
93
94
|
let hoveringIndex: number = null;
|
|
94
95
|
let mouseMoveListener: EventListener;
|
|
95
96
|
let mouseUpListener: EventListener;
|
|
@@ -97,18 +98,14 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
97
98
|
let startYOffset = 0;
|
|
98
99
|
|
|
99
100
|
// After item returning to where it started animation completes
|
|
100
|
-
const onTransitionEnd = (_ev: React.TransitionEvent<
|
|
101
|
+
const onTransitionEnd = (_ev: React.TransitionEvent<HTMLElement>) => {
|
|
101
102
|
if (isDragging) {
|
|
102
103
|
setIsDragging(false);
|
|
103
104
|
setStyle(styleProp);
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
droppableItems.forEach(resetDroppableItem);
|
|
109
|
-
document.removeEventListener('mousemove', mouseMoveListener);
|
|
110
|
-
document.removeEventListener('mouseup', mouseUpListener);
|
|
111
|
-
document.removeEventListener('contextmenu', mouseUpListener);
|
|
108
|
+
function getSourceAndDest() {
|
|
112
109
|
const hoveringDroppableId = hoveringDroppable ? hoveringDroppable.getAttribute('data-pf-droppableid') : null;
|
|
113
110
|
const source = {
|
|
114
111
|
droppableId,
|
|
@@ -121,6 +118,15 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
121
118
|
index: hoveringIndex
|
|
122
119
|
}
|
|
123
120
|
: undefined;
|
|
121
|
+
return { source, dest, hoveringDroppableId };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const onMouseUpWhileDragging = (droppableItems: DroppableItem[]) => {
|
|
125
|
+
droppableItems.forEach(resetDroppableItem);
|
|
126
|
+
document.removeEventListener('mousemove', mouseMoveListener);
|
|
127
|
+
document.removeEventListener('mouseup', mouseUpListener);
|
|
128
|
+
document.removeEventListener('contextmenu', mouseUpListener);
|
|
129
|
+
const { source, dest, hoveringDroppableId } = getSourceAndDest();
|
|
124
130
|
const consumerReordered = onDrop(source, dest);
|
|
125
131
|
if (consumerReordered && droppableId === hoveringDroppableId) {
|
|
126
132
|
setIsDragging(false);
|
|
@@ -215,9 +221,12 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
215
221
|
lastTranslate = translateY;
|
|
216
222
|
});
|
|
217
223
|
}
|
|
224
|
+
|
|
225
|
+
const { source, dest } = getSourceAndDest();
|
|
226
|
+
onDragMove(source, dest);
|
|
218
227
|
};
|
|
219
228
|
|
|
220
|
-
const onDragStart = (ev: React.DragEvent<
|
|
229
|
+
const onDragStart = (ev: React.DragEvent<HTMLElement>) => {
|
|
221
230
|
// Default HTML drag and drop doesn't allow us to change what the thing
|
|
222
231
|
// being dragged looks like. Because of this we'll use prevent the default
|
|
223
232
|
// and use `mouseMove` and `mouseUp` instead
|
|
@@ -228,19 +237,21 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
228
237
|
}
|
|
229
238
|
|
|
230
239
|
// Cache droppable and draggable nodes and their bounding rects
|
|
231
|
-
const
|
|
232
|
-
const
|
|
240
|
+
const dragging = ev.target as HTMLElement;
|
|
241
|
+
const rect = dragging.getBoundingClientRect();
|
|
242
|
+
const droppableNodes = Array.from(document.querySelectorAll(`[data-pf-droppable="${zone}"]`)) as HTMLElement[];
|
|
233
243
|
const droppableItems = droppableNodes.reduce((acc, cur) => {
|
|
234
|
-
const draggableNodes = Array.from(cur.querySelectorAll(`[data-pf-draggable-zone="${zone}"]`)) as
|
|
235
|
-
const isDraggingHost = cur.contains(
|
|
244
|
+
const draggableNodes = Array.from(cur.querySelectorAll(`[data-pf-draggable-zone="${zone}"]`)) as HTMLElement[];
|
|
245
|
+
const isDraggingHost = cur.contains(dragging);
|
|
236
246
|
if (isDraggingHost) {
|
|
237
|
-
index = draggableNodes.indexOf(
|
|
247
|
+
index = draggableNodes.indexOf(dragging);
|
|
238
248
|
}
|
|
239
249
|
const droppableItem = {
|
|
240
250
|
node: cur,
|
|
241
251
|
rect: cur.getBoundingClientRect(),
|
|
242
252
|
isDraggingHost,
|
|
243
|
-
|
|
253
|
+
// We don't want styles to apply to the left behind div in onMouseMoveWhileDragging
|
|
254
|
+
draggableNodes: draggableNodes.map(node => (node === dragging ? node.cloneNode(false) : node)),
|
|
244
255
|
draggableNodesRects: draggableNodes.map(node => node.getBoundingClientRect())
|
|
245
256
|
};
|
|
246
257
|
acc.push(droppableItem);
|
|
@@ -260,7 +271,7 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
260
271
|
left: rect.x,
|
|
261
272
|
width: rect.width,
|
|
262
273
|
height: rect.height,
|
|
263
|
-
background: getInheritedBackgroundColor(
|
|
274
|
+
background: getInheritedBackgroundColor(dragging),
|
|
264
275
|
boxShadow: '0px 0px 0px 1px blue, 0px 2px 5px rgba(0, 0, 0, 0.2)',
|
|
265
276
|
zIndex: 5000
|
|
266
277
|
};
|
|
@@ -275,35 +286,32 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
275
286
|
document.addEventListener('mousemove', mouseMoveListener);
|
|
276
287
|
document.addEventListener('mouseup', mouseUpListener);
|
|
277
288
|
// Comment out this line to debug while dragging by right clicking
|
|
278
|
-
document.addEventListener('contextmenu', mouseUpListener);
|
|
289
|
+
// document.addEventListener('contextmenu', mouseUpListener);
|
|
279
290
|
};
|
|
280
291
|
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
ref={ref}
|
|
291
|
-
{...props}
|
|
292
|
-
>
|
|
293
|
-
{children}
|
|
294
|
-
</div>
|
|
295
|
-
);
|
|
292
|
+
const childProps = {
|
|
293
|
+
'data-pf-draggable-zone': isDragging ? null : zone,
|
|
294
|
+
draggable: true,
|
|
295
|
+
className,
|
|
296
|
+
onDragStart,
|
|
297
|
+
onTransitionEnd,
|
|
298
|
+
style,
|
|
299
|
+
...props
|
|
300
|
+
};
|
|
296
301
|
|
|
297
302
|
return (
|
|
298
303
|
<React.Fragment>
|
|
299
304
|
{/* Leave behind blank spot per-design */}
|
|
300
305
|
{isDragging && (
|
|
301
|
-
<div draggable
|
|
306
|
+
<div draggable {...props} style={{ ...styleProp, visibility: 'hidden' }}>
|
|
302
307
|
{children}
|
|
303
308
|
</div>
|
|
304
309
|
)}
|
|
305
|
-
{
|
|
306
|
-
|
|
310
|
+
{hasNoWrapper ? (
|
|
311
|
+
React.cloneElement(children as React.ReactElement, childProps)
|
|
312
|
+
) : (
|
|
313
|
+
<div {...childProps}>{children}</div>
|
|
314
|
+
)}
|
|
307
315
|
</React.Fragment>
|
|
308
316
|
);
|
|
309
317
|
};
|
|
@@ -10,6 +10,8 @@ interface DroppableProps extends React.HTMLProps<HTMLDivElement> {
|
|
|
10
10
|
zone?: string;
|
|
11
11
|
/** Id to be passed back on drop events */
|
|
12
12
|
droppableId?: string;
|
|
13
|
+
/** Don't wrap the component in a div. Requires passing a single child. */
|
|
14
|
+
hasNoWrapper?: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export const Droppable: React.FunctionComponent<DroppableProps> = ({
|
|
@@ -17,12 +19,24 @@ export const Droppable: React.FunctionComponent<DroppableProps> = ({
|
|
|
17
19
|
children,
|
|
18
20
|
zone = 'defaultZone',
|
|
19
21
|
droppableId = 'defaultId',
|
|
22
|
+
hasNoWrapper = false,
|
|
20
23
|
...props
|
|
21
|
-
}: DroppableProps) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
}: DroppableProps) => {
|
|
25
|
+
const childProps = {
|
|
26
|
+
'data-pf-droppable': zone,
|
|
27
|
+
'data-pf-droppableid': droppableId,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<DroppableContext.Provider value={{ zone, droppableId }}>
|
|
34
|
+
{hasNoWrapper ? (
|
|
35
|
+
React.cloneElement(children as React.ReactElement, childProps)
|
|
36
|
+
) : (
|
|
37
|
+
<div {...childProps}>{children}</div>
|
|
38
|
+
)}
|
|
39
|
+
</DroppableContext.Provider>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
28
42
|
Droppable.displayName = 'Droppable';
|
|
@@ -35,7 +35,7 @@ export interface NavProps
|
|
|
35
35
|
/** Indicates which theme color to use */
|
|
36
36
|
theme?: 'dark' | 'light';
|
|
37
37
|
/** For horizontal navs */
|
|
38
|
-
variant?: 'default' | 'horizontal' | 'tertiary' | 'horizontal-subnav'
|
|
38
|
+
variant?: 'default' | 'horizontal' | 'tertiary' | 'horizontal-subnav';
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export const NavContext = React.createContext<{
|
|
@@ -55,14 +55,9 @@ export const NavContext = React.createContext<{
|
|
|
55
55
|
onToggle?: (event: React.MouseEvent<HTMLButtonElement>, groupId: number | string, expanded: boolean) => void;
|
|
56
56
|
updateIsScrollable?: (isScrollable: boolean) => void;
|
|
57
57
|
isHorizontal?: boolean;
|
|
58
|
-
flyoutRef?: React.Ref<HTMLLIElement>;
|
|
59
|
-
setFlyoutRef?: (ref: React.Ref<HTMLLIElement>) => void;
|
|
60
58
|
}>({});
|
|
61
59
|
|
|
62
|
-
export class Nav extends React.Component<
|
|
63
|
-
NavProps,
|
|
64
|
-
{ isScrollable: boolean; ouiaStateId: string; flyoutRef: React.Ref<HTMLLIElement> | null }
|
|
65
|
-
> {
|
|
60
|
+
export class Nav extends React.Component<NavProps, { isScrollable: boolean; ouiaStateId: string }> {
|
|
66
61
|
static displayName = 'Nav';
|
|
67
62
|
static defaultProps: NavProps = {
|
|
68
63
|
onSelect: () => undefined,
|
|
@@ -73,8 +68,7 @@ export class Nav extends React.Component<
|
|
|
73
68
|
|
|
74
69
|
state = {
|
|
75
70
|
isScrollable: false,
|
|
76
|
-
ouiaStateId: getDefaultOUIAId(Nav.displayName, this.props.variant)
|
|
77
|
-
flyoutRef: null as React.Ref<HTMLLIElement>
|
|
71
|
+
ouiaStateId: getDefaultOUIAId(Nav.displayName, this.props.variant)
|
|
78
72
|
};
|
|
79
73
|
|
|
80
74
|
// Callback from NavItem
|
|
@@ -122,7 +116,6 @@ export class Nav extends React.Component<
|
|
|
122
116
|
...props
|
|
123
117
|
} = this.props;
|
|
124
118
|
const isHorizontal = ['horizontal', 'tertiary'].includes(variant);
|
|
125
|
-
const Component = variant === 'subnav' ? 'section' : 'nav';
|
|
126
119
|
|
|
127
120
|
return (
|
|
128
121
|
<NavContext.Provider
|
|
@@ -143,15 +136,12 @@ export class Nav extends React.Component<
|
|
|
143
136
|
onToggle: (event: React.MouseEvent<HTMLButtonElement>, groupId: number | string, expanded: boolean) =>
|
|
144
137
|
this.onToggle(event, groupId, expanded),
|
|
145
138
|
updateIsScrollable: (isScrollable: boolean) => this.setState({ isScrollable }),
|
|
146
|
-
isHorizontal: ['horizontal', 'tertiary', 'horizontal-subnav'].includes(variant)
|
|
147
|
-
flyoutRef: this.state.flyoutRef,
|
|
148
|
-
setFlyoutRef: flyoutRef => this.setState({ flyoutRef })
|
|
139
|
+
isHorizontal: ['horizontal', 'tertiary', 'horizontal-subnav'].includes(variant)
|
|
149
140
|
}}
|
|
150
141
|
>
|
|
151
|
-
<
|
|
142
|
+
<nav
|
|
152
143
|
className={css(
|
|
153
|
-
|
|
154
|
-
variant === 'subnav' && styles.navSubnav,
|
|
144
|
+
styles.nav,
|
|
155
145
|
theme === 'light' && styles.modifiers.light,
|
|
156
146
|
isHorizontal && styles.modifiers.horizontal,
|
|
157
147
|
variant === 'tertiary' && styles.modifiers.tertiary,
|
|
@@ -164,7 +154,7 @@ export class Nav extends React.Component<
|
|
|
164
154
|
{...props}
|
|
165
155
|
>
|
|
166
156
|
{children}
|
|
167
|
-
</
|
|
157
|
+
</nav>
|
|
168
158
|
</NavContext.Provider>
|
|
169
159
|
);
|
|
170
160
|
}
|