-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathSearch.tsx
96 lines (86 loc) · 2.29 KB
/
Search.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
89
90
91
92
93
94
95
96
import styled from "styled-components";
import { default as Input, InputProps } from "antd/es/input";
import { ReactComponent as Icon } from "icons/v1/icon-Search.svg";
import React, { CSSProperties } from "react";
const SearchInput = styled(Input)`
margin: 0;
padding: 0 11px 0 0;
height: 32px;
width: 100%;
border: 1px solid #d7d9e0;
border-radius: 4px;
font-size: 13px;
user-select: none;
overflow: hidden;
background-color: #fdfdfd;
color: #000;
&:focus {
outline: none;
box-shadow: 0 0 0 3px #daecfc;
}
&:hover {
background-color: #fdfdfd;
color: #000;
}
&:focus-within {
background-color: #fdfdfd;
color: #000;
}
`;
const SearchDiv = styled.div<{ error?: boolean }>`
height: 32px;
width: 100%;
background: #fdfdfd;
border-radius: 4px;
margin-top: 16px;
user-select: none;
&&&&& .ant-input-affix-wrapper-focused {
border-color: #3377ff;
box-shadow: 0 0 0 2px rgba(51, 119, 255, 0.2);
}
&&&.ant-input-affix-wrapper:focus,
.ant-input-affix-wrapper-focused {
border-color: #3377ff;
box-shadow: 0 0 0 2px rgba(51, 119, 255, 0.2);
}
.ant-input-affix-wrapper:hover {
border-color: #8b8fa3;
}
`;
const SearchIcon = styled(Icon)`
color: #9195a3;
margin: 6px 0 6px 8px;
`;
interface ISearch {
style?: CSSProperties;
placeholder: string;
value: string;
onChange: (value: React.ChangeEvent<HTMLInputElement>) => void;
onEnterPress?: (value: string) => void; // Added for capturing Enter key press
disabled?: boolean;
}
export const Search = (props: ISearch & InputProps) => {
const { value, onChange, style, disabled, placeholder, onEnterPress, ...others } = props;
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange && onChange(e);
};
// Handling Enter key press
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && onEnterPress) {
onEnterPress(value);
}
};
return (
<SearchDiv style={style}>
<SearchInput
disabled={disabled}
placeholder={placeholder}
onChange={handleChange}
onKeyDown={handleKeyDown} // Listening for key down events
value={value}
prefix={<SearchIcon />}
{...others}
/>
</SearchDiv>
);
};