-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui5-list,ui5-tree): make drag&drop feature public (#8904)
The drag&drop feature for both `ui5-tree` and `ui5-list` components is now public. Updated documentation and new samples have been added to assist with implementation. Related to #8461, #7887
- Loading branch information
1 parent
70dc2a6
commit 60b8038
Showing
13 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/website/docs/_samples/main/List/DragAndDrop/DragAndDrop.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import html from '!!raw-loader!./sample.html'; | ||
import js from '!!raw-loader!./main.js'; | ||
|
||
<Editor html={html} js={js} /> |
45 changes: 45 additions & 0 deletions
45
packages/website/docs/_samples/main/List/DragAndDrop/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import "@ui5/webcomponents/dist/List.js"; | ||
import "@ui5/webcomponents/dist/StandardListItem.js"; | ||
|
||
import "@ui5/webcomponents-icons/dist/checklist-item.js"; | ||
|
||
const list = document.getElementById('listDnd1'); | ||
const handleBeforeItemMove = (e) => { | ||
const { destination, source } = e.detail; | ||
|
||
if (destination.placement === 'Before' || destination.placement === 'After') { | ||
e.preventDefault(); | ||
} | ||
|
||
}; | ||
|
||
const handleMoveOver = (e) => { | ||
const { destination, source } = e.detail; | ||
|
||
if (!list.contains(source.element)) { | ||
return; | ||
} | ||
|
||
handleBeforeItemMove(e); | ||
}; | ||
|
||
const handleMove = (e) => { | ||
const { destination, source } = e.detail; | ||
const parent = destination.element.closest('[ui5-list]'); | ||
|
||
if (destination.placement === 'Before') { | ||
parent.insertBefore(source.element, destination.element); | ||
} else if (destination.placement === 'After') { | ||
const nextElement = Array.from(parent.children).at( | ||
Array.from(parent.children).indexOf(destination.element) + 1 | ||
); | ||
|
||
parent.insertBefore(source.element, nextElement); | ||
} else if (destination.placement === 'On') { | ||
destination.element.prepend(source.element); | ||
} | ||
}; | ||
|
||
list.addEventListener('move-over', handleMoveOver); | ||
list.addEventListener('move', handleMove); | ||
|
27 changes: 27 additions & 0 deletions
27
packages/website/docs/_samples/main/List/DragAndDrop/sample.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- playground-fold --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sample</title> | ||
</head> | ||
|
||
<body style="background-color: var(--sapBackgroundColor)"> | ||
<!-- playground-fold-end --> | ||
|
||
<ui5-list id="listDnd1"> | ||
<ui5-li icon="checklist-item" movable>Item #1</ui5-li> | ||
<ui5-li icon="checklist-item" movable>Item #2</ui5-li> | ||
<ui5-li icon="checklist-item" movable>Item #3</ui5-li> | ||
<ui5-li icon="checklist-item" movable>Item #4</ui5-li> | ||
<ui5-li icon="checklist-item" movable>Item #5</ui5-li> | ||
</ui5-list> | ||
|
||
<!-- playground-fold --> | ||
<script type="module" src="main.js"></script> | ||
</body> | ||
|
||
</html> | ||
<!-- playground-fold-end --> |
4 changes: 4 additions & 0 deletions
4
packages/website/docs/_samples/main/Tree/DragAndDrop/DragAndDrop.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import html from '!!raw-loader!./sample.html'; | ||
import js from '!!raw-loader!./main.js'; | ||
|
||
<Editor html={html} js={js} /> |
55 changes: 55 additions & 0 deletions
55
packages/website/docs/_samples/main/Tree/DragAndDrop/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import "@ui5/webcomponents/dist/Tree.js"; | ||
import "@ui5/webcomponents/dist/TreeItem.js"; | ||
import "@ui5/webcomponents/dist/Title.js"; | ||
import "@ui5/webcomponents/dist/Label.js"; | ||
|
||
|
||
const tree = document.getElementById("tree"); | ||
const handleBeforeItemMove = (e) => { | ||
const { destination, source } = e.detail; | ||
|
||
if (destination.placement === "Before" || destination.placement === "After") { | ||
e.preventDefault(); | ||
} | ||
|
||
if (destination.placement === "On" && "allowsNesting" in destination.element.dataset) { | ||
e.preventDefault(); | ||
} | ||
|
||
console.log(`Moving "${source.element.text}" ${destination.placement.toLowerCase()} "${destination.element.text}"`); | ||
}; | ||
|
||
const handleMoveOver = (e) => { | ||
const { destination, source } = e.detail; | ||
|
||
if (!tree.contains(source.element)) { | ||
return; | ||
} | ||
|
||
handleBeforeItemMove(e); | ||
}; | ||
|
||
const handleMove = (e) => { | ||
const { destination, source } = e.detail; | ||
const parent = destination.element.parentNode.closest("[ui5-tree-item]") || | ||
destination.element.closest("[ui5-tree]"); | ||
|
||
if (destination.placement === "Before") { | ||
parent.insertBefore( | ||
source.element, | ||
destination.element | ||
); | ||
} else if (destination.placement === "After") { | ||
const nextElement = Array.from(parent.children).at(Array.from(parent.children).indexOf(destination.element) + 1); | ||
|
||
parent.insertBefore( | ||
source.element, | ||
nextElement, | ||
); | ||
} else if (destination.placement === "On") { | ||
destination.element.prepend(source.element); | ||
} | ||
}; | ||
|
||
tree.addEventListener("move-over", handleMoveOver); | ||
tree.addEventListener("move", handleMove); |
51 changes: 51 additions & 0 deletions
51
packages/website/docs/_samples/main/Tree/DragAndDrop/sample.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!-- playground-fold --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sample</title> | ||
</head> | ||
|
||
<body style="background-color: var(--sapBackgroundColor)"> | ||
<!-- playground-fold-end --> | ||
<ui5-tree id="tree" no-data-text="No data" mode="MultiSelect" accessible-name="Tree with accessibleName"> | ||
|
||
<ui5-tree-item movable text="Tree 1" icon="paste" additional-text="Available" indeterminate selected additional-text-state="Information" accessible-name="Tree item with accessibleName"> | ||
<ui5-title slot="content"> | ||
<ui5-label>Tree 1</ui5-label> | ||
<ui5-label>Tree 1</ui5-label> | ||
</ui5-title> | ||
|
||
<ui5-tree-item movable expanded text="Tree 1.1" additional-text="Re-stock" additional-text-state="Negative" indeterminate selected> | ||
<ui5-tree-item movable text="Tree 1.1.1" additional-text="Required" additional-text-state="Critical" selected></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 1.1.2" additional-text="Available" additional-text-state="Positive"></ui5-tree-item> | ||
</ui5-tree-item> | ||
</ui5-tree-item> | ||
|
||
<ui5-tree-item movable data-allows-nesting text="Tree 2(Allows Nesting)" icon="copy"> | ||
<ui5-tree-item movable id="firstCollapsedItem" text="Tree 2.1"> | ||
<ui5-tree-item movable text="Tree 2.1.1"></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.1.2"> | ||
<ui5-tree-item movable text="Tree 2.1.2.1"></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.1.2.2"></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.1.2.3"></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.1.2.5"></ui5-tree-item> | ||
</ui5-tree-item> | ||
</ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.2"></ui5-tree-item> | ||
<ui5-tree-item movable text="Tree 2.3"></ui5-tree-item> | ||
</ui5-tree-item> | ||
|
||
<ui5-tree-item movable text="Tree 3 (no icon)"> | ||
</ui5-tree-item> | ||
|
||
</ui5-tree> | ||
|
||
<!-- playground-fold --> | ||
<script type="module" src="main.js"></script> | ||
</body> | ||
|
||
</html> | ||
<!-- playground-fold-end --> |