🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): unify keyboard shortcut keycaps (#14164)
Nikita Kabardin480028c60d2a
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsxindex 399118f1cc..db7963133d 100644--- a/web/src/components/layouts/routes.tsx+++ b/web/src/components/layouts/routes.tsx@@ -30,6 +30,7 @@ import { InAppAiAgentButton } from "@/src/components/nav/in-app-ai-agent-button"import { BookACallButton } from "@/src/components/nav/book-a-call-button";import { V4SidebarToggle } from "@/src/features/events/components/V4SidebarToggle";import { SidebarMenuButton } from "@/src/components/ui/sidebar";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import { useCommandMenu } from "@/src/features/command-k-menu/CommandMenuProvider";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { CloudStatusMenu } from "@/src/features/cloud-status-notification/components/CloudStatusMenu";@@ -277,14 +278,10 @@ function CommandMenuTrigger() {><Search className="h-4 w-4" />Go to...- <kbd className="pointer-events-none ml-auto inline-flex h-5 items-center gap-1 rounded-md border px-1.5 font-mono text-[10px] select-none">- {navigator.userAgent.includes("Mac") ? (- <span className="text-[12px]">⌘</span>- ) : (- <span>Ctrl</span>- )}- <span>K</span>- </kbd>+ <KeyboardShortcut+ className="ml-auto"+ keys={[navigator.userAgent.includes("Mac") ? "⌘" : "Ctrl", "K"]}+ /></SidebarMenuButton>);}diff --git a/web/src/components/ui/command.tsx b/web/src/components/ui/command.tsxindex 539df913ad..1596071f75 100644--- a/web/src/components/ui/command.tsx+++ b/web/src/components/ui/command.tsx@@ -6,6 +6,10 @@ import { Command as CommandPrimitive } from "cmdk";import { Search } from "lucide-react";import { cn } from "@/src/utils/tailwind";+import {+ KeyboardShortcut,+ type KeyboardShortcutProps,+} from "@/src/components/ui/keyboard-shortcut";import {Dialog,DialogBody,@@ -163,19 +167,8 @@ const CommandItem = React.forwardRef<CommandItem.displayName = CommandPrimitive.Item.displayName;-const CommandShortcut = ({- className,- ...props-}: React.HTMLAttributes<HTMLSpanElement>) => {- return (- <span- className={cn(- "text-muted-foreground ml-auto text-xs tracking-widest",- className,- )}- {...props}- />- );+const CommandShortcut = ({ className, ...props }: KeyboardShortcutProps) => {+ return <KeyboardShortcut className={cn("ml-auto", className)} {...props} />;};CommandShortcut.displayName = "CommandShortcut";diff --git a/web/src/components/ui/input-command.tsx b/web/src/components/ui/input-command.tsxindex 7fb57a45b2..a61379dabb 100644--- a/web/src/components/ui/input-command.tsx+++ b/web/src/components/ui/input-command.tsx@@ -9,6 +9,10 @@ import { Command as CommandPrimitive } from "cmdk";import { Search } from "lucide-react";import { Dialog, DialogBody, DialogContent } from "@/src/components/ui/dialog";+import {+ KeyboardShortcut,+ type KeyboardShortcutProps,+} from "@/src/components/ui/keyboard-shortcut";import { cn } from "@/src/utils/tailwind";const InputCommand = React.forwardRef<@@ -146,16 +150,8 @@ InputCommandItem.displayName = CommandPrimitive.Item.displayName;const InputCommandShortcut = ({className,...props-}: React.HTMLAttributes<HTMLSpanElement>) => {- return (- <span- className={cn(- "ml-auto text-xs tracking-widest text-slate-500 dark:text-slate-400",- className,- )}- {...props}- />- );+}: KeyboardShortcutProps) => {+ return <KeyboardShortcut className={cn("ml-auto", className)} {...props} />;};InputCommandShortcut.displayName = "CommandShortcut";diff --git a/web/src/components/ui/keyboard-shortcut.tsx b/web/src/components/ui/keyboard-shortcut.tsxnew file mode 100644index 0000000000..7b331ccbb2--- /dev/null+++ b/web/src/components/ui/keyboard-shortcut.tsx@@ -0,0 +1,33 @@+import * as React from "react";++import { cn } from "@/src/utils/tailwind";++type KeyboardShortcutContent =+ | { children: React.ReactNode; keys?: never }+ | { children?: never; keys: React.ReactNode[] };++export type KeyboardShortcutProps = Omit<+ React.ComponentPropsWithoutRef<"kbd">,+ "children"+> &+ KeyboardShortcutContent;++const KeyboardShortcut = React.forwardRef<HTMLElement, KeyboardShortcutProps>(+ ({ className, children, keys, ...props }, ref) => (+ <kbd+ ref={ref}+ className={cn(+ "bg-muted text-muted-foreground pointer-events-none inline-flex h-5 min-w-5 items-center justify-center gap-1 rounded-md border px-1.5 font-mono text-[10px] leading-none font-medium shadow-xs select-none",+ className,+ )}+ {...props}+ >+ {keys+ ? keys.map((key, index) => <span key={index}>{key}</span>)+ : children}+ </kbd>+ ),+);+KeyboardShortcut.displayName = "KeyboardShortcut";++export { KeyboardShortcut };diff --git a/web/src/features/comments/CommentList.tsx b/web/src/features/comments/CommentList.tsxindex 7e6e1da6e5..0da62cd680 100644--- a/web/src/features/comments/CommentList.tsx+++ b/web/src/features/comments/CommentList.tsx@@ -4,6 +4,7 @@ import {AvatarImage,} from "@/src/components/ui/avatar";import { Button } from "@/src/components/ui/button";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import {Form,FormControl,@@ -536,16 +537,15 @@ export function CommentList({</Button>)}{!searchQuery && (- <kbd className="bg-muted text-muted-foreground pointer-events-none absolute top-1/2 right-1 h-5 -translate-y-1/2 items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium opacity-50 select-none sm:inline-flex">- {typeof navigator !== "undefined" &&- navigator.userAgent.includes("Macintosh") ? (- <>- <span className="text-xs">⌘</span>F- </>- ) : (- <>Ctrl+F</>- )}- </kbd>+ <KeyboardShortcut+ className="absolute top-1/2 right-1 hidden -translate-y-1/2 opacity-50 sm:inline-flex"+ keys={+ typeof navigator !== "undefined" &&+ navigator.userAgent.includes("Macintosh")+ ? ["⌘", "F"]+ : ["Ctrl", "F"]+ }+ />)}</div></div>@@ -803,9 +803,7 @@ export function CommentList({><div className="flex items-center gap-2 text-sm"><span>Send comment</span>- <kbd className="bg-muted text-muted-foreground pointer-events-none inline-flex h-5 items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium opacity-100 select-none">- <span className="text-xs">⌘</span>Enter- </kbd>+ <KeyboardShortcut keys={["⌘", "Enter"]} /></div></HoverCardContent></HoverCard>diff --git a/web/src/features/evals/components/code-eval-template-form-body.tsx b/web/src/features/evals/components/code-eval-template-form-body.tsxindex 756428e86e..1c8e556dd6 100644--- a/web/src/features/evals/components/code-eval-template-form-body.tsx+++ b/web/src/features/evals/components/code-eval-template-form-body.tsx@@ -21,6 +21,7 @@ import {import { Loader2 } from "lucide-react";import { Button } from "@/src/components/ui/button";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import { darkTheme } from "@/src/components/editor/dark-theme";import { lightTheme } from "@/src/components/editor/light-theme";import {@@ -399,17 +400,15 @@ export function CodeEvalTemplateFormBody({<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" />)}Format- <kbd className="bg-muted text-muted-foreground pointer-events-none ml-2 hidden h-4 items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium select-none sm:inline-flex">- {typeof navigator !== "undefined" &&- navigator.userAgent.includes("Macintosh") ? (- <>- <span className="text-xs">⇧</span>- <span className="text-xs">⌥</span>F- </>- ) : (- <>Shift+Alt+F</>- )}- </kbd>+ <KeyboardShortcut+ className="ml-2 hidden h-4 sm:inline-flex"+ keys={+ typeof navigator !== "undefined" &&+ navigator.userAgent.includes("Macintosh")+ ? ["⇧", "⌥", "F"]+ : ["Shift", "Alt", "F"]+ }+ /></Button>) : null}</div>diff --git a/web/src/features/navigate-detail-pages/DetailPageNav.tsx b/web/src/features/navigate-detail-pages/DetailPageNav.tsxindex d7ba7e2960..fdcbc15dd0 100644--- a/web/src/features/navigate-detail-pages/DetailPageNav.tsx+++ b/web/src/features/navigate-detail-pages/DetailPageNav.tsx@@ -1,5 +1,6 @@import { Button } from "@/src/components/ui/button";import { InputCommandShortcut } from "@/src/components/ui/input-command";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import {Tooltip,TooltipContent,@@ -10,9 +11,14 @@ import {useDetailPageLists,} from "@/src/features/navigate-detail-pages/context";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";-import { ChevronDown, ChevronUp } from "lucide-react";+import { cn } from "@/src/utils/tailwind";+import { ArrowDown, ArrowUp } from "lucide-react";import { useRouter } from "next/router";-import { useCallback, useEffect } from "react";+import { useCallback, useEffect, useRef, useState } from "react";++const SHORTCUT_PULSE_MS = 160;++type ShortcutPulse = "previous" | "next" | null;export const DetailPageNav = (props: {currentId: string;@@ -23,6 +29,10 @@ export const DetailPageNav = (props: {const { currentId, path, listKey, onNavigate } = props;const { detailPagelists } = useDetailPageLists();const entries = detailPagelists[listKey] ?? [];+ const [shortcutPulse, setShortcutPulse] = useState<ShortcutPulse>(null);+ const shortcutPulseTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(+ null,+ );const capture = usePostHogClientCapture();const router = useRouter();@@ -49,6 +59,29 @@ export const DetailPageNav = (props: {[onNavigate, path, router],);+ const pulseShortcut = useCallback(+ (direction: Exclude<ShortcutPulse, null>) => {+ if (shortcutPulseTimeoutRef.current) {+ clearTimeout(shortcutPulseTimeoutRef.current);+ }++ setShortcutPulse(direction);+ shortcutPulseTimeoutRef.current = setTimeout(() => {+ setShortcutPulse(null);+ shortcutPulseTimeoutRef.current = null;+ }, SHORTCUT_PULSE_MS);+ },+ [],+ );++ useEffect(() => {+ return () => {+ if (shortcutPulseTimeoutRef.current) {+ clearTimeout(shortcutPulseTimeoutRef.current);+ }+ };+ }, []);+// keyboard shortcuts for buttons k and juseEffect(() => {const handleKeyDown = (event: KeyboardEvent) => {@@ -67,14 +100,16 @@ export const DetailPageNav = (props: {}if (event.key === "k" && previousPageEntry) {+ pulseShortcut("previous");navigateToEntry(previousPageEntry);} else if (event.key === "j" && nextPageEntry) {+ pulseShortcut("next");navigateToEntry(nextPageEntry);}};window.addEventListener("keydown", handleKeyDown);return () => window.removeEventListener("keydown", handleKeyDown);- }, [previousPageEntry, nextPageEntry, navigateToEntry]);+ }, [previousPageEntry, nextPageEntry, navigateToEntry, pulseShortcut]);if (entries.length > 1)return (@@ -84,7 +119,11 @@ export const DetailPageNav = (props: {<Buttonvariant="outline"type="button"- className="p-2"+ className={cn(+ "gap-1.5 px-2 transition-[background-color,border-color,box-shadow,color] duration-150",+ shortcutPulse === "previous" &&+ "border-primary/60 bg-accent/60 ring-primary/20 ring-2",+ )}disabled={!previousPageEntry}onClick={() => {if (previousPageEntry) {@@ -93,17 +132,13 @@ export const DetailPageNav = (props: {}}}>- <ChevronUp className="h-4 w-4" />- <span className="bg-primary/80 text-primary-foreground ml-1 h-4 w-4 rounded-sm text-xs shadow-xs">- K- </span>+ <ArrowUp className="h-4 w-4" />+ <KeyboardShortcut>K</KeyboardShortcut></Button></TooltipTrigger><TooltipContent><span>Navigate up</span>- <InputCommandShortcut className="bg-muted ml-2 rounded-sm p-1 px-2">- k- </InputCommandShortcut>+ <InputCommandShortcut className="ml-2">K</InputCommandShortcut></TooltipContent></Tooltip>@@ -112,7 +147,11 @@ export const DetailPageNav = (props: {<Buttonvariant="outline"type="button"- className="p-2"+ className={cn(+ "gap-1.5 px-2 transition-[background-color,border-color,box-shadow,color] duration-150",+ shortcutPulse === "next" &&+ "border-primary/60 bg-accent/60 ring-primary/20 ring-2",+ )}disabled={!nextPageEntry}onClick={() => {if (nextPageEntry) {@@ -121,17 +160,13 @@ export const DetailPageNav = (props: {}}}>- <ChevronDown className="h-4 w-4" />- <span className="bg-primary/80 text-primary-foreground ml-1 h-4 w-4 rounded-sm text-xs shadow-xs">- J- </span>+ <ArrowDown className="h-4 w-4" />+ <KeyboardShortcut>J</KeyboardShortcut></Button></TooltipTrigger><TooltipContent><span>Navigate down</span>- <InputCommandShortcut className="bg-muted ml-2 rounded-sm p-1 px-2">- j- </InputCommandShortcut>+ <InputCommandShortcut className="ml-2">J</InputCommandShortcut></TooltipContent></Tooltip></div>diff --git a/web/src/features/playground/page/index.tsx b/web/src/features/playground/page/index.tsxindex 3e8b552717..5b7b025667 100644--- a/web/src/features/playground/page/index.tsx+++ b/web/src/features/playground/page/index.tsx@@ -1,5 +1,6 @@import React, { useCallback, useEffect, useState } from "react";import { Button } from "@/src/components/ui/button";+import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import { Play } from "lucide-react";import { ResetPlaygroundButton } from "@/src/features/playground/page/components/ResetPlaygroundButton";import { useWindowCoordination } from "@/src/features/playground/page/hooks/useWindowCoordination";@@ -190,14 +191,7 @@ export default function PlaygroundPage() {)}<span className="hidden items-center gap-1 lg:inline-flex"><span>Run All</span>- <kbd className="bg-muted text-muted-foreground pointer-events-none inline-flex h-5 items-center gap-1 rounded border px-1.5 font-mono text-[10px] font-medium opacity-100 select-none">- {isMac ? (- <span className="text-xs">⌘</span>- ) : (- <span>Ctrl</span>- )}- <span>Enter</span>- </kbd>+ <KeyboardShortcut keys={[isMac ? "⌘" : "Ctrl", "Enter"]} /></span></Button>