@patternfly/react-core 6.2.0-prerelease.4 → 6.2.0-prerelease.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 +12 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/AboutModal/package.json +1 -1
- package/dist/dynamic/components/Accordion/package.json +1 -1
- package/dist/dynamic/components/ActionList/package.json +1 -1
- package/dist/dynamic/components/Alert/package.json +1 -1
- package/dist/dynamic/components/Avatar/package.json +1 -1
- package/dist/dynamic/components/BackToTop/package.json +1 -1
- package/dist/dynamic/components/Backdrop/package.json +1 -1
- package/dist/dynamic/components/BackgroundImage/package.json +1 -1
- package/dist/dynamic/components/Badge/package.json +1 -1
- package/dist/dynamic/components/Banner/package.json +1 -1
- package/dist/dynamic/components/Brand/package.json +1 -1
- package/dist/dynamic/components/Breadcrumb/package.json +1 -1
- package/dist/dynamic/components/Button/package.json +1 -1
- package/dist/dynamic/components/CalendarMonth/package.json +1 -1
- package/dist/dynamic/components/Card/package.json +1 -1
- package/dist/dynamic/components/Checkbox/package.json +1 -1
- package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
- package/dist/dynamic/components/CodeBlock/package.json +1 -1
- package/dist/dynamic/components/Content/package.json +1 -1
- package/dist/dynamic/components/DataList/package.json +1 -1
- package/dist/dynamic/components/DatePicker/package.json +1 -1
- package/dist/dynamic/components/DescriptionList/package.json +1 -1
- package/dist/dynamic/components/Divider/package.json +1 -1
- package/dist/dynamic/components/Drawer/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/components/EmptyState/package.json +1 -1
- package/dist/dynamic/components/ExpandableSection/package.json +1 -1
- package/dist/dynamic/components/FileUpload/package.json +1 -1
- package/dist/dynamic/components/Form/package.json +1 -1
- package/dist/dynamic/components/FormSelect/package.json +1 -1
- package/dist/dynamic/components/HelperText/package.json +1 -1
- package/dist/dynamic/components/Hint/package.json +1 -1
- package/dist/dynamic/components/Icon/package.json +1 -1
- package/dist/dynamic/components/InputGroup/package.json +1 -1
- package/dist/dynamic/components/JumpLinks/package.json +1 -1
- package/dist/dynamic/components/Label/package.json +1 -1
- package/dist/dynamic/components/List/package.json +1 -1
- package/dist/dynamic/components/LoginPage/package.json +1 -1
- package/dist/dynamic/components/Masthead/package.json +1 -1
- package/dist/dynamic/components/Menu/package.json +1 -1
- package/dist/dynamic/components/MenuToggle/package.json +1 -1
- package/dist/dynamic/components/Modal/package.json +1 -1
- package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
- package/dist/dynamic/components/Nav/package.json +1 -1
- package/dist/dynamic/components/NotificationBadge/package.json +1 -1
- package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
- package/dist/dynamic/components/NumberInput/package.json +1 -1
- package/dist/dynamic/components/OverflowMenu/package.json +1 -1
- package/dist/dynamic/components/Page/package.json +1 -1
- package/dist/dynamic/components/Pagination/package.json +1 -1
- package/dist/dynamic/components/Panel/package.json +1 -1
- package/dist/dynamic/components/Popover/package.json +1 -1
- package/dist/dynamic/components/Progress/package.json +1 -1
- package/dist/dynamic/components/ProgressStepper/package.json +1 -1
- package/dist/dynamic/components/Radio/package.json +1 -1
- package/dist/dynamic/components/SearchInput/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic/components/Sidebar/package.json +1 -1
- package/dist/dynamic/components/SimpleList/package.json +1 -1
- package/dist/dynamic/components/Skeleton/package.json +1 -1
- package/dist/dynamic/components/SkipToContent/package.json +1 -1
- package/dist/dynamic/components/Slider/package.json +1 -1
- package/dist/dynamic/components/Spinner/package.json +1 -1
- package/dist/dynamic/components/Switch/package.json +1 -1
- package/dist/dynamic/components/Tabs/package.json +1 -1
- package/dist/dynamic/components/TextArea/package.json +1 -1
- package/dist/dynamic/components/TextInput/package.json +1 -1
- package/dist/dynamic/components/TextInputGroup/package.json +1 -1
- package/dist/dynamic/components/TimePicker/package.json +1 -1
- package/dist/dynamic/components/Timestamp/package.json +1 -1
- package/dist/dynamic/components/Title/package.json +1 -1
- package/dist/dynamic/components/ToggleGroup/package.json +1 -1
- package/dist/dynamic/components/Toolbar/package.json +1 -1
- package/dist/dynamic/components/Tooltip/package.json +1 -1
- package/dist/dynamic/components/TreeView/package.json +1 -1
- package/dist/dynamic/components/Truncate/package.json +1 -1
- package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
- package/dist/dynamic/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/Chip/package.json +1 -1
- package/dist/dynamic/deprecated/components/DragDrop/package.json +1 -1
- package/dist/dynamic/deprecated/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/deprecated/components/Modal/package.json +1 -1
- package/dist/dynamic/deprecated/components/Tile/package.json +1 -1
- package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
- package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
- package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
- package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
- package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
- package/dist/dynamic/helpers/constants/package.json +1 -1
- package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
- package/dist/dynamic/helpers/fileUtils/package.json +1 -1
- package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
- package/dist/dynamic/helpers/package.json +1 -1
- package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
- package/dist/dynamic/helpers/typeUtils/package.json +1 -1
- package/dist/dynamic/helpers/useInterval/package.json +1 -1
- package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
- package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
- package/dist/dynamic/helpers/util/package.json +1 -1
- package/dist/dynamic/layouts/Bullseye/package.json +1 -1
- package/dist/dynamic/layouts/Flex/package.json +1 -1
- package/dist/dynamic/layouts/Gallery/package.json +1 -1
- package/dist/dynamic/layouts/Grid/package.json +1 -1
- package/dist/dynamic/layouts/Level/package.json +1 -1
- package/dist/dynamic/layouts/Split/package.json +1 -1
- package/dist/dynamic/layouts/Stack/package.json +1 -1
- package/dist/dynamic/styles/package.json +1 -1
- package/dist/umd/assets/{output-DpfM3x9c.css → output-DiECpjV-.css} +18839 -18839
- package/helpers/package.json +1 -1
- package/layouts/package.json +1 -1
- package/next/package.json +1 -1
- package/package.json +2 -2
- package/src/components/Toolbar/examples/Toolbar.md +8 -8
- package/src/components/TreeView/examples/TreeView.md +7 -1
- package/src/components/TreeView/examples/TreeViewWithIconPerItem.tsx +64 -0
- package/src/components/DataList/examples/DataListDraggable.tsx +0 -108
- package/src/components/DualListSelector/examples/DualListSelectorDragDrop.tsx +0 -177
package/helpers/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.2.0-prerelease.5","private":true}
|
package/layouts/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.2.0-prerelease.5","private":true}
|
package/next/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.2.0-prerelease.5","private":true}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "6.2.0-prerelease.
|
|
3
|
+
"version": "6.2.0-prerelease.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",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"react": "^17 || ^18",
|
|
64
64
|
"react-dom": "^17 || ^18"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "640b9eb146a8ecdaae6cfcbfbbefe4c27289c877"
|
|
67
67
|
}
|
|
@@ -62,6 +62,14 @@ Note: This example does not demonstrate responsive toolbar behavior. Responsive
|
|
|
62
62
|
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
### Background color variants
|
|
66
|
+
|
|
67
|
+
To change the background color of a toolbar, use the `colorVariant` property on the `<Toolbar>`.
|
|
68
|
+
|
|
69
|
+
```ts file="./ToolbarColorVariant.tsx"
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
|
|
65
73
|
## Examples with toggle groups and filters
|
|
66
74
|
|
|
67
75
|
The following examples use toggle groups to allow for more responsive and complex toolbars with multiple items and groups of items. To visualize responsive toolbar behavior in the following examples, resize the browser to a smaller screen width.
|
|
@@ -112,11 +120,3 @@ When all of a toolbar's required elements cannot fit in a single line, you can s
|
|
|
112
120
|
```ts file="./ToolbarStacked.tsx"
|
|
113
121
|
|
|
114
122
|
```
|
|
115
|
-
|
|
116
|
-
## Background color variants
|
|
117
|
-
|
|
118
|
-
To change the background color of a toolbar, use the `colorVariant` property on the `<Toolbar>`.
|
|
119
|
-
|
|
120
|
-
```ts file="./ToolbarColorVariant.tsx"
|
|
121
|
-
|
|
122
|
-
```
|
|
@@ -5,7 +5,7 @@ cssPrefix: pf-v6-c-tree-view
|
|
|
5
5
|
propComponents: ['TreeView', 'TreeViewDataItem', 'TreeViewSearch']
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
import { FolderIcon, FolderOpenIcon, EllipsisVIcon, ClipboardIcon, HamburgerIcon } from '@patternfly/react-icons';
|
|
8
|
+
import { FolderIcon, FolderOpenIcon, EllipsisVIcon, ClipboardIcon, HamburgerIcon, GitlabIcon, GithubIcon, GoogleIcon } from '@patternfly/react-icons';
|
|
9
9
|
|
|
10
10
|
## Examples
|
|
11
11
|
|
|
@@ -51,6 +51,12 @@ A search input can be used to filter tree view items. It is recommended that a t
|
|
|
51
51
|
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
### With unique icon per item
|
|
55
|
+
|
|
56
|
+
```ts file='./TreeViewWithIconPerItem.tsx'
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
54
60
|
### With badges
|
|
55
61
|
|
|
56
62
|
```ts file='./TreeViewWithBadges.tsx'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TreeView, TreeViewDataItem } from '@patternfly/react-core';
|
|
3
|
+
import GitlabIcon from '@patternfly/react-icons/dist/esm/icons/gitlab-icon';
|
|
4
|
+
import GithubIcon from '@patternfly/react-icons/dist/esm/icons/github-icon';
|
|
5
|
+
import GoogleIcon from '@patternfly/react-icons/dist/esm/icons/google-icon';
|
|
6
|
+
|
|
7
|
+
export const TreeViewWithIconPerItem: React.FunctionComponent = () => {
|
|
8
|
+
const [activeItems, setActiveItems] = React.useState<TreeViewDataItem[]>();
|
|
9
|
+
|
|
10
|
+
const onSelect = (_event: React.MouseEvent, treeViewItem: TreeViewDataItem) => {
|
|
11
|
+
// Ignore folders for selection
|
|
12
|
+
if (treeViewItem && !treeViewItem.children) {
|
|
13
|
+
setActiveItems([treeViewItem]);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const options: TreeViewDataItem[] = [
|
|
17
|
+
{
|
|
18
|
+
name: 'Github accounts',
|
|
19
|
+
id: 'iconPerItem-Github',
|
|
20
|
+
icon: <GithubIcon />,
|
|
21
|
+
children: [
|
|
22
|
+
{
|
|
23
|
+
name: 'Account 1',
|
|
24
|
+
id: 'iconPerItem-Acc1'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Account 2',
|
|
28
|
+
id: 'iconPerItem-Acc2'
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
defaultExpanded: true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Gitlab accounts',
|
|
35
|
+
id: 'iconPerItem-Gitlab',
|
|
36
|
+
icon: <GitlabIcon />,
|
|
37
|
+
children: [
|
|
38
|
+
{
|
|
39
|
+
name: 'Account 3',
|
|
40
|
+
id: 'iconPerItem-Acc3'
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Google accounts',
|
|
46
|
+
id: 'iconPerItem-Google',
|
|
47
|
+
icon: <GoogleIcon />,
|
|
48
|
+
children: [
|
|
49
|
+
{
|
|
50
|
+
name: 'Account 4',
|
|
51
|
+
id: 'iconPerItem-Acc4'
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
return (
|
|
57
|
+
<TreeView
|
|
58
|
+
aria-label="Tree View with unique icon per item example"
|
|
59
|
+
data={options}
|
|
60
|
+
activeItems={activeItems}
|
|
61
|
+
onSelect={onSelect}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
DataList,
|
|
4
|
-
DataListItem,
|
|
5
|
-
DataListCell,
|
|
6
|
-
DataListItemRow,
|
|
7
|
-
DataListCheck,
|
|
8
|
-
DataListControl,
|
|
9
|
-
DataListDragButton,
|
|
10
|
-
DataListItemCells,
|
|
11
|
-
getUniqueId
|
|
12
|
-
} from '@patternfly/react-core';
|
|
13
|
-
import { DragDrop, Draggable, Droppable } from '@patternfly/react-core/deprecated';
|
|
14
|
-
|
|
15
|
-
interface ItemType {
|
|
16
|
-
id: string;
|
|
17
|
-
content: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const getItems = (count: number) =>
|
|
21
|
-
Array.from({ length: count }, (_, idx) => idx).map((idx) => ({
|
|
22
|
-
id: `draggable-item-${idx}`,
|
|
23
|
-
content: `item ${idx} `.repeat(idx === 4 ? 20 : 1)
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
const reorder = (list: ItemType[], startIndex: number, endIndex: number) => {
|
|
27
|
-
const result = list;
|
|
28
|
-
const [removed] = result.splice(startIndex, 1);
|
|
29
|
-
result.splice(endIndex, 0, removed);
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const DataListDraggable: React.FunctionComponent = () => {
|
|
34
|
-
const [items, setItems] = React.useState(getItems(10));
|
|
35
|
-
const [liveText, setLiveText] = React.useState('');
|
|
36
|
-
|
|
37
|
-
function onDrag(source) {
|
|
38
|
-
setLiveText(`Started dragging ${items[source.index].content}`);
|
|
39
|
-
// Return true to allow drag
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function onDragMove(source, dest) {
|
|
44
|
-
const newText = dest ? `Move ${items[source.index].content} to ${items[dest.index].content}` : 'Invalid drop zone';
|
|
45
|
-
if (newText !== liveText) {
|
|
46
|
-
setLiveText(newText);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function onDrop(source, dest) {
|
|
51
|
-
if (dest) {
|
|
52
|
-
const newItems = reorder(items, source.index, dest.index);
|
|
53
|
-
setItems(newItems);
|
|
54
|
-
|
|
55
|
-
setLiveText('Dragging finished.');
|
|
56
|
-
return true; // Signal that this is a valid drop and not to animate the item returning home.
|
|
57
|
-
} else {
|
|
58
|
-
setLiveText('Dragging cancelled. List unchanged.');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const uniqueId = getUniqueId();
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<DragDrop onDrag={onDrag} onDragMove={onDragMove} onDrop={onDrop}>
|
|
66
|
-
<Droppable hasNoWrapper>
|
|
67
|
-
<DataList aria-label="draggable data list example" isCompact>
|
|
68
|
-
{items.map(({ id, content }) => (
|
|
69
|
-
<Draggable key={id} hasNoWrapper>
|
|
70
|
-
<DataListItem aria-labelledby={`draggable-${id}`} ref={React.createRef()}>
|
|
71
|
-
<DataListItemRow>
|
|
72
|
-
<DataListControl>
|
|
73
|
-
<DataListDragButton
|
|
74
|
-
aria-label="Reorder"
|
|
75
|
-
aria-labelledby={`draggable-${id}`}
|
|
76
|
-
aria-describedby={`description-${uniqueId}`}
|
|
77
|
-
aria-pressed="false"
|
|
78
|
-
/>
|
|
79
|
-
<DataListCheck
|
|
80
|
-
id={`check-draggable-${id}`}
|
|
81
|
-
aria-labelledby={`draggable-${id}`}
|
|
82
|
-
name={id}
|
|
83
|
-
otherControls
|
|
84
|
-
/>
|
|
85
|
-
</DataListControl>
|
|
86
|
-
<DataListItemCells
|
|
87
|
-
dataListCells={[
|
|
88
|
-
<DataListCell key={id}>
|
|
89
|
-
<span id={`draggable-${id}`}>{content}</span>
|
|
90
|
-
</DataListCell>
|
|
91
|
-
]}
|
|
92
|
-
/>
|
|
93
|
-
</DataListItemRow>
|
|
94
|
-
</DataListItem>
|
|
95
|
-
</Draggable>
|
|
96
|
-
))}
|
|
97
|
-
</DataList>
|
|
98
|
-
</Droppable>
|
|
99
|
-
<div className="pf-v6-screen-reader" aria-live="assertive">
|
|
100
|
-
{liveText}
|
|
101
|
-
</div>
|
|
102
|
-
<div className="pf-v6-screen-reader" id={`description-${uniqueId}`}>
|
|
103
|
-
Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm
|
|
104
|
-
the drag, or any other key to cancel the drag operation.
|
|
105
|
-
</div>
|
|
106
|
-
</DragDrop>
|
|
107
|
-
);
|
|
108
|
-
};
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
DualListSelector,
|
|
4
|
-
DualListSelectorPane,
|
|
5
|
-
DualListSelectorList,
|
|
6
|
-
DualListSelectorListItem,
|
|
7
|
-
DualListSelectorControlsWrapper,
|
|
8
|
-
DualListSelectorControl
|
|
9
|
-
} from '@patternfly/react-core';
|
|
10
|
-
import { DragDrop, Draggable, Droppable, DraggableItemPosition } from '@patternfly/react-core/deprecated';
|
|
11
|
-
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
12
|
-
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
13
|
-
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
14
|
-
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
15
|
-
|
|
16
|
-
export const DualListSelectorComposableDragDrop: React.FunctionComponent = () => {
|
|
17
|
-
const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
|
|
18
|
-
const [availableOptions, setAvailableOptions] = React.useState([
|
|
19
|
-
{ text: 'Apple', selected: false, isVisible: true },
|
|
20
|
-
{ text: 'Banana', selected: false, isVisible: true },
|
|
21
|
-
{ text: 'Pineapple', selected: false, isVisible: true }
|
|
22
|
-
]);
|
|
23
|
-
const [chosenOptions, setChosenOptions] = React.useState([
|
|
24
|
-
{ text: 'Orange', selected: false, isVisible: true },
|
|
25
|
-
{ text: 'Grape', selected: false, isVisible: true },
|
|
26
|
-
{ text: 'Peach', selected: false, isVisible: true },
|
|
27
|
-
{ text: 'Strawberry', selected: false, isVisible: true }
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
const moveSelected = (fromAvailable: boolean) => {
|
|
31
|
-
const sourceOptions = fromAvailable ? availableOptions : chosenOptions;
|
|
32
|
-
const destinationOptions = fromAvailable ? chosenOptions : availableOptions;
|
|
33
|
-
for (let i = 0; i < sourceOptions.length; i++) {
|
|
34
|
-
const option = sourceOptions[i];
|
|
35
|
-
if (option.selected && option.isVisible) {
|
|
36
|
-
sourceOptions.splice(i, 1);
|
|
37
|
-
destinationOptions.push(option);
|
|
38
|
-
option.selected = false;
|
|
39
|
-
i--;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (fromAvailable) {
|
|
43
|
-
setAvailableOptions([...sourceOptions]);
|
|
44
|
-
setChosenOptions([...destinationOptions]);
|
|
45
|
-
} else {
|
|
46
|
-
setChosenOptions([...sourceOptions]);
|
|
47
|
-
setAvailableOptions([...destinationOptions]);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const moveAll = (fromAvailable: boolean) => {
|
|
52
|
-
if (fromAvailable) {
|
|
53
|
-
setChosenOptions([...availableOptions.filter((option) => option.isVisible), ...chosenOptions]);
|
|
54
|
-
setAvailableOptions([...availableOptions.filter((option) => !option.isVisible)]);
|
|
55
|
-
} else {
|
|
56
|
-
setAvailableOptions([...chosenOptions.filter((option) => option.isVisible), ...availableOptions]);
|
|
57
|
-
setChosenOptions([...chosenOptions.filter((option) => !option.isVisible)]);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const onOptionSelect = (
|
|
62
|
-
event: React.MouseEvent | React.ChangeEvent | React.KeyboardEvent,
|
|
63
|
-
index: number,
|
|
64
|
-
isChosen: boolean
|
|
65
|
-
) => {
|
|
66
|
-
if (ignoreNextOptionSelect) {
|
|
67
|
-
setIgnoreNextOptionSelect(false);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (isChosen) {
|
|
71
|
-
const newChosen = [...chosenOptions];
|
|
72
|
-
newChosen[index].selected = !chosenOptions[index].selected;
|
|
73
|
-
setChosenOptions(newChosen);
|
|
74
|
-
} else {
|
|
75
|
-
const newAvailable = [...availableOptions];
|
|
76
|
-
newAvailable[index].selected = !availableOptions[index].selected;
|
|
77
|
-
setAvailableOptions(newAvailable);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const onDrop = (source: DraggableItemPosition, dest: DraggableItemPosition | undefined) => {
|
|
82
|
-
if (dest) {
|
|
83
|
-
const newList = [...chosenOptions];
|
|
84
|
-
const [removed] = newList.splice(source.index, 1);
|
|
85
|
-
newList.splice(dest.index, 0, removed);
|
|
86
|
-
setChosenOptions(newList);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<DualListSelector>
|
|
94
|
-
<DualListSelectorPane
|
|
95
|
-
title="Available"
|
|
96
|
-
status={`${availableOptions.filter((option) => option.selected && option.isVisible).length} of ${
|
|
97
|
-
availableOptions.filter((option) => option.isVisible).length
|
|
98
|
-
} options selected`}
|
|
99
|
-
>
|
|
100
|
-
<DualListSelectorList>
|
|
101
|
-
{availableOptions.map((option, index) =>
|
|
102
|
-
option.isVisible ? (
|
|
103
|
-
<DualListSelectorListItem
|
|
104
|
-
key={index}
|
|
105
|
-
isSelected={option.selected}
|
|
106
|
-
id={`composable-drag-drop-available-option-${index}`}
|
|
107
|
-
onOptionSelect={(e) => onOptionSelect(e, index, false)}
|
|
108
|
-
>
|
|
109
|
-
{option.text}
|
|
110
|
-
</DualListSelectorListItem>
|
|
111
|
-
) : null
|
|
112
|
-
)}
|
|
113
|
-
</DualListSelectorList>
|
|
114
|
-
</DualListSelectorPane>
|
|
115
|
-
<DualListSelectorControlsWrapper>
|
|
116
|
-
<DualListSelectorControl
|
|
117
|
-
isDisabled={!availableOptions.some((option) => option.selected)}
|
|
118
|
-
onClick={() => moveSelected(true)}
|
|
119
|
-
aria-label="Add selected"
|
|
120
|
-
icon={<AngleRightIcon />}
|
|
121
|
-
/>
|
|
122
|
-
<DualListSelectorControl
|
|
123
|
-
isDisabled={availableOptions.length === 0}
|
|
124
|
-
onClick={() => moveAll(true)}
|
|
125
|
-
aria-label="Add all"
|
|
126
|
-
icon={<AngleDoubleRightIcon />}
|
|
127
|
-
/>
|
|
128
|
-
<DualListSelectorControl
|
|
129
|
-
isDisabled={chosenOptions.length === 0}
|
|
130
|
-
onClick={() => moveAll(false)}
|
|
131
|
-
aria-label="Remove all"
|
|
132
|
-
icon={<AngleDoubleLeftIcon />}
|
|
133
|
-
/>
|
|
134
|
-
<DualListSelectorControl
|
|
135
|
-
onClick={() => moveSelected(false)}
|
|
136
|
-
isDisabled={!chosenOptions.some((option) => option.selected)}
|
|
137
|
-
aria-label="Remove selected"
|
|
138
|
-
icon={<AngleLeftIcon />}
|
|
139
|
-
/>
|
|
140
|
-
</DualListSelectorControlsWrapper>
|
|
141
|
-
<DragDrop
|
|
142
|
-
onDrag={() => {
|
|
143
|
-
setIgnoreNextOptionSelect(true);
|
|
144
|
-
return true;
|
|
145
|
-
}}
|
|
146
|
-
onDrop={onDrop}
|
|
147
|
-
>
|
|
148
|
-
<DualListSelectorPane
|
|
149
|
-
title="Chosen"
|
|
150
|
-
status={`${chosenOptions.filter((option) => option.selected && option.isVisible).length} of ${
|
|
151
|
-
chosenOptions.filter((option) => option.isVisible).length
|
|
152
|
-
} options selected`}
|
|
153
|
-
isChosen
|
|
154
|
-
>
|
|
155
|
-
<Droppable hasNoWrapper>
|
|
156
|
-
<DualListSelectorList>
|
|
157
|
-
{chosenOptions.map((option, index) =>
|
|
158
|
-
option.isVisible ? (
|
|
159
|
-
<Draggable key={index} hasNoWrapper>
|
|
160
|
-
<DualListSelectorListItem
|
|
161
|
-
isSelected={option.selected}
|
|
162
|
-
id={`composable-drag-drop-chosen-option-${index}`}
|
|
163
|
-
onOptionSelect={(e) => onOptionSelect(e, index, true)}
|
|
164
|
-
isDraggable
|
|
165
|
-
>
|
|
166
|
-
{option.text}
|
|
167
|
-
</DualListSelectorListItem>
|
|
168
|
-
</Draggable>
|
|
169
|
-
) : null
|
|
170
|
-
)}
|
|
171
|
-
</DualListSelectorList>
|
|
172
|
-
</Droppable>
|
|
173
|
-
</DualListSelectorPane>
|
|
174
|
-
</DragDrop>
|
|
175
|
-
</DualListSelector>
|
|
176
|
-
);
|
|
177
|
-
};
|