Attempt at using inline select
Browse files
frontend/public/index.css
CHANGED
@@ -121,13 +121,13 @@ details > summary {
|
|
121 |
color: red;
|
122 |
}
|
123 |
|
124 |
-
|
125 |
background-color: #222222;
|
126 |
color: white;
|
127 |
padding: 2px;
|
128 |
}
|
129 |
|
130 |
-
|
131 |
background-color: #dd1111;
|
132 |
}
|
133 |
|
|
|
121 |
color: red;
|
122 |
}
|
123 |
|
124 |
+
.word-chip {
|
125 |
background-color: #222222;
|
126 |
color: white;
|
127 |
padding: 2px;
|
128 |
}
|
129 |
|
130 |
+
.word-chip.flagged {
|
131 |
background-color: #dd1111;
|
132 |
}
|
133 |
|
frontend/src/components/WordChip.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import React
|
2 |
|
3 |
export const WordChip = ({
|
4 |
word,
|
@@ -13,63 +13,39 @@ export const WordChip = ({
|
|
13 |
replacements: string[],
|
14 |
onReplace: (newWord: string) => void
|
15 |
}) => {
|
16 |
-
const [isExpanded, setIsExpanded] = useState(false);
|
17 |
-
const dropdownRef = useRef<HTMLSelectElement>(null);
|
18 |
-
|
19 |
-
useEffect(() => {
|
20 |
-
const handleClickOutside = (event: MouseEvent) => {
|
21 |
-
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
22 |
-
setIsExpanded(false);
|
23 |
-
}
|
24 |
-
};
|
25 |
-
|
26 |
-
document.addEventListener("mousedown", handleClickOutside);
|
27 |
-
return () => {
|
28 |
-
document.removeEventListener("mousedown", handleClickOutside);
|
29 |
-
};
|
30 |
-
}, []);
|
31 |
-
|
32 |
-
const handleClick = () => {
|
33 |
-
if (logprob < threshold && replacements.length > 0) {
|
34 |
-
setIsExpanded(true);
|
35 |
-
}
|
36 |
-
}
|
37 |
|
38 |
const handleReplacement = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
39 |
console.log("handleReplacement", event.target.value)
|
40 |
const newWord = event.target.value
|
41 |
onReplace(newWord)
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
|
45 |
return (
|
46 |
-
<
|
47 |
-
|
48 |
-
|
49 |
-
style={{
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
>
|
52 |
-
{word}
|
53 |
-
{
|
54 |
-
<
|
55 |
-
|
56 |
-
|
57 |
-
value={word}
|
58 |
-
style={{
|
59 |
-
position: "absolute",
|
60 |
-
top: "100%",
|
61 |
-
left: 0,
|
62 |
-
zIndex: 1000,
|
63 |
-
overflowY: "auto"
|
64 |
-
}}
|
65 |
-
size={replacements.length + 1}
|
66 |
-
>
|
67 |
-
<option key="original" hidden>{word}</option>
|
68 |
-
{replacements.map((r, i) => (
|
69 |
-
<option key={i} value={r}>{r}</option>
|
70 |
-
))}
|
71 |
-
</select>
|
72 |
-
)}
|
73 |
-
</span>
|
74 |
)
|
75 |
}
|
|
|
1 |
+
import React from "react"
|
2 |
|
3 |
export const WordChip = ({
|
4 |
word,
|
|
|
13 |
replacements: string[],
|
14 |
onReplace: (newWord: string) => void
|
15 |
}) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
const handleReplacement = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
18 |
console.log("handleReplacement", event.target.value)
|
19 |
const newWord = event.target.value
|
20 |
onReplace(newWord)
|
21 |
+
}
|
22 |
+
|
23 |
+
const className = `word-chip ${logprob < threshold ? "flagged" : ""}`
|
24 |
+
|
25 |
+
if (replacements.length === 0) {
|
26 |
+
return <span className={className}>{word}</span>
|
27 |
}
|
28 |
|
29 |
return (
|
30 |
+
<select
|
31 |
+
className={className}
|
32 |
+
onChange={handleReplacement}
|
33 |
+
style={{
|
34 |
+
appearance: 'none',
|
35 |
+
border: 'none',
|
36 |
+
fontFamily: 'inherit',
|
37 |
+
fontSize: 'inherit',
|
38 |
+
color: 'inherit',
|
39 |
+
background: 'inherit',
|
40 |
+
backgroundColor: 'red',
|
41 |
+
padding: 0,
|
42 |
+
cursor: 'pointer'
|
43 |
+
}}
|
44 |
>
|
45 |
+
<option key="original" hidden>{word}</option>
|
46 |
+
{replacements.map((r, i) => (
|
47 |
+
<option key={i} value={r}>{r}</option>
|
48 |
+
))}
|
49 |
+
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
)
|
51 |
}
|