From 14d3d72bcccd6dc9079eee30f59b64d9dd0f8e0e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 21 Jan 2026 02:58:51 +0000 Subject: [PATCH] refactor(ui): reuse emoji icon helpers --- ui/src/ui/chat/copy-as-markdown.ts | 46 +++++++++++++++++++----------- ui/src/ui/icons.ts | 10 +++++++ 2 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 ui/src/ui/icons.ts diff --git a/ui/src/ui/chat/copy-as-markdown.ts b/ui/src/ui/chat/copy-as-markdown.ts index 0310a59b8..8786d3546 100644 --- a/ui/src/ui/chat/copy-as-markdown.ts +++ b/ui/src/ui/chat/copy-as-markdown.ts @@ -1,4 +1,5 @@ import { html, type TemplateResult } from "lit"; +import { renderEmojiIcon, setEmojiIcon } from "../icons"; const COPIED_FOR_MS = 1500; const ERROR_FOR_MS = 2000; @@ -9,6 +10,11 @@ const COPY_ICON = "📋"; const COPIED_ICON = "✓"; const ERROR_ICON = "!"; +type CopyButtonOptions = { + text: () => string; + label?: string; +}; + async function copyTextToClipboard(text: string): Promise { if (!text) return false; @@ -20,13 +26,19 @@ async function copyTextToClipboard(text: string): Promise { } } -export function renderCopyAsMarkdownButton(markdown: string): TemplateResult { +function setButtonLabel(button: HTMLButtonElement, label: string) { + button.title = label; + button.setAttribute("aria-label", label); +} + +function createCopyButton(options: CopyButtonOptions): TemplateResult { + const idleLabel = options.label ?? COPY_LABEL; return html` `; } + +export function renderCopyAsMarkdownButton(markdown: string): TemplateResult { + return createCopyButton({ text: () => markdown, label: COPY_LABEL }); +} diff --git a/ui/src/ui/icons.ts b/ui/src/ui/icons.ts new file mode 100644 index 000000000..4803f223e --- /dev/null +++ b/ui/src/ui/icons.ts @@ -0,0 +1,10 @@ +import { html, type TemplateResult } from "lit"; + +export function renderEmojiIcon(icon: string, className: string): TemplateResult { + return html``; +} + +export function setEmojiIcon(target: HTMLElement | null, icon: string): void { + if (!target) return; + target.textContent = icon; +}