|
| 1 | +import { SxProps, Theme, useTheme } from '@mui/material'; |
1 | 2 | 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'; |
5 | 6 |
|
6 | 7 | interface SearchBarProps { |
7 | 8 | onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void; |
8 | 9 | value?: string; |
9 | 10 | width?: string; |
10 | | - label: string; |
| 11 | + label?: string; |
| 12 | + placeholder?: string; |
| 13 | + sx?: SxProps<Theme>; |
11 | 14 | endAdornment?: React.ReactNode; |
12 | 15 | } |
13 | 16 |
|
| 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 | + */ |
14 | 30 | function StyledSearchBar({ |
15 | 31 | onChange, |
16 | 32 | value, |
17 | | - width, |
18 | 33 | label, |
19 | | - endAdornment, |
20 | | - ...props |
| 34 | + sx, |
| 35 | + placeholder, |
| 36 | + endAdornment |
21 | 37 | }: SearchBarProps): JSX.Element { |
| 38 | + const theme = useTheme(); |
| 39 | + |
22 | 40 | 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 | + /> |
49 | 56 | ); |
50 | 57 | } |
51 | 58 |
|
|
0 commit comments