11'use client' ;
22
3- import { ListView , Item , Text , useListData , useDragAndDrop } from '@adobe/react-spectrum' ;
4- import { style } from '@react-spectrum/s2/style' ;
5- import File from '@spectrum-icons/illustrations/File' ;
6- import Folder from '@spectrum-icons/illustrations/Folder' ;
3+ import { GridList , GridListItem } from 'vanilla-starter/GridList' ;
4+ import { useDragAndDrop , isTextDropItem } from 'react-aria-components' ;
5+ import { useListData } from 'react-stately' ;
6+ import File from '@react-spectrum/s2/icons/File' ;
7+ import Folder from '@react-spectrum/s2/icons/Folder' ;
78import React from 'react' ;
89
9- function BidirectionalDnDListView ( props ) {
10+ function BidirectionalDnDGridList ( props ) {
1011 let { list} = props ;
1112 let { dragAndDropHooks} = useDragAndDrop ( {
1213 acceptedDragTypes : [ 'custom-app-type-bidirectional' ] ,
@@ -28,15 +29,17 @@ function BidirectionalDnDListView(props) {
2829 target
2930 } = e ;
3031 let processedItems = await Promise . all (
31- items . map ( async item => JSON . parse ( await item . getText ( 'custom-app-type-bidirectional' ) ) )
32+ items
33+ . filter ( isTextDropItem )
34+ . map ( async item => JSON . parse ( await item . getText ( 'custom-app-type-bidirectional' ) ) )
3235 ) ;
3336 if ( target . dropPosition === 'before' ) {
3437 list . insertBefore ( target . key , ...processedItems ) ;
3538 } else if ( target . dropPosition === 'after' ) {
3639 list . insertAfter ( target . key , ...processedItems ) ;
3740 }
3841 } ,
39- onReorder : async ( e ) => {
42+ onReorder : ( e ) => {
4043 let {
4144 keys,
4245 target
@@ -53,7 +56,9 @@ function BidirectionalDnDListView(props) {
5356 items
5457 } = e ;
5558 let processedItems = await Promise . all (
56- items . map ( async item => JSON . parse ( await item . getText ( 'custom-app-type-bidirectional' ) ) )
59+ items
60+ . filter ( isTextDropItem )
61+ . map ( async item => JSON . parse ( await item . getText ( 'custom-app-type-bidirectional' ) ) )
5762 ) ;
5863 list . append ( ...processedItems ) ;
5964 } ,
@@ -73,20 +78,20 @@ function BidirectionalDnDListView(props) {
7378 } ) ;
7479
7580 return (
76- < ListView
81+ < GridList
7782 aria-label = { props [ 'aria-label' ] }
7883 selectionMode = "multiple"
79- width = "size-3600"
80- height = "size-3600"
84+ layout = "list"
8185 items = { list . items }
82- dragAndDropHooks = { dragAndDropHooks } >
86+ dragAndDropHooks = { dragAndDropHooks }
87+ style = { { width : 300 , height : 300 } } >
8388 { item => (
84- < Item textValue = { item . name } >
89+ < GridListItem textValue = { item . name } >
8590 { item . type === 'folder' ? < Folder /> : < File /> }
86- < Text > { item . name } </ Text >
87- </ Item >
91+ < span > { item . name } </ span >
92+ </ GridListItem >
8893 ) }
89- </ ListView >
94+ </ GridList >
9095 ) ;
9196}
9297
@@ -115,9 +120,9 @@ export default function DragBetweenListsExample() {
115120
116121
117122 return (
118- < div className = { style ( { display : 'flex' , flexWrap : 'wrap' , gap : 8 } ) } >
119- < BidirectionalDnDListView list = { list1 } aria-label = "First ListView in drag between list example" />
120- < BidirectionalDnDListView list = { list2 } aria-label = "Second ListView in drag between list example" />
123+ < div style = { { display : 'flex' , justifyContent : 'center' , flexWrap : 'wrap' , gap : 8 } } >
124+ < BidirectionalDnDGridList list = { list1 } aria-label = "First GridList in drag between list example" />
125+ < BidirectionalDnDGridList list = { list2 } aria-label = "Second GridList in drag between list example" />
121126 </ div >
122127 ) ;
123128}
0 commit comments