-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSearchInput.tsx
88 lines (76 loc) · 2.09 KB
/
SearchInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { ChangeEvent, ReactElement } from 'react'
import styled from 'styled-components'
import { SearchIcon } from '../assets'
import Icon from './base/Icon'
const searchLogoWidth = '24px'
const Spacer = styled.div<{ $space: boolean }>`
${props => props.$space && 'margin: 15px 0;'}
`
const TextInput = styled.input`
width: calc(100% - ${searchLogoWidth} - 5px);
height: 25px;
box-sizing: border-box;
margin-inline-start: 5px;
color: ${props => props.theme.colors.textColor};
background: transparent;
border-width: 0 0 1px;
border-color: ${props => props.theme.colors.textSecondaryColor};
border-radius: 0;
&:focus-visible {
outline: none !important;
}
&::placeholder {
color: ${props => props.theme.colors.textColor};
}
`
const Wrapper = styled.div`
position: relative;
width: 100%;
box-sizing: border-box;
padding: 10px 10%;
background-color: ${props => props.theme.colors.backgroundColor};
display: flex;
align-items: center;
`
const StyledIcon = styled(Icon)`
width: 20px;
height: 20px;
`
type SearchInputProps = {
placeholderText: string
filterText: string
onFilterTextChange: (filterText: string) => void
spaceSearch?: boolean
onClickInput?: () => void
}
const SearchInput = ({
placeholderText,
filterText,
onClickInput,
onFilterTextChange,
spaceSearch = false,
}: SearchInputProps): ReactElement => {
const handleFilterTextChange = (event: ChangeEvent<HTMLInputElement>): void => {
if (typeof event.target.value === 'string') {
onFilterTextChange(event.target.value)
}
}
return (
<Spacer $space={spaceSearch}>
<Wrapper>
<StyledIcon src={SearchIcon} />
{/* eslint-disable-next-line styled-components-a11y/no-autofocus -- in a dedicated search modal autofocus is fine */}
<TextInput
placeholder={placeholderText}
aria-label={placeholderText}
value={filterText}
onChange={handleFilterTextChange}
onClick={onClickInput}
autoFocus
type='text'
/>
</Wrapper>
</Spacer>
)
}
export default SearchInput