@@ -425,16 +425,153 @@ function EmptyTableExample({ locale, language, ghostGrid, compactMode }: { local
425425 ) ;
426426}
427427
428- const TABS = [
428+ // ---------------------------------------------------------------------------
429+ // Example 7: Height modes comparison
430+ // ---------------------------------------------------------------------------
431+
432+ const HEIGHT_COLUMNS = [
433+ { id : 'Organization' } ,
434+ { id : 'Slug' } ,
435+ { id : 'Status' , type : 'SingleSelect' as const , options : { options : [
436+ { value : 'Synced' , label : 'Synced' , color : '#dcfce7' } ,
437+ { value : 'Pending' , label : 'Pending' , color : '#fef3c7' } ,
438+ { value : 'Error' , label : 'Error' , color : '#fecaca' } ,
439+ ] } } ,
440+ { id : 'Filter' } ,
441+ { id : 'Link' , type : 'URL' as const } ,
442+ ] ;
443+
444+ const HEIGHT_ROWS_3 = [
445+ { Organization : 'test' , Slug : 'test' , Status : 'Synced' , Filter : "filter(org_slug == 'test')" , Link : '/test/db/news-articles' } ,
446+ { Organization : 'testorg' , Slug : 'testorg' , Status : 'Synced' , Filter : "filter(org_slug == 'testorg')" , Link : '/testorg/db/news-articles' } ,
447+ { Organization : 'acme' , Slug : 'acme' , Status : 'Pending' , Filter : "filter(org_slug == 'acme')" , Link : '/acme/db/news-articles' } ,
448+ ] ;
449+
450+ const HEIGHT_ROWS_1 = [ HEIGHT_ROWS_3 [ 0 ] ] ;
451+
452+ type HeightMode = 'auto' | 'auto-capped' | 'fixed-400' | 'fixed-400-no-ghost' | 'fill' ;
453+
454+ const HEIGHT_MODES : { id : HeightMode ; label : string ; code : string } [ ] = [
455+ { id : 'auto' , label : 'auto' , code : 'height="auto"' } ,
456+ { id : 'auto-capped' , label : 'auto + maxHeight' , code : 'height="auto" maxHeight={300}' } ,
457+ { id : 'fixed-400' , label : '400px (ghost on)' , code : 'height={400}' } ,
458+ { id : 'fixed-400-no-ghost' , label : '400px (ghost off)' , code : 'height={400} ghostGrid={false}' } ,
459+ { id : 'fill' , label : '100% (fill parent)' , code : 'height="100%"' } ,
460+ ] ;
461+
462+ function HeightModeTable ( { rows, mode, locale, language, compactMode } : {
463+ rows : Array < Record < string , Value > > ;
464+ mode : HeightMode ;
465+ locale : string ;
466+ language : string ;
467+ compactMode : boolean ;
468+ } ) {
469+ const heightProps = ( ( ) => {
470+ switch ( mode ) {
471+ case 'auto' : return { height : 'auto' as const } ;
472+ case 'auto-capped' : return { height : 'auto' as const , maxHeight : 300 } ;
473+ case 'fixed-400' : return { height : 400 } ;
474+ case 'fixed-400-no-ghost' : return { height : 400 , ghostGrid : false as const } ;
475+ case 'fill' : return { height : '100%' } ;
476+ }
477+ } ) ( ) ;
478+
479+ const needsContainer = mode === 'fill' ;
480+
481+ const table = (
482+ < MonkeyTable
483+ columns = { HEIGHT_COLUMNS }
484+ rows = { rows }
485+ editable = { false }
486+ showToolbar = { false }
487+ compactMode = { compactMode }
488+ locale = { locale }
489+ language = { language }
490+ { ...heightProps }
491+ />
492+ ) ;
493+
494+ if ( needsContainer ) {
495+ return < div style = { { height : '300px' , border : '1px dashed #d1d5db' , borderRadius : '6px' } } > { table } </ div > ;
496+ }
497+ return table ;
498+ }
499+
500+ function HeightModesExample ( { locale, language, compactMode } : { locale : string ; language : string ; compactMode : boolean } ) {
501+ const [ mode , setMode ] = useState < HeightMode > ( 'auto' ) ;
502+
503+ const currentMode = HEIGHT_MODES . find ( ( m ) => m . id === mode ) ! ;
504+
505+ return (
506+ < div className = "example" >
507+ < h2 > Height Modes</ h2 >
508+ < div className = "desc" style = { { display : 'flex' , alignItems : 'center' , gap : '12px' , flexWrap : 'wrap' , marginBottom : '12px' } } >
509+ < span > Compare how different < code > height</ code > modes handle 0, 1, and 3 rows.</ span >
510+ < div style = { { display : 'flex' , gap : '4px' } } >
511+ { HEIGHT_MODES . map ( ( m ) => (
512+ < button
513+ key = { m . id }
514+ onClick = { ( ) => setMode ( m . id ) }
515+ style = { {
516+ padding : '3px 10px' ,
517+ fontSize : '12px' ,
518+ fontWeight : mode === m . id ? 600 : 400 ,
519+ borderRadius : '4px' ,
520+ border : '1px solid' ,
521+ borderColor : mode === m . id ? '#111827' : '#d1d5db' ,
522+ background : mode === m . id ? '#111827' : 'white' ,
523+ color : mode === m . id ? 'white' : '#374151' ,
524+ cursor : 'pointer' ,
525+ } }
526+ >
527+ { m . label }
528+ </ button >
529+ ) ) }
530+ </ div >
531+ </ div >
532+ < div style = { { marginBottom : '16px' , padding : '6px 12px' , background : '#f9fafb' , borderRadius : '4px' , fontFamily : 'monospace' , fontSize : '13px' , color : '#6b7280' } } >
533+ { '<MonkeyTable ' } { currentMode . code } { ' />' }
534+ { mode === 'fill' && < span style = { { color : '#9ca3af' } } > (inside a 300px container)</ span > }
535+ </ div >
536+
537+ < div style = { { display : 'flex' , flexDirection : 'column' , gap : '24px' } } >
538+ { ( [
539+ { label : '0 rows (empty)' , rows : [ ] as Array < Record < string , Value > > } ,
540+ { label : '1 row' , rows : HEIGHT_ROWS_1 } ,
541+ { label : '3 rows' , rows : HEIGHT_ROWS_3 } ,
542+ ] ) . map ( ( scenario ) => (
543+ < div key = { scenario . label } >
544+ < div style = { { fontSize : '13px' , fontWeight : 600 , color : '#374151' , marginBottom : '6px' } } >
545+ { scenario . label }
546+ </ div >
547+ < div style = { { border : '1px solid #e5e7eb' , borderRadius : '6px' , overflow : 'hidden' } } >
548+ < HeightModeTable
549+ rows = { scenario . rows }
550+ mode = { mode }
551+ locale = { locale }
552+ language = { language }
553+ compactMode = { compactMode }
554+ />
555+ </ div >
556+ </ div >
557+ ) ) }
558+ </ div >
559+ </ div >
560+ ) ;
561+ }
562+
563+
564+ const TABS : Array < { id : string ; label : string ; private ?: boolean } > = [
429565 { id : 'editable' , label : 'Editable' } ,
566+ { id : 'height' , label : 'Height Modes' } ,
430567 { id : 'columns' , label : 'Column Options' } ,
431568 { id : 'empty' , label : 'Empty Table' } ,
432569 { id : 'readonly' , label : 'Read-Only' } ,
433570 { id : 'large' , label : 'Large Dataset' } ,
434571 { id : 'pagination' , label : 'Pagination' } ,
435- ] as const ;
572+ ] ;
436573
437- type TabId = typeof TABS [ number ] [ 'id' ] ;
574+ type TabId = string ;
438575
439576function App ( ) {
440577 const [ tab , setTab ] = useState < TabId > ( 'editable' ) ;
@@ -467,7 +604,7 @@ function App() {
467604 { TABS . map ( ( t ) => (
468605 < button
469606 key = { t . id }
470- className = { `tab ${ tab === t . id ? 'tab-active' : '' } ` }
607+ className = { `tab ${ tab === t . id ? 'tab-active' : '' } ${ t . private ? ' tab-private' : '' } ` }
471608 onClick = { ( ) => setTab ( t . id ) }
472609 >
473610 { t . label }
@@ -550,6 +687,10 @@ function App() {
550687 </ div >
551688 ) }
552689
690+ { tab === 'height' && (
691+ < HeightModesExample locale = { locale } language = { language } compactMode = { compactMode } />
692+ ) }
693+
553694 { tab === 'columns' && (
554695 < div className = "example" style = { { display : 'flex' , flexDirection : 'column' , minHeight : 'calc(100vh - 200px)' } } >
555696 < h2 > Column Options</ h2 >
@@ -602,6 +743,7 @@ function App() {
602743 { tab === 'pagination' && (
603744 < PaginationExample locale = { locale } language = { language } />
604745 ) }
746+
605747 </ div >
606748 </ div >
607749 ) ;
0 commit comments