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

Commit e25143b

Browse files
committed
Merge branch 'navbar-css'
2 parents 3bcf7e7 + 5710375 commit e25143b

File tree

4 files changed

+106
-45
lines changed

4 files changed

+106
-45
lines changed

src/components/NavBar.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import MenuItem from "@mui/material/MenuItem";
1111
import Toolbar from "@mui/material/Toolbar";
1212
import { c } from "helpers/StylesHelper";
1313
import MenuIcon from "components/img/MenuIcon";
14+
import Typography from "@mui/material/Typography";
1415

1516
export function NavBar(navBarProps: NavBarProps) {
1617
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
@@ -72,6 +73,14 @@ export function NavBar(navBarProps: NavBarProps) {
7273
<MenuIcon />
7374
</IconButton>
7475
{renderMenu}
76+
<Typography
77+
variant="h6"
78+
noWrap
79+
component="div"
80+
sx={{ display: { xs: "none", sm: "block" } }}
81+
>
82+
{navBarProps.csvButtonProps.name}
83+
</Typography>
7584
{/** Global filter */}
7685
<GlobalFilter {...navBarProps.globalFilterRows} />
7786
</Toolbar>
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+
}
Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
import React from "react";
22
import "regenerator-runtime/runtime";
33
import { GlobalFilterProps } from "cdm/MenuBarModel";
4-
5-
// A debounced input react component
6-
function DebouncedInput({
7-
value: initialValue,
8-
onChange,
9-
debounce = 500,
10-
...props
11-
}: {
12-
value: string | number;
13-
onChange: (value: string | number) => void;
14-
debounce?: number;
15-
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">) {
16-
const [value, setValue] = React.useState(initialValue);
17-
18-
React.useEffect(() => {
19-
setValue(initialValue);
20-
}, [initialValue]);
21-
22-
React.useEffect(() => {
23-
const timeout = setTimeout(() => {
24-
onChange(value);
25-
}, debounce);
26-
27-
return () => clearTimeout(timeout);
28-
}, [value]);
29-
30-
return (
31-
<input
32-
{...props}
33-
value={value}
34-
onChange={(e) => setValue(e.target.value)}
35-
/>
36-
);
37-
}
4+
import {
5+
DebouncedInputWrapper,
6+
Search,
7+
SearchIconWrapper,
8+
} from "components/styles/NavBarSearchStyles";
9+
import SearchIcon from "@mui/icons-material/Search";
10+
import DebouncedInput from "components/behavior/DebouncedInputFn";
3811

3912
/**
4013
* Filter component based on react-table.
@@ -43,19 +16,20 @@ function DebouncedInput({
4316
* @returns
4417
*/
4518
export default function GlobalFilter(globalFilterProps: GlobalFilterProps) {
46-
// TODO add typing to props
4719
const { hits, globalFilter, setGlobalFilter } = globalFilterProps;
48-
const [value, setValue] = React.useState(globalFilter);
4920

5021
return (
51-
<span>
52-
Search:{" "}
53-
<DebouncedInput
54-
value={globalFilter ?? ""}
55-
onChange={(value) => setGlobalFilter(String(value))}
56-
className="p-2 font-lg shadow border border-block"
57-
placeholder={`Search... (${hits})`}
58-
/>
59-
</span>
22+
<Search>
23+
<SearchIconWrapper>
24+
<SearchIcon />
25+
</SearchIconWrapper>
26+
<DebouncedInputWrapper>
27+
<DebouncedInput
28+
value={globalFilter ?? ""}
29+
onChange={(value) => setGlobalFilter(String(value))}
30+
placeholder={`Search... (${hits})`}
31+
/>
32+
</DebouncedInputWrapper>
33+
</Search>
6034
);
6135
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { alpha, styled } from "@mui/material/styles";
2+
3+
export const Search = styled('div')(({ theme }) => ({
4+
position: 'relative',
5+
borderRadius: theme.shape.borderRadius,
6+
backgroundColor: alpha(theme.palette.common.white, 0.15),
7+
'&:hover': {
8+
backgroundColor: alpha(theme.palette.common.white, 0.25),
9+
},
10+
marginRight: theme.spacing(2),
11+
marginLeft: 0,
12+
width: '100%',
13+
[theme.breakpoints.up('sm')]: {
14+
marginLeft: theme.spacing(3),
15+
width: 'auto',
16+
},
17+
}));
18+
19+
export const SearchIconWrapper = styled('div')(({ theme }) => ({
20+
padding: theme.spacing(0, 2),
21+
height: '100%',
22+
position: 'absolute',
23+
pointerEvents: 'none',
24+
display: 'flex',
25+
alignItems: 'center',
26+
justifyContent: 'center',
27+
}));
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)