Skip to content

Commit 34ccf63

Browse files
Control UI: unify composer attachment chip layout (#130312)
* fix(ui): unify composer attachment chips * fix(ui): resolve composer attachment glyphs
1 parent 7a55009 commit 34ccf63

3 files changed

Lines changed: 82 additions & 52 deletions

File tree

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5872,11 +5872,11 @@ describe("chat attachment picker", () => {
58725872
expect(preview.querySelector(".chat-attachment-file__name")?.textContent).toBe("brief.pdf");
58735873
});
58745874

5875-
it("accepts video file attachments with the generic file preview", async () => {
5875+
it("infers video preview glyphs from filenames when MIME is absent", async () => {
58765876
const onAttachmentsChange = vi.fn();
58775877
const container = renderChatView({ onAttachmentsChange });
58785878
const input = container.querySelector<HTMLInputElement>(".agent-chat__file-input");
5879-
const file = new File(["video"], "clip.mp4", { type: "video/mp4" });
5879+
const file = new File(["video"], "clip.mp4");
58805880

58815881
expect(input).toBeInstanceOf(HTMLInputElement);
58825882
expect(input?.accept).toContain("video/*");
@@ -5886,14 +5886,18 @@ describe("chat attachment picker", () => {
58865886
const attachments = requireFirstAttachmentsChange(onAttachmentsChange);
58875887
expect(attachments).toHaveLength(1);
58885888
expect(attachments[0]?.fileName).toBe("clip.mp4");
5889-
expect(attachments[0]?.mimeType).toBe("video/mp4");
5889+
expect(attachments[0]?.mimeType).toBe("application/octet-stream");
58905890
expect(attachments[0]?.sizeBytes).toBe(file.size);
58915891
});
58925892

58935893
const nextAttachments = requireFirstAttachmentsChange(onAttachmentsChange);
58945894
const preview = renderChatView({ attachments: nextAttachments });
58955895
expect(preview.querySelectorAll(".chat-attachment-thumb--file")).toHaveLength(1);
58965896
expect(preview.querySelector(".chat-attachment-file__name")?.textContent).toBe("clip.mp4");
5897+
expect(preview.querySelector(".chat-attachment-file__icon")?.getAttribute("data-family")).toBe(
5898+
"video",
5899+
);
5900+
expect(preview.querySelector(".chat-attachment-file__type")?.textContent).toBe("MP4");
58975901
});
58985902
});
58995903

‎ui/src/pages/chat/components/chat-attachments.ts‎

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
releaseChatAttachmentPayload,
1818
} from "../attachment-payload-store.ts";
1919
import { admitAttachmentFiles } from "./chat-attachment-admission.ts";
20-
import { renderAttachmentFileIcon } from "./chat-attachment-file-icon.ts";
20+
import { resolveAttachmentFileIcon } from "./chat-attachment-file-icon.ts";
2121
import { syncChatAttachmentRailScroll } from "./chat-attachment-viewport.ts";
2222

2323
const CHAT_ATTACHMENT_ACCEPT =
@@ -195,6 +195,32 @@ function pastedTextPreview(attachment: ChatAttachment): string {
195195
);
196196
}
197197

