blob: 0a8592f2631c4c3ec370e86637888af275f2e3b3 (
plain)
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
|
import React, { useRef } from "react";
import styled from "styled-components";
import { vscBackground } from ".";
interface InputAndButtonProps {
onUserInput: (input: string) => void;
}
const TopDiv = styled.div`
display: grid;
grid-template-columns: 3fr 1fr;
grid-gap: 0;
`;
const Input = styled.input`
padding: 0.5rem;
border: 1px solid white;
background-color: ${vscBackground};
color: white;
border-radius: 4px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
outline: none;
`;
const Button = styled.button`
padding: 0.5rem;
border: 1px solid white;
background-color: ${vscBackground};
color: white;
border-radius: 4px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-left: 0;
cursor: pointer;
&:hover {
background-color: white;
color: black;
}
`;
function InputAndButton(props: InputAndButtonProps) {
const userInputRef = useRef<HTMLInputElement>(null);
return (
<TopDiv className="grid grid-cols-2 space-x-0">
<Input
ref={userInputRef}
onKeyDown={(e) => {
if (e.key === "Enter") {
props.onUserInput(e.currentTarget.value);
}
}}
type="text"
onSubmit={(ev) => {
props.onUserInput(ev.currentTarget.value);
}}
onClick={(e) => {
e.stopPropagation();
}}
/>
<Button
onClick={(e) => {
if (userInputRef.current) {
props.onUserInput(userInputRef.current.value);
}
e.stopPropagation();
}}
>
Enter
</Button>
</TopDiv>
);
}
export default InputAndButton;
|