@@ -22,6 +22,7 @@ const head = shallowRef<HTMLElement | null>(null)
2222const body = shallowRef <HTMLElement | null >(null )
2323const block = shallowRef <HTMLElement | null >(null )
2424const row = shallowRef <HTMLElement | null >(null )
25+ const table = shallowRef <HTMLElement | null >(null )
2526
2627const ordersToShow = smartComputed (() => {
2728 const orders = unref (props .options .orders ).filter ((key ) => {
@@ -61,6 +62,12 @@ const cellOfColToGrow = computed(() => {
6162const colWidths = reactive <Record <string , string >>({})
6263const blockWidth = ref <number | undefined >()
6364
65+ const resizeState = ref <{
66+ columnName: string
67+ startX: number
68+ indicatorX: number
69+ } | null >(null )
70+
6471watch (() => unref (props .options .columns ), (columns ) => {
6572 Object .keys (columns ).forEach ((key ) => {
6673 const width = columns [key ]?.width
@@ -386,6 +393,29 @@ function getStyles(key: string) {
386393 ' --table-col-left' : widthSum ? ` calc(${widthSum }) ` : ' 0px'
387394 }
388395}
396+
397+ function handleResizeStart(data : { columnName: string ; startX: number ; initialX: number }) {
398+ const tableRect = table .value ?.getBoundingClientRect ()
399+ const tableLeft = tableRect ?.left ?? 0
400+ const indicatorX = data .initialX - tableLeft
401+
402+ resizeState .value = {
403+ columnName: data .columnName ,
404+ startX: indicatorX ,
405+ indicatorX
406+ }
407+ }
408+
409+ function handleResizeMove(data : { deltaX: number }) {
410+ if (resizeState .value ) {
411+ resizeState .value .indicatorX = resizeState .value .startX + data .deltaX
412+ }
413+ }
414+
415+ function handleResizeEnd(data : { columnName: string ; finalWidth: string }) {
416+ updateColWidth (data .columnName , data .finalWidth , true )
417+ resizeState .value = null
418+ }
389419 </script >
390420
391421<template >
@@ -401,7 +431,13 @@ function getStyles(key: string) {
401431 :selected =" Array.isArray(selected) ? selected : undefined"
402432 />
403433
404- <div class =" table" role =" grid" >
434+ <div ref =" table" class =" table" role =" grid" >
435+ <div
436+ v-if =" resizeState"
437+ class =" resize-indicator"
438+ :style =" { left: `${resizeState.indicatorX}px` }"
439+ />
440+
405441 <div ref =" head" class =" container head" @scroll =" syncHeadScroll" >
406442 <div ref =" block" class =" block" >
407443 <div ref =" row" class =" row" >
@@ -420,7 +456,9 @@ function getStyles(key: string) {
420456 :dropdown =" unref(options.columns)[key]?.dropdown"
421457 :has-header =" showHeader"
422458 :resizable =" unref(options.columns)[key]?.resizable"
423- @resize =" (value) => updateColWidth(key, value, true)"
459+ @resize-start =" handleResizeStart"
460+ @resize-move =" handleResizeMove"
461+ @resize-end =" handleResizeEnd"
424462 >
425463 <SInputCheckbox
426464 v-if ="
@@ -636,6 +674,16 @@ function getStyles(key: string) {
636674 color : var (--c-text-1 );
637675}
638676
677+ .resize-indicator {
678+ position : absolute;
679+ top : 0 ;
680+ bottom : 0 ;
681+ width : 1 px ;
682+ background-color : var (--c-border-info-1 );
683+ z-index : 200 ;
684+ pointer-events : none;
685+ }
686+
639687.STable .col-__select {
640688 --table-col-width : calc (48 px + var (--table-padding-left ));
641689
0 commit comments