198+
function renderCompactAttachmentFile(attachment: ChatAttachment) {
199+
const resolved = resolveAttachmentFileIcon(
200+
attachment.fileName ?? "attachment",
201+
attachment.mimeType,
202+
);
203+
const glyph =
204+
resolved.family === "video"
205+
? icons.play
206+
: resolved.family === "audio"
207+
? icons.music
208+
: icons.fileText;
209+
return html`
210+
<openclaw-tooltip .content=${attachment.fileName ?? t("chat.attachments.attachedFile")}>
211+
<div class="chat-attachment-file">
212+
<span class="chat-attachment-file__icon" data-family=${resolved.family}>${glyph}</span>
213+
<span class="chat-attachment-file__body">
214+
<span class="chat-attachment-file__name"
215+
>${attachment.fileName ?? t("chat.attachments.attachedFile")}</span
216+
>
217+
<span class="chat-attachment-file__type">${resolved.extensionLabel}</span>
218+
</span>
219+
</div>
220+
</openclaw-tooltip>
221+
`;
222+
}
223+
198224
function appendPastedTextToDraft(draft: string, text: string): string {
199225
if (!draft.trim()) {
200226
return text;
@@ -685,13 +711,7 @@ export function renderAttachmentPreview(props: ChatAttachmentControlsProps) {
685711
: isLargePastedTextAttachment(att)
686712
? html`
687713
<div class="chat-attachment-file chat-attachment-file--pasted-text">
688-
<span class="chat-attachment-file__icon"
689-
>${renderAttachmentFileIcon({
690-
filename: att.fileName ?? "pasted-text.txt",
691-
mimeType: att.mimeType,
692-
mode: "preview-with-favicon",
693-
})}</span
694-
>
714+
<span class="chat-attachment-file__icon">${icons.fileText}</span>
695715
<span class="chat-attachment-file__body">
696716
<span class="chat-attachment-file__name"
697717
>${pastedTextPreview(att)}</span
@@ -709,24 +729,7 @@ export function renderAttachmentPreview(props: ChatAttachmentControlsProps) {
709729
</span>
710730
</div>
711731
`
712-
: html`
713-
<openclaw-tooltip
714-
.content=${att.fileName ?? t("chat.attachments.attachedFile")}
715-
>
716-
<div class="chat-attachment-file">
717-
<span class="chat-attachment-file__icon"
718-
>${renderAttachmentFileIcon({
719-
filename: att.fileName ?? "attachment",
720-
mimeType: att.mimeType,
721-
mode: "large-placeholder",
722-
})}</span
723-
>
724-
<span class="chat-attachment-file__name"
725-
>${att.fileName ?? t("chat.attachments.attachedFile")}</span
726-
>
727-
</div>
728-
</openclaw-tooltip>
729-
`}
732+
: renderCompactAttachmentFile(att)}
730733
<openclaw-tooltip .content=${t("chat.composer.removeAttachment")}>
731734
<button
732735
class="chat-attachment-remove"

‎ui/src/styles/chat/layout.css‎

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,7 +5592,7 @@ button.chat-pr__diff {
55925592
padding-block-start: 10px;
55935593
padding-block-end: 5px;
55945594
padding-inline: 10px;
5595-
margin-bottom: 8px;
5595+
margin-bottom: 2px;
55965596
overflow-x: auto;
55975597
overflow-y: hidden;
55985598
overscroll-behavior-inline: contain;
@@ -5632,7 +5632,7 @@ button.chat-pr__diff {
56325632
corner-shape: superellipse(1.5);
56335633
overflow: hidden;
56345634
border: 1px solid var(--border);
5635-
background: var(--panel);
5635+
background: var(--chat-composer-surface, var(--popover));
56365636
transition:
56375637
border-color var(--duration-fast) ease,
56385638
background var(--duration-fast) ease;
@@ -5644,13 +5644,13 @@ button.chat-pr__diff {
56445644
}
56455645

56465646
.chat-attachment-thumb--file {
5647-
width: 220px;
5648-
height: 82px;
5647+
width: 162px;
5648+
height: 56px;
56495649
}
56505650

56515651
.chat-attachment-thumb--pasted-text {
5652-
width: min(220px, calc(100vw - 64px));
5653-
background: transparent;
5652+
width: min(162px, calc(100vw - 64px));
5653+
background: var(--chat-composer-surface, var(--popover));
56545654
}
56555655

56565656
.chat-attachment-thumb--browser-annotation {
@@ -5661,7 +5661,7 @@ button.chat-pr__diff {
56615661
max-width: min(300px, calc(100vw - 64px));
56625662
min-width: 0;
56635663
height: 56px;
5664-
background: transparent;
5664+
background: var(--chat-composer-surface, var(--popover));
56655665
}
56665666

56675667
.chat-browser-annotation-card__preview {
@@ -5723,19 +5723,20 @@ button.chat-pr__diff {
57235723
object-fit: cover;
57245724
}
57255725

5726-
.chat-attachment-image-button {
5726+
.chat-attachment-image-button.chat-attachment-image-button {
57275727
position: relative;
57285728
width: 100%;
57295729
height: 100%;
57305730
border-radius: calc(var(--chat-attachment-radius) - 1px);
57315731
corner-shape: superellipse(1.5);
57325732
}
57335733

5734-
.chat-attachment-image-button::after {
5734+
.chat-attachment-image-button.chat-attachment-image-button::after {
57355735
content: "";
57365736
position: absolute;
57375737
inset: 0;
5738-
border-radius: inherit;
5738+
border-radius: calc(var(--chat-attachment-radius) - 1px);
5739+
corner-shape: superellipse(1.5);
57395740
background: color-mix(in srgb, var(--text-strong) 8%, transparent);
57405741
opacity: 0;
57415742
pointer-events: none;
@@ -5754,7 +5755,8 @@ button.chat-pr__diff {
57545755
width: 20px;
57555756
height: 20px;
57565757
padding: 0;
5757-
border-radius: 50%;
5758+
border-radius: calc(7px * var(--openclaw-corner-radius-scale));
5759+
corner-shape: superellipse(1.5);
57585760
border: none;
57595761
background: color-mix(in srgb, var(--bg) 82%, transparent);
57605762
color: var(--text-strong);
@@ -5796,11 +5798,11 @@ button.chat-pr__diff {
57965798
display: flex;
57975799
align-items: center;
57985800
justify-content: flex-start;
5799-
gap: 9px;
5800-
width: fit-content;
5801+
gap: 10px;
5802+
width: 100%;
58015803
max-width: 100%;
58025804
height: 100%;
5803-
padding: 7px 10px;
5805+
padding: 8px 12px;
58045806
overflow: hidden;
58055807
font-size: 0.72rem;
58065808
color: var(--text);
@@ -5811,13 +5813,13 @@ button.chat-pr__diff {
58115813
}
58125814

58135815
.chat-attachment-thumb--file:is(:hover, :focus-within) .chat-attachment-file {
5814-
background: color-mix(in srgb, var(--panel) 86%, var(--text));
5816+
background: color-mix(in srgb, var(--chat-composer-surface, var(--popover)) 86%, var(--text));
58155817
}
58165818

58175819
.chat-attachment-file--pasted-text {
58185820
justify-content: flex-start;
5819-
gap: 8px;
5820-
padding: 10px 42px 10px 10px;
5821+
gap: 10px;
5822+
padding: 8px 32px 8px 12px;
58215823
background: transparent;
58225824
}
58235825

@@ -5826,11 +5828,19 @@ button.chat-pr__diff {
58265828
align-items: center;
58275829
justify-content: center;
58285830
flex: 0 0 auto;
5831+
width: 20px;
5832+
height: 20px;
5833+
color: var(--muted);
58295834
}
58305835

5831-
.chat-attachment-file--pasted-text .chat-attachment-file__icon {
5832-
width: 16px;
5833-
height: 16px;
5836+
.chat-attachment-file__icon svg {
5837+
width: 20px;
5838+
height: 20px;
5839+
stroke: currentColor;
5840+
fill: none;
5841+
stroke-width: 1.8px;
5842+
stroke-linecap: round;
5843+
stroke-linejoin: round;
58345844
}
58355845

58365846
.chat-attachment-file__name {
@@ -5842,19 +5852,28 @@ button.chat-pr__diff {
58425852
}
58435853

58445854
.chat-attachment-file--pasted-text .chat-attachment-file__name {
5845-
font-size: 0.86rem;
5846-
line-height: 1.2;
5855+
font-size: 0.72rem;
5856+
line-height: 1.15;
58475857
}
58485858

58495859
.chat-attachment-file__body {
58505860
display: flex;
58515861
min-width: 0;
5852-
max-width: 220px;
5862+
max-width: 100%;
58535863
flex-direction: column;
58545864
justify-content: center;
58555865
gap: 3px;
58565866
}
58575867

5868+
.chat-attachment-file__type {
5869+
overflow: hidden;
5870+
color: var(--muted);
5871+
font-size: 0.64rem;
5872+
line-height: 1.1;
5873+
text-overflow: ellipsis;
5874+
white-space: nowrap;
5875+
}
5876+
58585877
.chat-attachment-text-action {
58595878
display: inline-flex;
58605879
width: fit-content;
@@ -5867,10 +5886,14 @@ button.chat-pr__diff {
58675886
background: transparent;
58685887
cursor: var(--cursor-action);
58695888
font: inherit;
5889+
overflow: hidden;
5890+
font-size: 0.64rem;
58705891
line-height: 1.15;
58715892
text-align: left;
5893+
text-overflow: ellipsis;
58725894
text-decoration: underline;
58735895
text-underline-offset: 2px;
5896+
white-space: nowrap;
58745897
}
58755898

58765899
.chat-attachment-text-action:hover {

0 commit comments

Comments
 (0)