@patternfly/react-drag-drop 6.2.0-prerelease.8 → 6.2.0

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/dist/cjs.tsbuildinfo +1 -1
  3. package/dist/esm/components/DragDrop/DragButton.d.ts +1 -1
  4. package/dist/esm/components/DragDrop/DragButton.d.ts.map +1 -1
  5. package/dist/esm/components/DragDrop/DragButton.js +2 -3
  6. package/dist/esm/components/DragDrop/DragButton.js.map +1 -1
  7. package/dist/esm/components/DragDrop/DragDropContainer.d.ts +1 -1
  8. package/dist/esm/components/DragDrop/DragDropContainer.d.ts.map +1 -1
  9. package/dist/esm/components/DragDrop/DragDropContainer.js +17 -21
  10. package/dist/esm/components/DragDrop/DragDropContainer.js.map +1 -1
  11. package/dist/esm/components/DragDrop/DragDropSort.d.ts +2 -2
  12. package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +1 -1
  13. package/dist/esm/components/DragDrop/DragDropSort.js +4 -4
  14. package/dist/esm/components/DragDrop/DragDropSort.js.map +1 -1
  15. package/dist/esm/components/DragDrop/Draggable.d.ts +1 -1
  16. package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -1
  17. package/dist/esm/components/DragDrop/Draggable.js +2 -4
  18. package/dist/esm/components/DragDrop/Draggable.js.map +1 -1
  19. package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts +1 -1
  20. package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts.map +1 -1
  21. package/dist/esm/components/DragDrop/DraggableDataListItem.js +2 -6
  22. package/dist/esm/components/DragDrop/DraggableDataListItem.js.map +1 -1
  23. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts +2 -2
  24. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -1
  25. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js +12 -16
  26. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  27. package/dist/esm/components/DragDrop/Droppable.d.ts +3 -3
  28. package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
  29. package/dist/esm/components/DragDrop/Droppable.js +8 -9
  30. package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
  31. package/dist/esm.tsbuildinfo +1 -1
  32. package/dist/js/components/DragDrop/DragButton.d.ts +1 -1
  33. package/dist/js/components/DragDrop/DragButton.d.ts.map +1 -1
  34. package/dist/js/components/DragDrop/DragButton.js +2 -3
  35. package/dist/js/components/DragDrop/DragButton.js.map +1 -1
  36. package/dist/js/components/DragDrop/DragDropContainer.d.ts +1 -1
  37. package/dist/js/components/DragDrop/DragDropContainer.d.ts.map +1 -1
  38. package/dist/js/components/DragDrop/DragDropContainer.js +17 -21
  39. package/dist/js/components/DragDrop/DragDropContainer.js.map +1 -1
  40. package/dist/js/components/DragDrop/DragDropSort.d.ts +2 -2
  41. package/dist/js/components/DragDrop/DragDropSort.d.ts.map +1 -1
  42. package/dist/js/components/DragDrop/DragDropSort.js +4 -4
  43. package/dist/js/components/DragDrop/DragDropSort.js.map +1 -1
  44. package/dist/js/components/DragDrop/Draggable.d.ts +1 -1
  45. package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -1
  46. package/dist/js/components/DragDrop/Draggable.js +2 -4
  47. package/dist/js/components/DragDrop/Draggable.js.map +1 -1
  48. package/dist/js/components/DragDrop/DraggableDataListItem.d.ts +1 -1
  49. package/dist/js/components/DragDrop/DraggableDataListItem.d.ts.map +1 -1
  50. package/dist/js/components/DragDrop/DraggableDataListItem.js +2 -6
  51. package/dist/js/components/DragDrop/DraggableDataListItem.js.map +1 -1
  52. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts +2 -2
  53. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -1
  54. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js +12 -16
  55. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  56. package/dist/js/components/DragDrop/Droppable.d.ts +3 -3
  57. package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
  58. package/dist/js/components/DragDrop/Droppable.js +8 -9
  59. package/dist/js/components/DragDrop/Droppable.js.map +1 -1
  60. package/package.json +8 -8
  61. package/src/components/DragDrop/DragButton.tsx +0 -1
  62. package/src/components/DragDrop/DragDropContainer.tsx +9 -9
  63. package/src/components/DragDrop/DragDropSort.tsx +3 -3
  64. package/src/components/DragDrop/Draggable.tsx +0 -1
  65. package/src/components/DragDrop/DraggableDataListItem.tsx +0 -1
  66. package/src/components/DragDrop/DraggableDualListSelectorListItem.tsx +3 -3
  67. package/src/components/DragDrop/Droppable.tsx +5 -5
  68. package/src/components/DragDrop/__tests__/DragDrop.test.tsx +0 -1
  69. package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +1 -1
  70. package/src/components/DragDrop/examples/BasicSorting.tsx +2 -2
  71. package/src/components/DragDrop/examples/DataListDraggable.tsx +2 -2
  72. package/src/components/DragDrop/examples/DragDrop.md +1 -0
  73. package/src/components/DragDrop/examples/DragDropContainerBasic.tsx +2 -2
  74. package/src/components/DragDrop/examples/DragDropContainerDataList.tsx +2 -2
  75. package/src/components/DragDrop/examples/DragDropContainerDualListSelector.tsx +6 -6
  76. package/src/components/DragDrop/examples/DragDropDemos.md +1 -0
  77. package/src/components/DragDrop/examples/DualListSelectorDraggable.tsx +4 -4
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import * as ReactDOM from 'react-dom';
3
3
  import { css } from '@patternfly/react-styles';
