1- import { Button , SearchInput } from "@sumup-oss/circuit-ui" ;
2- import { useEffect , useMemo , useRef , useState } from "react" ;
1+ import { SearchInput } from "@sumup-oss/circuit-ui" ;
2+ import { useMemo , useRef , useState } from "react" ;
33
44import styles from "./SearchableTable.module.css" ;
55import Table , { type TableColumn } from "./Table" ;
@@ -10,20 +10,16 @@ type Props = {
1010 columns : SearchableTableColumn [ ] ;
1111 rows : Record < string , unknown > [ ] ;
1212 searchPlaceholder ?: string ;
13- maxHeight ?: number ;
1413 tableLayout ?: "fixed" | "auto" ;
1514} ;
1615
1716const SearchableTable = ( {
1817 columns,
1918 rows,
2019 searchPlaceholder = "Search" ,
21- maxHeight = 420 ,
2220 tableLayout = "fixed" ,
2321} : Props ) => {
2422 const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
25- const [ isExpanded , setIsExpanded ] = useState ( false ) ;
26- const [ canExpand , setCanExpand ] = useState ( false ) ;
2723 const wrapperRef = useRef < HTMLDivElement > ( null ) ;
2824
2925 const normalizedQuery = searchQuery . trim ( ) . toLowerCase ( ) ;
@@ -47,19 +43,6 @@ const SearchableTable = ({
4743 ) ;
4844 } , [ columns , normalizedQuery , rows ] ) ;
4945
50- useEffect ( ( ) => {
51- const container = wrapperRef . current ;
52- if ( ! container ) {
53- return ;
54- }
55-
56- setCanExpand ( container . scrollHeight > maxHeight ) ;
57- } , [ filteredRows , maxHeight ] ) ;
58-
59- useEffect ( ( ) => {
60- setIsExpanded ( false ) ;
61- } , [ searchQuery ] ) ;
62-
6346 return (
6447 < section className = { `${ styles . section } not-content` } >
6548 < SearchInput
@@ -75,20 +58,8 @@ const SearchableTable = ({
7558 rows = { filteredRows }
7659 tableLayout = { tableLayout }
7760 containerRef = { wrapperRef }
78- maxHeight = { isExpanded ? undefined : ` ${ maxHeight } px` }
61+ maxHeight = "420px"
7962 />
80-
81- { canExpand ? (
82- < Button
83- type = "button"
84- variant = "tertiary"
85- size = "s"
86- onClick = { ( ) => setIsExpanded ( ( value ) => ! value ) }
87- className = { styles . button }
88- >
89- { isExpanded ? "Collapse" : "Expand to view all" }
90- </ Button >
91- ) : null }
9263 </ section >
9364 ) ;
9465} ;
0 commit comments