11import { ContextProvider } from '@lit/context' ;
22import { LitElement , html } from 'lit' ;
3- import { property , state } from 'lit/decorators.js' ;
3+ import { property , query , state } from 'lit/decorators.js' ;
44import { styleMap } from 'lit/directives/style-map.js' ;
55import { tileContext } from '../common/context.js' ;
66import { registerComponent } from '../common/definitions/register.js' ;
@@ -16,6 +16,7 @@ import IgcResizeComponent from './resize-element.js';
1616import { styles as shared } from './themes/shared/tile/tile.common.css.js' ;
1717import { styles } from './themes/tile.base.css.js' ;
1818import IgcTileHeaderComponent from './tile-header.js' ;
19+ import type IgcTileManagerComponent from './tile-manager.js' ;
1920
2021type IgcTileChangeState = {
2122 tile : IgcTileComponent ;
@@ -60,6 +61,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
6061
6162 private static readonly increment = createCounter ( ) ;
6263 private _dragController : TileDragAndDropController ;
64+ private _tileManager ?: IgcTileManagerComponent ;
6365 private _colSpan = 1 ;
6466 private _rowSpan = 1 ;
6567 private _colStart : number | null = null ;
@@ -83,6 +85,9 @@ export default class IgcTileComponent extends EventEmitterMixin<
8385 initialValue : this ,
8486 } ) ;
8587
88+ @query ( '[part="ghost"]' , true )
89+ public _ghost ! : HTMLElement ;
90+
8691 @state ( )
8792 private _isDragging = false ;
8893
@@ -254,6 +259,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
254259 dragEnd : this . handleDragEnd ,
255260 dragEnter : this . handleDragEnter ,
256261 dragLeave : this . handleDragLeave ,
262+ dragOver : this . handleDragOver ,
257263 drop : this . handleDragLeave ,
258264 } ) ;
259265
@@ -266,6 +272,10 @@ export default class IgcTileComponent extends EventEmitterMixin<
266272 public override connectedCallback ( ) {
267273 super . connectedCallback ( ) ;
268274 this . tileId = this . tileId || `tile-${ IgcTileComponent . increment ( ) } ` ;
275+ // RIVIEW: Should we use lit context instead?
276+ this . _tileManager = this . closest (
277+ 'igc-tile-manager'
278+ ) as IgcTileManagerComponent ;
269279 }
270280
271281 public toggleFullscreen ( ) {
@@ -305,14 +315,6 @@ export default class IgcTileComponent extends EventEmitterMixin<
305315 }
306316 }
307317
308- private handleDragEnter ( ) {
309- this . _hasDragOver = true ;
310- }
311-
312- private handleDragLeave ( ) {
313- this . _hasDragOver = false ;
314- }
315-
316318 private handleDragStart ( e : DragEvent ) {
317319 const event = new CustomEvent ( 'tileDragStart' , {
318320 detail : { tile : this } ,
@@ -330,17 +332,56 @@ export default class IgcTileComponent extends EventEmitterMixin<
330332 this . _isDragging = true ;
331333
332334 requestAnimationFrame ( ( ) => {
333- this . style . transform = 'scale(0 )' ;
335+ this . _ghost . style . transform = 'scale(1 )' ;
334336 } ) ;
335337 }
336338
339+ private handleDragEnter ( ) {
340+ const draggedId = this . _tileManager ?. draggedItem ?. tileId ;
341+ if ( this . _tileManager && this . tileId !== draggedId ) {
342+ const draggedItem = this . _tileManager . draggedItem ;
343+ if ( this . _tileManager ?. dragMode === 'slide' && draggedItem ) {
344+ requestAnimationFrame ( ( ) => {
345+ this . _ghost . style . transform = 'scale(0)' ;
346+ } ) ;
347+ } else {
348+ this . _hasDragOver = true ;
349+ }
350+ }
351+ }
352+
353+ private handleDragOver ( ) {
354+ const draggedId = this . _tileManager ?. draggedItem ?. tileId ;
355+ if (
356+ this . _tileManager &&
357+ this . tileId !== draggedId &&
358+ this . _tileManager ?. dragMode === 'slide'
359+ ) {
360+ const draggedItem = this . _tileManager ?. draggedItem ;
361+ const draggedPosition = draggedItem ? draggedItem . position : - 1 ;
362+ if ( draggedPosition >= 0 ) {
363+ const tempPosition = this . _tileManager ?. tiles [ draggedPosition ] . position ;
364+ this . _tileManager . tiles [ draggedPosition ] . position = this . position ;
365+ this . position = tempPosition ;
366+ }
367+ }
368+ }
369+
370+ private handleDragLeave ( ) {
371+ this . _hasDragOver = false ;
372+ }
373+
337374 private handleDragEnd ( ) {
338375 const event = new CustomEvent ( 'tileDragEnd' , {
339376 detail : { tile : this } ,
340377 bubbles : true ,
341378 } ) ;
342379 this . dispatchEvent ( event ) ;
343380 this . _isDragging = false ;
381+
382+ requestAnimationFrame ( ( ) => {
383+ this . _ghost . style . transform = 'scale(0)' ;
384+ } ) ;
344385 }
345386
346387 private cacheStyles ( ) {
@@ -533,10 +574,17 @@ export default class IgcTileComponent extends EventEmitterMixin<
533574 } ;
534575
535576 return html `
536- < div part =${ parts } .inert =${ this . _hasDragOver } style=${ styleMap ( styles ) } >
537- < slot name ="header "> </ slot >
538- < div part ="content-container ">
539- < slot > </ slot >
577+ < div
578+ part ="tile-container "
579+ .inert =${ this . _hasDragOver }
580+ style =${ styleMap ( styles ) }
581+ >
582+ < div part ="ghost "> </ div >
583+ < div part =${ parts } >
584+ < slot name ="header "> </ slot >
585+ < div part ="content-container ">
586+ < slot > </ slot >
587+ </ div >
540588 </ div >
541589 </ div >
542590 ` ;
0 commit comments