-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathSearchInputBox.tsx
More file actions
124 lines (114 loc) · 3.44 KB
/
SearchInputBox.tsx
File metadata and controls
124 lines (114 loc) · 3.44 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/interactive-supports-focus */
import { ForwardedRef, forwardRef, MouseEvent } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import { Input, MagnifyingGlassSVG } from '@ensdomains/thorin'
const SearchInputWrapper = styled.div<{ $size: 'medium' | 'extraLarge' }>(
({ theme, $size }) => css`
z-index: 1;
box-shadow: ${theme.boxShadows['0.25']};
border-radius: ${theme.radii['2.5xLarge']};
border-color: ${theme.colors.border};
width: 100%;
& input {
padding-right: ${theme.space['12']};
}
& button {
position: relative;
right: -${theme.space['4']};
}
& input::placeholder {
color: ${theme.colors.greyPrimary};
font-weight: ${theme.fontWeights.bold};
}
${$size === 'medium' &&
css`
max-width: ${theme.space['96']};
box-shadow: none;
border-radius: ${theme.radii.full};
& input::placeholder {
color: ${theme.colors.greyPrimary};
font-weight: ${theme.fontWeights.normal};
}
`}
`,
)
const MagnifyingGlassIcon = styled.svg(
({ theme }) => css`
width: ${theme.space['4']};
height: ${theme.space['4']};
`,
)
// const ResetButton = styled.div(
// ({ theme }) => css`
// display: block;
// transition: all 0.15s ease-in-out;
// cursor: pointer;
// color: rgba(${theme.shadesRaw.foreground}, 0.25);
// width: ${theme.space['7']};
// height: ${theme.space['7']};
// margin-right: ${theme.space['2']};
// &:hover {
// color: rgba(${theme.shadesRaw.foreground}, 0.3);
// transform: translateY(-1px);
// }
// `,
// )
type SearchInputBoxProps = {
size?: 'medium' | 'extraLarge'
input: string
setInput: (value: string) => void
containerRef: ForwardedRef<HTMLDivElement>
}
export const SearchInputBox = forwardRef<HTMLInputElement, SearchInputBoxProps>(
({ size = 'extraLarge', input, setInput, containerRef }, ref) => {
const { t } = useTranslation('common')
return (
<SearchInputWrapper ref={containerRef} $size={size}>
<Input
size={size}
label={t('search.label')}
hideLabel
placeholder={t('search.placeholder')}
value={input}
onChange={(e) => setInput(e.target.value)}
ref={ref}
clearable
autoComplete="off"
autoCorrect="off"
icon={size === 'medium' ? <MagnifyingGlassIcon as={MagnifyingGlassSVG} /> : undefined}
spellCheck="false"
data-testid="search-input-box"
/>
</SearchInputWrapper>
)
},
)
type FakeSearchInputBoxProps = {
size?: 'medium' | 'extraLarge'
onClick: (e: MouseEvent<HTMLInputElement>) => void
}
export const FakeSearchInputBox = forwardRef<HTMLInputElement, FakeSearchInputBoxProps>(
({ size = 'extraLarge', onClick }, ref) => {
const { t } = useTranslation('common')
return (
<SearchInputWrapper $size={size}>
<Input
size={size}
label={t('search.label')}
hideLabel
placeholder={t('search.placeholder')}
ref={ref}
onClick={onClick}
readOnly
autoComplete="off"
autoCorrect="off"
spellCheck="false"
data-testid="search-input-box-fake"
/>
</SearchInputWrapper>
)
},
)