@@ -21,6 +21,7 @@ import { styles as shared } from './themes/shared/tile/tile.common.css.js';
2121import { styles } from './themes/tile.base.css.js' ;
2222import { all } from './themes/tile.js' ;
2323import IgcTileHeaderComponent from './tile-header.js' ;
24+ import { ResizeUtil } from './tile-util.js' ;
2425
2526type IgcTileChangeState = {
2627 tile : IgcTileComponent ;
@@ -101,6 +102,8 @@ export default class IgcTileComponent extends EventEmitterMixin<
101102 background ?: string ;
102103 border ?: string ;
103104 borderRadius ?: string ;
105+ rowHeights ?: number [ ] ;
106+ initialTop ?: number ;
104107 } = { } ;
105108
106109 // Tile manager context properties and helpers
@@ -371,6 +374,12 @@ export default class IgcTileComponent extends EventEmitterMixin<
371374 private cacheStyles ( ) {
372375 //use util
373376 const computedStyle = getComputedStyle ( this ) ;
377+ const parentWrapper =
378+ this . parentElement ! . shadowRoot ! . querySelector ( '[part="base"]' ) ! ;
379+
380+ const rowHeights = getComputedStyle ( parentWrapper )
381+ . gridTemplateRows . split ( ' ' )
382+ . map ( ( height ) => Number . parseFloat ( height . trim ( ) ) ) ;
374383
375384 this . _cachedStyles = {
376385 columnCount : Number . parseFloat (
@@ -385,6 +394,8 @@ export default class IgcTileComponent extends EventEmitterMixin<
385394 minHeight : Number . parseFloat (
386395 computedStyle . getPropertyValue ( '--ig-min-row-height' )
387396 ) ,
397+ rowHeights,
398+ initialTop : parentWrapper . getBoundingClientRect ( ) . top ,
388399 } ;
389400 }
390401
@@ -403,6 +414,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
403414 this . _isResizing = true ;
404415
405416 const ghostElement = event . detail . state . current ;
417+ const rowHeights = this . _cachedStyles . rowHeights ! ;
406418
407419 if ( ghostElement ) {
408420 const deltaX = event . detail . event . clientX - this . _initialPointerX ! ;
@@ -414,10 +426,20 @@ export default class IgcTileComponent extends EventEmitterMixin<
414426 event . detail . state . initial . width ,
415427 columnGap
416428 ) ;
417- const snappedHeight = this . _calculateSnappedHeight (
429+
430+ const actualTop = this . _cachedStyles . initialTop ! + window . scrollY ;
431+ const initialTop = event . detail . state . initial . top + window . scrollY ;
432+ const actualBottom = event . detail . state . initial . bottom + window . scrollY ;
433+
434+ const startingY = actualBottom - actualTop ;
435+
436+ const snappedHeight = ResizeUtil . calculateSnappedHeight (
418437 deltaY ,
419- event . detail . state . initial . height ,
420- columnGap
438+ startingY ,
439+ rowHeights ,
440+ columnGap ,
441+ initialTop ,
442+ event . detail . state . initial . height
421443 ) ;
422444
423445 ghostElement . width = snappedWidth ;
@@ -446,33 +468,6 @@ export default class IgcTileComponent extends EventEmitterMixin<
446468 return snappedWidth < colWidth ? colWidth : snappedWidth ;
447469 }
448470
449- private _calculateSnappedHeight (
450- deltaY : number ,
451- initialHeight : number ,
452- rowGap : number
453- ) : number {
454- const minHeight = this . _cachedStyles . minHeight ! ;
455- let snappedHeight = initialHeight ;
456-
457- if ( deltaY > 0 ) {
458- // For resizing down, add the gaps and the rows multiplied by min height to the initial tile height
459- const additionalHeight = initialHeight + deltaY ;
460- const wholeRows = Math . floor ( additionalHeight / ( minHeight + rowGap ) ) ;
461- const totalHeight = wholeRows * ( minHeight + rowGap ) - rowGap ;
462-
463- snappedHeight = Math . max ( totalHeight , minHeight ) ; // Ensure it at least snaps to minHeight
464- } else if ( deltaY < 0 && initialHeight > minHeight ) {
465- // For resizing up, subtract the gaps and the rows multiplied by min height from the initial tile height
466- const reducedHeight = initialHeight + deltaY ;
467- const wholeRows = Math . floor ( reducedHeight / ( minHeight + rowGap ) ) ;
468- const totalHeight = wholeRows * ( minHeight + rowGap ) - rowGap ;
469-
470- snappedHeight = Math . max ( totalHeight , minHeight ) ;
471- }
472-
473- return snappedHeight ;
474- }
475-
476471 private _handleResizeEnd ( event : CustomEvent < ResizeCallbackParams > ) {
477472 const state = event . detail . state ;
478473 const width = state . current . width ; // - state.current.x;
0 commit comments