Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 5710375

Browse files
committed
css of navbar improved
1 parent 9caa3d0 commit 5710375

File tree

3 files changed

+60
-55
lines changed

3 files changed

+60
-55
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import InputBase from "@mui/material/InputBase";
2+
import React from "react";
3+
4+
// A debounced input react component
5+
export default function DebouncedInput({
6+
value: initialValue,
7+
onChange,
8+
debounce = 500,
9+
placeholder,
10+
}: {
11+
value: string | number;
12+
onChange: (value: string | number) => void;
13+
debounce?: number;
14+
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">) {
15+
const [value, setValue] = React.useState(initialValue);
16+
17+
React.useEffect(() => {
18+
setValue(initialValue);
19+
}, [initialValue]);
20+
21+
React.useEffect(() => {
22+
const timeout = setTimeout(() => {
23+
onChange(value);
24+
}, debounce);
25+
26+
return () => clearTimeout(timeout);
27+
}, [value]);
28+
29+
return (
30+
<InputBase
31+
value={value}
32+
onChange={(e) => setValue(e.target.value)}
33+
placeholder={placeholder}
34+
style={{}}
35+
/>
36+
);
37+
}

src/components/reducers/GlobalFilter.tsx

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,12 @@ import React from "react";
22
import "regenerator-runtime/runtime";
33
import { GlobalFilterProps } from "cdm/MenuBarModel";
44
import {
5+
DebouncedInputWrapper,
56
Search,
67
SearchIconWrapper,
78
} from "components/styles/NavBarSearchStyles";
89
import 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({
5218
export 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
}

src/components/styles/NavBarSearchStyles.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import InputBase from "@mui/material/InputBase";
21
import { alpha, styled } from "@mui/material/styles";
32

43
export const Search = styled('div')(({ theme }) => ({
@@ -26,3 +25,17 @@ export const SearchIconWrapper = styled('div')(({ theme }) => ({
2625
alignItems: 'center',
2726
justifyContent: 'center',
2827
}));
28+
29+
export const DebouncedInputWrapper = styled('div')(({ theme }) => ({
30+
color: "inherit",
31+
"& div *": {
32+
padding: theme.spacing(1, 1, 1, 0),
33+
// vertical padding + font size from searchIcon
34+
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
35+
transition: theme.transitions.create("width"),
36+
width: "100%",
37+
[theme.breakpoints.up("md")]: {
38+
width: "20ch",
39+
},
40+
},
41+
}));

0 commit comments

Comments
 (0)