@@ -6,7 +6,7 @@ dayjs.extend(weekOfYear)
6
6
dayjs . extend ( weekYear )
7
7
dayjs . extend ( localeData )
8
8
import type React from "react"
9
- import { Fragment , type RefObject , useRef } from "react"
9
+ import { Fragment , type RefObject , useCallback , useRef , useState } from "react"
10
10
11
11
// if more locales then english and germans are needed, we need to enable them first here
12
12
import "dayjs/locale/de"
@@ -22,6 +22,7 @@ import type {
22
22
TimeTableViewType ,
23
23
} from "./TimeTable"
24
24
import type { TimeFrameDay } from "./TimeTableConfigStore"
25
+ import useResizeObserver , { type ObservedSize } from "use-resize-observer"
25
26
26
27
const headerTimeSlotFormat : { [ viewType in TimeTableViewType ] : string } = {
27
28
hours : "HH:mm" ,
@@ -69,6 +70,7 @@ export type CustomHeaderRowTimeSlotProps<
69
70
entries : TimeTableEntry < G , I > [ ]
70
71
slotsArray : readonly Dayjs [ ]
71
72
tableCellRef : RefObject < HTMLTableCellElement >
73
+ tableCellWidth : number
72
74
}
73
75
74
76
export type CustomHeaderRowHeaderProps <
@@ -358,7 +360,22 @@ function CustomHeaderRowCell<
358
360
header : ( props : CustomHeaderRowHeaderProps < G , I > ) => JSX . Element
359
361
}
360
362
} ) {
361
- const ref = useRef < HTMLTableCellElement > ( null )
363
+ // this is the same as in the TableCell component
364
+ const tableCellRef = useRef < HTMLTableCellElement > ( null )
365
+ const [ tableCellWidth , setTableCellWidth ] = useState (
366
+ tableCellRef . current ?. offsetWidth ?? 70 ,
367
+ )
368
+
369
+ const resizeCallback = useCallback ( ( observedSize : ObservedSize ) => {
370
+ setTableCellWidth ( observedSize . width ?? 70 )
371
+ } , [ ] )
372
+ useResizeObserver ( {
373
+ ref : tableCellRef ,
374
+ onResize : resizeCallback ,
375
+ box : "border-box" ,
376
+ round : ( n : number ) => n , // we don't need rounding here
377
+ } )
378
+ //
362
379
363
380
return (
364
381
< th
@@ -367,7 +384,7 @@ function CustomHeaderRowCell<
367
384
className = { `${ headerCellBaseClassname } ${
368
385
isLastOfDay ? "after:border-l-2" : "after:border-l"
369
386
} `}
370
- ref = { ref }
387
+ ref = { tableCellRef }
371
388
>
372
389
{ customHeaderRow . timeSlot ( {
373
390
timeSlot,
@@ -377,7 +394,8 @@ function CustomHeaderRowCell<
377
394
viewType,
378
395
entries,
379
396
slotsArray,
380
- tableCellRef : ref ,
397
+ tableCellRef,
398
+ tableCellWidth,
381
399
} ) }
382
400
</ th >
383
401
)
0 commit comments