Skip to content

Commit

Permalink
Enhance key event viewer UI
Browse files Browse the repository at this point in the history
  • Loading branch information
yen223 committed Nov 9, 2024
1 parent 995d239 commit 700a44e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/routes/projects.key-event-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const meta = () => {
};

function KeyEventViewer() {
const [events, setEvents] = useState<{ type: string, key: string, keyCode?: number, inputType: string, isComposing: boolean }[]>([]);
const [events, setEvents] = useState<{ type: string, key: string, keyCode?: number, inputType: string, isComposing: boolean, index: number }[]>([]);
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const input = inputRef.current;
Expand All @@ -21,7 +21,8 @@ function KeyEventViewer() {
key: '',
keyCode: undefined,
inputType: e.inputType,
isComposing: e.isComposing
isComposing: e.isComposing,
index: prev.length
}, ...prev]);
};

Expand All @@ -31,7 +32,8 @@ function KeyEventViewer() {
key: '',
keyCode: undefined,
inputType: (e as InputEvent).inputType,
isComposing: (e as InputEvent).isComposing
isComposing: (e as InputEvent).isComposing,
index: prev.length
}, ...prev]);
};

Expand All @@ -41,7 +43,8 @@ function KeyEventViewer() {
key: e.key,
keyCode: e.keyCode,
inputType: '',
isComposing: e.isComposing
isComposing: e.isComposing,
index: prev.length
}, ...prev]);
};

Expand All @@ -51,7 +54,8 @@ function KeyEventViewer() {
key: e.key,
keyCode: e.keyCode,
inputType: '',
isComposing: e.isComposing
isComposing: e.isComposing,
index: prev.length
}, ...prev]);
};
input.addEventListener('keydown', handleKeyDown);
Expand Down Expand Up @@ -103,8 +107,8 @@ function KeyEventViewer() {
</tr>
</thead>
<tbody>
{events.map((event, i) => (
<tr key={i} className="border-b dark:border-zinc-700">
{events.map((event) => (
<tr key={event.index} className="border-b dark:border-zinc-700 animate-[flash_1s_ease-in-out]">
<td className="p-2 text-zinc-400">{event.type}</td>
<td className="p-2 text-zinc-400 font-semibold">{event.key}</td>
<td className="p-2 text-zinc-400">{event.keyCode}</td>
Expand Down
9 changes: 9 additions & 0 deletions app/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ body {
color-scheme: dark;
}
}

@keyframes flash {
0% {
@apply bg-zinc-200/20 dark:bg-zinc-700/20;
}
100% {
background-color: transparent;
}
}

0 comments on commit 700a44e

Please sign in to comment.