You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1029,16 +1041,22 @@ This can be done by returning multiple keys for an item from the `getItems` func
1029
1041
This example provides representations of each item as plain text, HTML, and a custom app-specific data format. Dropping on the drop targets in this page will use the custom data format to render formatted items. If you drop in an external application supporting rich text, the HTML representation will be used. Dropping in a text editor will use the plain text format.
1030
1042
1031
1043
```tsx example export=true
1044
+
interfaceRichTextItem {
1045
+
id:string,
1046
+
name:string,
1047
+
style:string
1048
+
}
1049
+
1032
1050
function DraggableGridList() {
1033
-
let items=newMap([
1034
-
['ps', {name: 'Photoshop', style: 'strong'}],
1035
-
['xd', {name: 'XD', style: 'strong'}],
1036
-
['id', {name: 'InDesign', style: 'strong'}],
1037
-
['dw', {name: 'Dreamweaver', style: 'em'}],
1038
-
['co', {name: 'Connect', style: 'em'}]
1039
-
]);
1051
+
let items:RichTextItem[] =[
1052
+
{id: 'ps', name: 'Photoshop', style: 'strong'},
1053
+
{id: 'xd', name: 'XD', style: 'strong'},
1054
+
{id: 'id', name: 'InDesign', style: 'strong'},
1055
+
{id: 'dw', name: 'Dreamweaver', style: 'em'},
1056
+
{id: 'co', name: 'Connect', style: 'em'}
1057
+
];
1040
1058
1041
-
let { dragAndDropHooks } =useDragAndDrop({
1059
+
let { dragAndDropHooks } =useDragAndDrop<RichTextItem>({
1042
1060
///- begin collapse -///
1043
1061
renderDragPreview(items) {
1044
1062
return (
@@ -1050,13 +1068,12 @@ function DraggableGridList() {
@@ -1082,15 +1099,17 @@ function DraggableGridList() {
1082
1099
Dropping on the GridList as a whole can be enabled using the `onRootDrop` event. When a valid drag hovers over the GridList, it receives the `isDropTarget` state and can be styled using the `[data-drop-target]` CSS selector.
1083
1100
1084
1101
```tsx example
1102
+
///- begin collapse -///
1085
1103
interfaceItem {
1086
1104
id:number,
1087
1105
name:string
1088
1106
}
1107
+
///- end collapse -///
1089
1108
1090
1109
function Example() {
1091
1110
let [items, setItems] =React.useState<Item[]>([]);
1092
1111
1093
-
let { dragAndDropHooks } =useDragAndDrop({
1112
+
let { dragAndDropHooks } =useDragAndDrop<Item>({
1094
1113
/*- begin highlight -*/
1095
1114
async onRootDrop(e) {
1096
1115
let items =awaitPromise.all(e.items.map(async (item, i) => {
@@ -1528,6 +1547,13 @@ The `onDragEnd` event allows the drag source to respond when a drag that it init
1528
1547
This example removes the dragged items from the UI when a move operation is completed. Try holding the <Keyboard>Option</Keyboard> or <Keyboard>Alt</Keyboard> keys to change the operation to copy, and see how the behavior changes.
1529
1548
1530
1549
```tsx example
1550
+
///- begin collapse -///
1551
+
interfaceItem {
1552
+
id:number,
1553
+
name:string
1554
+
}
1555
+
///- end collapse -///
1556
+
1531
1557
function Example() {
1532
1558
let list =useListData({
1533
1559
initialItems: [
@@ -1539,7 +1565,7 @@ function Example() {
1539
1565
]
1540
1566
});
1541
1567
1542
-
let { dragAndDropHooks } =useDragAndDrop({
1568
+
let { dragAndDropHooks } =useDragAndDrop<Item>({
1543
1569
///- begin collapse -///
1544
1570
renderDragPreview(items) {
1545
1571
return (
@@ -1549,9 +1575,8 @@ function Example() {
1549
1575
</div>
1550
1576
);
1551
1577
},
1552
-
getItems(keys) {
1553
-
return [...keys].map(key=> {
1554
-
let item =list.getItem(key);
1578
+
getItems(keys, items) {
1579
+
returnitems.map(item=> {
1555
1580
return {
1556
1581
'text/plain': item.name,
1557
1582
'custom-app-type': JSON.stringify(item)
@@ -1585,6 +1610,13 @@ function Example() {
1585
1610
The drag source can also control which drop operations are allowed for the data. For example, if moving data is not allowed, and only copying is supported, the `getAllowedDropOperations` function could be implemented to indicate this. When you drag the element below, the cursor now shows the copy affordance by default, and pressing a modifier to switch drop operations results in the drop being canceled.
1586
1611
1587
1612
```tsx example
1613
+
///- begin collapse -///
1614
+
interfaceItem {
1615
+
id:number,
1616
+
name:string
1617
+
}
1618
+
///- end collapse -///
1619
+
1588
1620
function Example() {
1589
1621
///- begin collapse -///
1590
1622
let list =useListData({
@@ -1599,7 +1631,7 @@ function Example() {
1599
1631
///- end collapse -///
1600
1632
// ...
1601
1633
1602
-
let { dragAndDropHooks } =useDragAndDrop({
1634
+
let { dragAndDropHooks } =useDragAndDrop<Item>({
1603
1635
///- begin collapse -///
1604
1636
renderDragPreview(items) {
1605
1637
return (
@@ -1609,9 +1641,8 @@ function Example() {
1609
1641
</div>
1610
1642
);
1611
1643
},
1612
-
getItems(keys) {
1613
-
return [...keys].map(key=> {
1614
-
let item =list.getItem(key);
1644
+
getItems(keys, items) {
1645
+
returnitems.map(item=> {
1615
1646
return {
1616
1647
'text/plain': item.name,
1617
1648
'custom-app-type': JSON.stringify(item)
@@ -1737,7 +1768,7 @@ function DndGridList(props: DndGridListProps) {
1737
1768
initialItems: props.initialItems
1738
1769
});
1739
1770
1740
-
let { dragAndDropHooks } =useDragAndDrop({
1771
+
let { dragAndDropHooks } =useDragAndDrop<FileItem>({
1741
1772
///- begin collapse -///
1742
1773
renderDragPreview(items) {
1743
1774
return (
@@ -1749,9 +1780,8 @@ function DndGridList(props: DndGridListProps) {
1749
1780
},
1750
1781
///- end collapse -///
1751
1782
// Provide drag data in a custom format as well as plain text.
0 commit comments