@@ -2,46 +2,12 @@ import React from "react";
22import "regenerator-runtime/runtime" ;
33import { GlobalFilterProps } from "cdm/MenuBarModel" ;
44import {
5+ DebouncedInputWrapper ,
56 Search ,
67 SearchIconWrapper ,
78} from "components/styles/NavBarSearchStyles" ;
89import SearchIcon from "@mui/icons-material/Search" ;
9- import { styled } from "@mui/material/styles" ;
10- import InputBase from "@mui/material/InputBase" ;
11-
12- // A debounced input react component
13- function DebouncedInput ( {
14- value : initialValue ,
15- onChange,
16- debounce = 500 ,
17- placeholder,
18- } : {
19- value : string | number ;
20- onChange : ( value : string | number ) => void ;
21- debounce ?: number ;
22- } & Omit < React . InputHTMLAttributes < HTMLInputElement > , "onChange" > ) {
23- const [ value , setValue ] = React . useState ( initialValue ) ;
24-
25- React . useEffect ( ( ) => {
26- setValue ( initialValue ) ;
27- } , [ initialValue ] ) ;
28-
29- React . useEffect ( ( ) => {
30- const timeout = setTimeout ( ( ) => {
31- onChange ( value ) ;
32- } , debounce ) ;
33-
34- return ( ) => clearTimeout ( timeout ) ;
35- } , [ value ] ) ;
36-
37- return (
38- < InputBase
39- value = { value }
40- onChange = { ( e ) => setValue ( e . target . value ) }
41- placeholder = { placeholder }
42- />
43- ) ;
44- }
10+ import DebouncedInput from "components/behavior/DebouncedInputFn" ;
4511
4612/**
4713 * Filter component based on react-table.
@@ -52,29 +18,18 @@ function DebouncedInput({
5218export default function GlobalFilter ( globalFilterProps : GlobalFilterProps ) {
5319 const { hits, globalFilter, setGlobalFilter } = globalFilterProps ;
5420
55- const CustomDebouncedInput = styled ( DebouncedInput ) ( ( { theme } ) => ( {
56- color : "inherit" ,
57- "& .MuiInputBase-input" : {
58- padding : theme . spacing ( 1 , 1 , 1 , 0 ) ,
59- // vertical padding + font size from searchIcon
60- paddingLeft : `calc(1em + ${ theme . spacing ( 4 ) } )` ,
61- transition : theme . transitions . create ( "width" ) ,
62- width : "100%" ,
63- [ theme . breakpoints . up ( "md" ) ] : {
64- width : "20ch" ,
65- } ,
66- } ,
67- } ) ) ;
6821 return (
6922 < Search >
7023 < SearchIconWrapper >
7124 < SearchIcon />
7225 </ SearchIconWrapper >
73- < CustomDebouncedInput
74- value = { globalFilter ?? "" }
75- onChange = { ( value ) => setGlobalFilter ( String ( value ) ) }
76- placeholder = { `Search... (${ hits } )` }
77- />
26+ < DebouncedInputWrapper >
27+ < DebouncedInput
28+ value = { globalFilter ?? "" }
29+ onChange = { ( value ) => setGlobalFilter ( String ( value ) ) }
30+ placeholder = { `Search... (${ hits } )` }
31+ />
32+ </ DebouncedInputWrapper >
7833 </ Search >
7934 ) ;
8035}
0 commit comments