4
4
  import {
@@ -79,17 +79,17 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
79
79
  overlayProps,
80
80
  ...props
81
81
  }: DragDropContainerProps) => {
82
- const itemsCopy = React.useRef<Record<string, DraggableObject[]> | null>(null);
83
- const hasRecentlyMovedContainer = React.useRef(false);
84
- const [activeId, setActiveId] = React.useState<UniqueIdentifier>(null);
85
- const lastOverId = React.useRef<UniqueIdentifier | null>(null);
82
+ const itemsCopy = useRef<Record<string, DraggableObject[]> | null>(null);
83
+ const hasRecentlyMovedContainer = useRef(false);
84
+ const [activeId, setActiveId] = useState<UniqueIdentifier>(null);
85
+ const lastOverId = useRef<UniqueIdentifier | null>(null);
86
86
 
87
- const findItem = React.useCallback(
87
+ const findItem = useCallback(
88
88
  (id: UniqueIdentifier, containerId: UniqueIdentifier) => items[containerId].find((item) => item.id === id),
89
89
  [items]
90
90
  );
91
91
 
92
- const findContainer = React.useCallback(
92
+ const findContainer = useCallback(
93
93
  (id: UniqueIdentifier) => {
94
94
  if (id in items) {
95
95
  return id;
@@ -106,7 +106,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
106
106
  })
107
107
  );
108
108
 
109
- const collisionDetectionStrategy: CollisionDetection = React.useCallback(
109
+ const collisionDetectionStrategy: CollisionDetection = useCallback(
110
110
  (args) => {
111
111
  if (activeId && activeId in items) {
112
112
  return closestCenter({
@@ -146,7 +146,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
146
146
  [activeId, items]
147
147
  );
148
148
 
149
- React.useEffect(() => {
149
+ useEffect(() => {
150
150
  requestAnimationFrame(() => {
151
151
  hasRecentlyMovedContainer.current = false;
152
152
  });
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { useMemo } from 'react';
2
2
  import { DndContextProps, DragEndEvent, DragStartEvent } from '@dnd-kit/core';
3
3
  import { Droppable } from './Droppable';
4
4
  import { DragDropContainer, DraggableObject } from './DragDropContainer';
@@ -12,7 +12,7 @@ export type DragDropSortDragStartEvent = DragStartEvent;
12
12
  export interface DragDropSortProps extends DndContextProps {
13
13
  /** Custom defined content wrapper for draggable items. By default, draggable items are wrapped in a styled div.
14
14
  * Intended to be a 'DataList' or 'DualListSelectorList' without children. */
15
- children?: React.ReactElement;
15
+ children?: React.ReactElement<any>;
16
16
  /** Sorted array of draggable objects */
17
17
  items: DraggableObject[];
18
18
  /** Callback when user drops a draggable object */
@@ -38,7 +38,7 @@ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
38
38
  overlayProps,
39
39
  ...props
40
40
  }: DragDropSortProps) => {
41
- const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
41
+ const itemIds = useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
42
42
 
43
43
  const handleDragStart = (event: DragStartEvent) => {
44
44
  onDrag(event, itemIds.indexOf(event.active.id as string));
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { useSortable } from '@dnd-kit/sortable';
3
2
  import { CSS } from '@dnd-kit/utilities';
4
3
  import { css } from '@patternfly/react-styles';
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { useSortable } from '@dnd-kit/sortable';
3
2
  import { CSS } from '@dnd-kit/utilities';
4
3
  import { css } from '@patternfly/react-styles';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { useContext } from 'react';
2
2
  import { useSortable } from '@dnd-kit/sortable';
3
3
  import { CSS } from '@dnd-kit/utilities';
4
4
  import { css } from '@patternfly/react-styles';
@@ -23,7 +23,7 @@ export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<
23
23
  /** @hide Internal field used to keep track of order of unfiltered options. */
24
24
  orderIndex?: number;
25
25
  /** @hide Forwarded ref */
26
- innerRef?: React.RefObject<HTMLLIElement>;
26
+ innerRef?: React.RefObject<HTMLLIElement | null>;
27
27
  /** Flag indicating if the dual list selector is in a disabled state */
28
28
  isDisabled?: boolean;
29
29
  }
@@ -42,7 +42,7 @@ export const DraggableDualListSelectorListItem: React.FunctionComponent<Draggabl
42
42
  animateLayoutChanges: () => false
43
43
  });
44
44
 
45
- const { setFocusedOption } = React.useContext(DualListSelectorListContext);
45
+ const { setFocusedOption } = useContext(DualListSelectorListContext);
46
46
 
47
47
  const style = {
48
48
  transform: CSS.Transform.toString(transform),
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { cloneElement, useMemo } from 'react';
2
2
  import { useDroppable } from '@dnd-kit/core';
3
3
  import { DraggableObject } from './DragDropContainer';
4
4
  import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
@@ -14,10 +14,10 @@ interface DroppableProps extends React.HTMLProps<HTMLDivElement> {
14
14
  /** Array of draggable objects */
15
15
  items: DraggableObject[];
16
16
  /** Alternative to wrapping drop zone in a div, will override any ref and style set on the element. */
17
- wrapper?: React.ReactElement;
17
+ wrapper?: React.ReactElement<any>;
18
18
  /** The variant determines which component wraps the draggable object.
19
19
  * Default variant wraps the draggable object in a div.
20
- * DataList vairant wraps the draggable object in a DataListItem
20
+ * DataList variant wraps the draggable object in a DataListItem
21
21
  * DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
22
22
  * TableComposable variant wraps the draggable objects in TODO
23
23
  * */
@@ -31,7 +31,7 @@ export const Droppable: React.FunctionComponent<DroppableProps> = ({
31
31
  wrapper,
32
32
  ...props
33
33
  }: DroppableProps) => {
34
- const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
34
+ const itemIds = useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
35
35
  const { setNodeRef } = useDroppable({ id: id ? id : 'droppable' });
36
36
 
37
37
  const content = items.map((item: DraggableObject) => {
@@ -60,7 +60,7 @@ export const Droppable: React.FunctionComponent<DroppableProps> = ({
60
60
  return (
61
61
  <SortableContext items={itemIds} strategy={verticalListSortingStrategy} id={id}>
62
62
  {wrapper &&
63
- React.cloneElement(wrapper, {
63
+ cloneElement(wrapper, {
64
64
  children: content,
65
65
  ref: setNodeRef,
66
66
  ...props
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { render } from '@testing-library/react';
3
2
  import { DragDropSort } from '../';
4
3
 
@@ -142,7 +142,7 @@ exports[`renders some divs 1`] = `
142
142
  aria-live="assertive"
143
143
  id="DndLiveRegion-0"
144
144
  role="status"
145
- style="position: fixed; width: 1px; height: 1px; margin: -1px; border: 0px; padding: 0px; overflow: hidden; clip-path: inset(100%); white-space: nowrap;"
145
+ style="position: fixed; top: 0px; left: 0px; width: 1px; height: 1px; margin: -1px; border: 0px; padding: 0px; overflow: hidden; clip-path: inset(100%); white-space: nowrap;"
146
146
  />
147
147
  </div>
148
148
  </DocumentFragment>
@@ -1,8 +1,8 @@
1
- import React from 'react';
1
+ import { useState } from 'react';
2
2
  import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
3
3
 
4
4
  export const BasicSorting: React.FunctionComponent = () => {
5
- const [items, setItems] = React.useState<DraggableObject[]>([
5
+ const [items, setItems] = useState<DraggableObject[]>([
6
6
  { id: 'basic-1', content: 'one' },
7
7
  { id: 'basic-2', content: 'two' },
8
8
  { id: 'basic-3', content: 'three' }
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useState } from 'react';
2
2
  import { DataList, DataListCell, DataListCheck, DataListControl, DataListItemCells } from '@patternfly/react-core';
3
3
  import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
4
4
 
@@ -22,7 +22,7 @@ const getItems = (count: number): DraggableObject[] =>
22
22
  }));
23
23
 
24
24
  export const DataListDraggable: React.FunctionComponent = (props) => {
25
- const [items, setItems] = React.useState<DraggableObject[]>(getItems(10));
25
+ const [items, setItems] = useState<DraggableObject[]>(getItems(10));
26
26
 
27
27
  return (
28
28
  <DragDropSort
@@ -8,6 +8,7 @@ hideNavItem: true
8
8
 
9
9
  Note: This drag and drop implementation lives in its own package at [@patternfly/react-drag-drop](https://www.npmjs.com/package/@patternfly/react-drag-drop)!
10
10
 
11
+ import { useState } from 'react';
11
12
  import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
12
13
  import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
13
14
  import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useState } from 'react';
2
2
  import {
3
3
  Droppable as NewDroppable,
4
4
  DraggableObject,
@@ -9,7 +9,7 @@ import {
9
9
  } from '@patternfly/react-drag-drop';
10
10
 
11
11
  export const DragDropContainerBasic: React.FunctionComponent = () => {
12
- const [allItems, setAllItems] = React.useState<Record<string, DraggableObject[]>>({
12
+ const [allItems, setAllItems] = useState<Record<string, DraggableObject[]>>({
13
13
  container1: [
14
14
  { id: 'button-1', content: 'one' },
15
15
  { id: 'button-2', content: 'two' },
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useState } from 'react';
2
2
  import {
3
3
  DataList,
4
4
  DataListCell,
@@ -35,7 +35,7 @@ const getItems = (from: number, count: number): DraggableObject[] =>
35
35
  }));
36
36
 
37
37
  export const DataListDraggable: React.FunctionComponent = (props) => {
38
- const [items, setItems] = React.useState<Record<string, DraggableObject[]>>({
38
+ const [items, setItems] = useState<Record<string, DraggableObject[]>>({
39
39
  group1: getItems(0, 5),
40
40
  group2: getItems(5, 5)
41
41
  });
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
  import {
3
3
  DualListSelector,
4
4
  DualListSelectorPane,
@@ -14,21 +14,21 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
14
14
  import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
15
15
 
16
16
  export const DragDropContainerDualListSelector: React.FunctionComponent = () => {
17
- const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
18
- const [availableOptions, setAvailableOptions] = React.useState<DraggableObject[]>([
17
+ const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = useState(false);
18
+ const [availableOptions, setAvailableOptions] = useState<DraggableObject[]>([
19
19
  { id: 'Apple', content: 'Apple', props: { key: 'Apple', isSelected: false } },
20
20
  { id: 'Banana', content: 'Banana', props: { key: 'Banana', isSelected: false } },
21
21
  { id: 'Pineapple', content: 'Pineapple', props: { key: 'Pineapple', isSelected: false } }
22
22
  ]);
23
23
 
24
- const [chosenOptions, setChosenOptions] = React.useState<DraggableObject[]>([
24
+ const [chosenOptions, setChosenOptions] = useState<DraggableObject[]>([
25
25
  { id: 'Orange', content: 'Orange', props: { key: 'Orange', isSelected: false } },
26
26
  { id: 'Grape', content: 'Grape', props: { key: 'Grape', isSelected: false } },
27
27
  { id: 'Peach', content: 'Peach', props: { key: 'Peach', isSelected: false } },
28
28
  { id: 'Strawberry', content: 'Strawberry', props: { key: 'Strawberry', isSelected: false } }
29
29
  ]);
30
30
 
31
- const [allDraggableItems, setAllItems] = React.useState<Record<string, DraggableObject[]>>({
31
+ const [allDraggableItems, setAllItems] = useState<Record<string, DraggableObject[]>>({
32
32
  available: availableOptions.map((option, index) => ({
33
33
  ...option,
34
34
  props: {
@@ -53,7 +53,7 @@ export const DragDropContainerDualListSelector: React.FunctionComponent = () =>
53
53
  setAllItems(items);
54
54
  };
55
55
 
56
- React.useEffect(() => {
56
+ useEffect(() => {
57
57
  setAllItems({
58
58
  available: availableOptions.map((option, index) => ({
59
59
  ...option,
@@ -7,6 +7,7 @@ propComponents: ['DragDropSort', 'DraggableObject']
7
7
 
8
8
  Note: This drag and drop implementation lives in its own package at [@patternfly/react-drag-drop](https://www.npmjs.com/package/@patternfly/react-drag-drop)!
9
9
 
10
+ import { useEffect, useState } from 'react';
10
11
  import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
11
12
  import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
12
13
  import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { useState } from 'react';
2
2
  import {
3
3
  DualListSelector,
4
4
  DualListSelectorPane,
@@ -15,14 +15,14 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
15
15
  import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
16
16
 
17
17
  export const ComposableDualListSelector: React.FunctionComponent = () => {
18
- const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
19
- const [availableOptions, setAvailableOptions] = React.useState<DraggableObject[]>([
18
+ const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = useState(false);
19
+ const [availableOptions, setAvailableOptions] = useState<DraggableObject[]>([
20
20
  { id: 'Apple', content: 'Apple', props: { key: 'Apple', isSelected: false } },
21
21
  { id: 'Banana', content: 'Banana', props: { key: 'Banana', isSelected: false } },
22
22
  { id: 'Pineapple', content: 'Pineapple', props: { key: 'Pineapple', isSelected: false } }
23
23
  ]);
24
24
 
25
- const [chosenOptions, setChosenOptions] = React.useState<DraggableObject[]>([
25
+ const [chosenOptions, setChosenOptions] = useState<DraggableObject[]>([
26
26
  { id: 'Orange', content: 'Orange', props: { key: 'Orange', isSelected: false } },
27
27
  { id: 'Grape', content: 'Grape', props: { key: 'Grape', isSelected: false } },
28
28
  { id: 'Peach', content: 'Peach', props: { key: 'Peach', isSelected: false } },