11import React from "react" ;
22import "regenerator-runtime/runtime" ;
33import { GlobalFilterProps } from "cdm/MenuBarModel" ;
4+ import {
5+ Search ,
6+ SearchIconWrapper ,
7+ } from "components/styles/NavBarSearchStyles" ;
8+ import SearchIcon from "@mui/icons-material/Search" ;
9+ import { styled } from "@mui/material/styles" ;
10+ import InputBase from "@mui/material/InputBase" ;
411
512// A debounced input react component
613function DebouncedInput ( {
714 value : initialValue ,
815 onChange,
916 debounce = 500 ,
10- ... props
17+ placeholder ,
1118} : {
1219 value : string | number ;
1320 onChange : ( value : string | number ) => void ;
@@ -28,10 +35,10 @@ function DebouncedInput({
2835 } , [ value ] ) ;
2936
3037 return (
31- < input
32- { ...props }
38+ < InputBase
3339 value = { value }
3440 onChange = { ( e ) => setValue ( e . target . value ) }
41+ placeholder = { placeholder }
3542 />
3643 ) ;
3744}
@@ -43,18 +50,31 @@ function DebouncedInput({
4350 * @returns
4451 */
4552export default function GlobalFilter ( globalFilterProps : GlobalFilterProps ) {
46- // TODO add typing to props
4753 const { hits, globalFilter, setGlobalFilter } = globalFilterProps ;
48- const [ value , setValue ] = React . useState ( globalFilter ) ;
4954
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+ } ) ) ;
5068 return (
51- < span >
52- < DebouncedInput
69+ < Search >
70+ < SearchIconWrapper >
71+ < SearchIcon />
72+ </ SearchIconWrapper >
73+ < CustomDebouncedInput
5374 value = { globalFilter ?? "" }
5475 onChange = { ( value ) => setGlobalFilter ( String ( value ) ) }
55- className = "p-2 font-lg shadow border border-block"
5676 placeholder = { `Search... (${ hits } )` }
5777 />
58- </ span >
78+ </ Search >
5979 ) ;
6080}
0 commit comments