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

Commit 9caa3d0

Browse files
committed
MUI customize
1 parent 8e224c6 commit 9caa3d0

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

src/components/reducers/GlobalFilter.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import React from "react";
22
import "regenerator-runtime/runtime";
33
import { 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
613
function 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
*/
4552
export 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
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import InputBase from "@mui/material/InputBase";
2+
import { alpha, styled } from "@mui/material/styles";
3+
4+
export const Search = styled('div')(({ theme }) => ({
5+
position: 'relative',
6+
borderRadius: theme.shape.borderRadius,
7+
backgroundColor: alpha(theme.palette.common.white, 0.15),
8+
'&:hover': {
9+
backgroundColor: alpha(theme.palette.common.white, 0.25),
10+
},
11+
marginRight: theme.spacing(2),
12+
marginLeft: 0,
13+
width: '100%',
14+
[theme.breakpoints.up('sm')]: {
15+
marginLeft: theme.spacing(3),
16+
width: 'auto',
17+
},
18+
}));
19+
20+
export const SearchIconWrapper = styled('div')(({ theme }) => ({
21+
padding: theme.spacing(0, 2),
22+
height: '100%',
23+
position: 'absolute',
24+
pointerEvents: 'none',
25+
display: 'flex',
26+
alignItems: 'center',
27+
justifyContent: 'center',
28+
}));

0 commit comments

Comments
 (0)