Skip to content

Commit 935efaf

Browse files
authored
Merge pull request #753 from amitamrutiya/catalog-search-sort
Convert cloud catalog sort menu and search field to sistent
2 parents ec97bc5 + 37e3572 commit 935efaf

2 files changed

Lines changed: 61 additions & 33 deletions

File tree

src/custom/StyledSearchBar/StyledSearchBar.tsx

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
1+
import { SxProps, Theme, useTheme } from '@mui/material';
12
import React from 'react';
2-
import { Box } from '../../base/Box';
3-
import { InputAdornment } from '../../base/Input';
4-
import { TextField } from '../../base/TextField';
3+
import { InputAdornment } from '../../base';
4+
import { SearchIcon } from '../../icons';
5+
import { InputAdornmentEnd, StyledSearchInput } from './style';
56

67
interface SearchBarProps {
78
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
89
value?: string;
910
width?: string;
10-
label: string;
11+
label?: string;
12+
placeholder?: string;
13+
sx?: SxProps<Theme>;
1114
endAdornment?: React.ReactNode;
1215
}
1316

17+
/**
18+
* StyledSearchBar component renders a search input field with customizable properties.
19+
*
20+
* @param {Object} props - The component props.
21+
* @param {function} [props.onChange] - Function to handle the change event when the search input value changes.
22+
* @param {string} [props.value] - The current value of the search input.
23+
* @param {string} [props.label] - The label for the search input.
24+
* @param {string} [props.placeholder] - The placeholder text for the search input.
25+
* @param {Object} [props.sx] - The style object for the search input.
26+
* @param {React.ReactNode} [props.endAdornment] - The element to display at the end of the search input.
27+
*
28+
* @returns {JSX.Element} The rendered StyledSearchBar component.
29+
*/
1430
function StyledSearchBar({
1531
onChange,
1632
value,
17-
width,
1833
label,
19-
endAdornment,
20-
...props
34+
sx,
35+
placeholder,
36+
endAdornment
2137
}: SearchBarProps): JSX.Element {
38+
const theme = useTheme();
39+
2240
return (
23-
<React.Fragment>
24-
<Box
25-
component="form"
26-
sx={{
27-
'& > :not(style)': { width }
28-
}}
29-
{...props}
30-
>
31-
<TextField
32-
variant="outlined"
33-
label={label}
34-
fullWidth
35-
type="search"
36-
value={value}
37-
onChange={onChange}
38-
sx={{
39-
margin: 'auto',
40-
height: '5ch'
41-
}}
42-
placeholder="Search"
43-
InputProps={{
44-
endAdornment: <InputAdornment position="end">{endAdornment}</InputAdornment>
45-
}}
46-
/>
47-
</Box>
48-
</React.Fragment>
41+
<StyledSearchInput
42+
type="search"
43+
label={label}
44+
fullWidth
45+
value={value}
46+
onChange={onChange}
47+
sx={sx}
48+
placeholder={placeholder ?? 'Search'}
49+
startAdornment={
50+
<InputAdornment position="start">
51+
<SearchIcon fill={theme.palette.background.neutral?.default} />
52+
</InputAdornment>
53+
}
54+
endAdornment={<InputAdornmentEnd position="end">{endAdornment}</InputAdornmentEnd>}
55+
/>
4956
);
5057
}
5158

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { styled } from '@mui/material';
2+
import { InputAdornment, OutlinedInput } from '../../base';
3+
4+
export const StyledSearchInput = styled(OutlinedInput)(({ style }) => ({
5+
width: '100%',
6+
'@media (max-width: 590px)': {
7+
marginLeft: '0.25rem',
8+
paddingLeft: '0.25rem'
9+
},
10+
display: 'flex',
11+
...style
12+
}));
13+
14+
export const InputAdornmentEnd = styled(InputAdornment)(({ theme }) => ({
15+
borderLeft: `1px solid ${theme.palette.border.normal}`,
16+
height: '30px',
17+
paddingLeft: '10px',
18+
'@media (max-width: 590px)': {
19+
paddingLeft: '0px'
20+
}
21+
}));

0 commit comments

Comments
 (0)