11'use client'
22
3- import { memo } from 'react'
3+ import { memo , useState , useRef , useEffect } from 'react'
44import _ from 'lodash'
55import CellPopover from '@/components/ui/CellPopover'
66import ImageBlock from '@/components/common/ImageBlock'
@@ -16,6 +16,23 @@ const ImageListCellRenderer = memo(function ImageListCellRenderer({
1616} : ImageListCellRendererProps ) {
1717 const tablePath = useAppSelector ( ( state ) => state . ui . tablePath )
1818 const baseUrl = useAppSelector ( ( state ) => state . ui . baseUrl )
19+ const containerRef = useRef < HTMLDivElement > ( null )
20+ const [ containerWidth , setContainerWidth ] = useState ( 0 )
21+
22+ // Track container width with ResizeObserver
23+ useEffect ( ( ) => {
24+ const element = containerRef . current
25+ if ( ! element ) return
26+
27+ const observer = new ResizeObserver ( ( entries ) => {
28+ for ( const entry of entries ) {
29+ setContainerWidth ( entry . contentRect . width )
30+ }
31+ } )
32+
33+ observer . observe ( element )
34+ return ( ) => observer . disconnect ( )
35+ } , [ ] )
1936
2037 // Filter out empty strings and resolve URLs
2138 const validUrls = _ . compact ( value . map ( url => url . trim ( ) ) )
@@ -25,18 +42,20 @@ const ImageListCellRenderer = memo(function ImageListCellRenderer({
2542
2643 if ( resolvedUrls . length === 0 ) {
2744 return (
28- < div className = "w-full h-full flex items-center justify-center text-muted-foreground text-xs" >
45+ < div ref = { containerRef } className = "w-full h-full flex items-center justify-center text-muted-foreground text-xs" >
2946 No images
3047 </ div >
3148 )
3249 }
3350
34- // Number of images to show in cell preview
35- const previewCount = 5
51+ // Calculate preview count based on container width
52+ // Assume each image needs ~60px minimum width
53+ const imageMinWidth = 80
54+ const previewCount = Math . max ( 2 , Math . min ( resolvedUrls . length , Math . floor ( containerWidth / imageMinWidth ) || 5 ) )
3655
3756 // Cell content: show first few images in a row
3857 const cellContent = (
39- < div className = "flex gap-1 w-full h-full overflow-hidden items-center" >
58+ < div className = "relative flex gap-1 w-full h-full overflow-hidden items-center" >
4059 { resolvedUrls . slice ( 0 , previewCount ) . map ( ( url , index ) => (
4160 < ImageBlock
4261 key = { index }
@@ -47,7 +66,7 @@ const ImageListCellRenderer = memo(function ImageListCellRenderer({
4766 />
4867 ) ) }
4968 { resolvedUrls . length > previewCount && (
50- < span className = "text-xs text-muted-foreground flex-shrink-0 " >
69+ < span className = "absolute bottom-1 right-1 text-xs text-muted-foreground bg-background/80 px-1 rounded " >
5170 +{ resolvedUrls . length - previewCount }
5271 </ span >
5372 ) }
@@ -73,14 +92,16 @@ const ImageListCellRenderer = memo(function ImageListCellRenderer({
7392 )
7493
7594 return (
76- < CellPopover
77- cellContent = { cellContent }
78- popoverContent = { popoverContent }
79- popoverClassName = "w-[600px] h-[500px] p-0"
80- cellContentClassName = "items-center justify-center"
81- copyValue = { validUrls . join ( '\n' ) }
82- title = { `${ resolvedUrls . length } images` }
83- />
95+ < div ref = { containerRef } className = "w-full h-full" >
96+ < CellPopover
97+ cellContent = { cellContent }
98+ popoverContent = { popoverContent }
99+ popoverClassName = "w-[600px] h-[500px] p-0"
100+ cellContentClassName = "items-center justify-center"
101+ copyValue = { validUrls . join ( '\n' ) }
102+ title = { `${ resolvedUrls . length } images` }
103+ />
104+ </ div >
84105 )
85106} )
86107
0 commit comments