Comments
A design thread where you can @mention the agent and it replies. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.
Need this designed into your product? Book a call
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add commentsReact
npx designme add comments --reactAstro
npx designme add comments --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/comments.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/comments.json The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.
About
What it is for and what it does.
Comments is a thread pinned to one spot in a design, where people reply to each other and can bring the agent in by typing @agent. Each comment is an avatar, a name, a time and the text; the first one starts the thread and the replies sit indented under it on a thin line. A quiet Agree button shows beside the time on hover or keyboard focus. The agent's reply shows a thinking mark first, then its words fade in, and it can end with buttons such as Apply to all that turn into a short note once used. The whole thread can be resolved: the pin turns green, a Resolved chip shows and the reply field folds away, while the thread keeps its colours.
- When feedback lives on a design or document and the agent should act on it from the thread
- When people need to @mention teammates and the agent from the same reply field
- When an agent's suggestion needs a yes or a choice before it changes anything
- When resolved threads should stay visible and say they are resolved
- The first of
commentsstarts the thread, and every later one is a reply, indented under it on one unbroken thin line that runs down from the first avatar, branches to each reply's avatar and ends at the last one, drawing itself down as a reply arrives. A hairline sets the head and the reply field off from the thread; in Studio the head is a strip and the reply field sits in a foot strip. The thread keeps no room for replies to come: it eases taller as they arrive and as the agent's words stream in, and the reply field glides down with it. - Typing @ and the start of a handle opens a menu of matching
people, and Enter or a click inserts the handle. - @mentions in plain text comments are highlighted in the accent's tint, limited to known handles when
peopleis given. - Each comment's Agree button shows on hover or keyboard focus, and always on a touch screen. It toggles yours in
agreed, and a chip under the text counts everyone who agreed (agreeson the comment, plus you); the chip toggles yours too, and takes the accent's tint once you have agreed. - A comment with
thinkingshows the thinking dots; anagentcomment's words fade in as itstextgrows. actionsadd buttons under a comment, and settingresolutionreplaces them with a confirmation line like "Applied to 3 frames", a neutral line with a green tick.- Enter or the Send button calls
onSendwith the trimmed reply and clears the field; Send is disabled while the field is empty; in Studio it is a quiet glyph until there is something to send, when the ink button fades in under it. - The reply field has a dimmed edge at rest and a step stronger one while it has the focus, with no ring.
- The Resolve button in the header toggles
resolved: the pin turns green, a green Resolved chip shows beside the title and the reply field folds away. The thread keeps its colours. Pressed again, it reopens the thread.
- The thread is an
aria-live="polite"region, so new comments and replies are announced, and the replies are a group labelled Replies. - The reply field is a
comboboxwitharia-expandedreflecting the mention menu, which is alistboxofoptionrows. - In the mention menu ↑ and ↓ move the highlight and wrap, which
aria-activedescendantpoints to, and Enter picks the highlighted person. - Escape dismisses the mention menu until the text changes.
- Agree and its chip are toggle buttons with
aria-pressed; the chip's label says how many agreed. The Agree button stays in the tab order and shows as soon as it has the focus. - Resolve thread reports its state with
aria-pressed, and the icon-only Send button has anaria-label.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { Comments } from '@/components/designme/comments/Comments';React example
The demo above as a React component, 62 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useCallback, useRef, useState } from 'react';
import { Comments, type CommentsEntry, type CommentsPerson } from './Comments';
import { useStory, useWait } from '../lib/useScript';
/* ---------- Comments: Maya asks the agent in the thread; it thinks, writes its answer, then offers to apply it ---------- */
const AGENT: CommentsPerson = { name: 'Design agent', initials: 'DA', color: 'var(--dm-av-b)', handle: 'agent' };
const MAYA: CommentsPerson = { name: 'Maya Kim', initials: 'MK', color: 'var(--dm-av-l)', handle: 'maya' };
const JON: CommentsPerson = { name: 'Jon Ortiz', initials: 'JO', color: 'var(--dm-av-m)', handle: 'jon' };
const START: CommentsEntry[] = [
{ id: 'c1', author: MAYA, text: 'The secondary button feels too faint next to the CTA.', time: '2h', agrees: 1 },
{ id: 'c2', author: JON, text: 'Agree. Can we keep it outlined though?', time: '1h' }
];
const ASK = '@agent can you keep it outlined but darker?';
export default function CommentsDemo() {
const [comments, setComments] = useState(START);
const [draft, setDraft] = useState('');
const wait = useWait();
const next = useRef(3);
const reply = useCallback(async (q: string) => {
const id = 'c' + next.current++;
const set = (patch: Partial<CommentsEntry>) => setComments(cs => cs.map(c => (c.id === id ? { ...c, ...patch } : c)));
setComments(cs => [...cs, { id, author: AGENT, text: '', time: 'now', agent: true, thinking: true }]);
await wait(900);
set({ thinking: false });
const answer = /outline|border/i.test(q + ' outlined')
? 'Kept it outlined and raised the text to #5B6472, which passes AA at 5.9 : 1. Want me to apply it to the other 2 frames?'
: 'On it. I will post the change here when it is ready.';
let text = '';
for (const w of answer.split(' ')) { text += (text ? ' ' : '') + w; set({ text }); await wait(40); }
set({ actions: [
{ label: 'Apply to all', primary: true, onClick: () => set({ resolution: 'Applied to 3 frames' }) },
{ label: 'Just this one', onClick: () => set({ resolution: 'Applied to frame 2' }) }
] });
}, [wait]);
const send = useCallback((text: string) => {
setComments(cs => [...cs, { id: 'c' + next.current++, author: MAYA, text, time: 'now' }]);
if (/@agent/i.test(text)) reply(text);
}, [reply]);
// Maya types the question a letter at a time, then sends it. Clicking, focusing or typing in it takes over, and what she
// had typed goes
const ref = useRef<HTMLDivElement>(null);
useStory(ref, async ({ wait, taken }) => {
await wait(1000);
taken(() => setDraft(''));
for (let i = 1; i <= ASK.length; i++) { setDraft(ASK.slice(0, i)); await wait(28); }
await wait(300);
setDraft(''); send(ASK);
});
return (
<div ref={ref} style={{ width: '100%' }}>
<Comments title="Pricing, frame 2" comments={comments} people={[AGENT, MAYA, JON]} value={draft} onValueChange={setDraft} onSend={send} />
</div>
);
}
Astro
In a page in src/pages. It plays the demo above; change its comments.js to show your own data. Attributes like class go on its root element.
---
import Comments from '../components/designme/comments/Comments.astro';
---
<Comments />
<Comments data-style="soft" class="my-class" />Props
Everything Comments takes.
| Prop | Type | What it does |
|---|---|---|
titlerequired | string | What the thread is about, like "Pricing, frame 2" |
pin | ReactNode | The number on the pin, like 1 |
commentsrequired | CommentsEntry[] | The thread: the first comment starts it, and every later one is a reply, indented under it |
people | CommentsPerson[] | Who can be @mentioned. Typing @ and the start of a handle opens a menu of them |
value | string | The reply being written. Leave it out to let the field keep it |
defaultValue | string | |
onValueChange | (value: string) => void | |
onSend | (text: string) => void | Called with the reply when it is sent. Add it to `comments` to show it |
placeholder | string | |
resolved | boolean | Whether the thread is resolved: the pin turns green, a Resolved chip shows and the reply field folds away, while the thread keeps its colours. Leave it out to let the Resolve button toggle it |
defaultResolved | boolean | |
onResolvedChange | (resolved: boolean) => void | |
agreed | string[] | The ids of the comments you agreed with. Leave it out to let the Agree buttons keep it |
defaultAgreed | string[] | |
onAgreedChange | (ids: string[]) => void | |
className | string |
Code
The full source, as the CLI installs it.
Comments.tsxReact · 194 lines
'use client';
import { useId, useState, type KeyboardEvent, type ReactNode } from 'react';
import { cx } from '../lib/cx';
import { useControllable } from '../lib/hooks';
import { Icon } from '../lib/icons';
import { Avatar, avatarInk, enter, Think, Tip, useGrow } from '../lib/motion';
import '../designme.css';
// its menus' rows glide in Studio
import '../lib/glide';
import './comments.css';
export interface CommentsPerson {
name: string;
/** Two letters for the avatar, like "MK" */
initials: string;
/** The avatar colour, like 'var(--dm-av-l)' */
color: string;
/** What follows the @ to mention them, like "maya". People with a handle show up in the mention menu */
handle?: string;
}
export interface CommentsAction {
label: string;
/** Draws it as the accent button. The others are white with an outline */
primary?: boolean;
onClick: () => void;
}
export interface CommentsEntry {
/** Keeps the comment in place when the list changes */
id: string;
author: CommentsPerson;
/** The comment. A string gets its @mentions highlighted; an agent's reply fades in word by word as it grows */
text: ReactNode;
/** Like "2h" or "now" */
time: string;
/** Marks the agent's replies: their words fade in as `text` grows */
agent?: boolean;
/** Shows the thinking mark instead of the text while the agent works on a reply */
thinking?: boolean;
/** Buttons under the comment, like "Apply to all" */
actions?: CommentsAction[];
/** Replaces the buttons once one is used, like "Applied to 3 frames" */
resolution?: string;
/** How many other people agreed with it. Yours is added on top when you agree */
agrees?: number;
}
export interface CommentsProps {
/** What the thread is about, like "Pricing, frame 2" */
title: string;
/** The number on the pin, like 1 */
pin?: ReactNode;
/** The thread: the first comment starts it, and every later one is a reply, indented under it */
comments: CommentsEntry[];
/** Who can be @mentioned. Typing @ and the start of a handle opens a menu of them */
people?: CommentsPerson[];
/** The reply being written. Leave it out to let the field keep it */
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
/** Called with the reply when it is sent. Add it to `comments` to show it */
onSend?: (text: string) => void;
placeholder?: string;
/** Whether the thread is resolved: the pin turns green, a Resolved chip shows and the reply field folds away, while the
thread keeps its colours. Leave it out to let the Resolve button toggle it */
resolved?: boolean;
defaultResolved?: boolean;
onResolvedChange?: (resolved: boolean) => void;
/** The ids of the comments you agreed with. Leave it out to let the Agree buttons keep it */
agreed?: string[];
defaultAgreed?: string[];
onAgreedChange?: (ids: string[]) => void;
className?: string;
}
/** Highlights @handles. With people given, only theirs; otherwise any @word */
function mentions(text: string, handles: string[] | null) {
return text.split(/(@\w+)/).map((part, i) => {
const hit = part.startsWith('@') && (!handles || handles.includes(part.slice(1).toLowerCase()));
return hit ? <span key={i} className="dm-m">{part}</span> : part;
});
}
function Comment({ c, handles, mine, onAgree }: { c: CommentsEntry; handles: string[] | null; mine: boolean; onAgree: () => void }) {
const e = enter();
let body: ReactNode = c.text;
if (c.thinking) body = <Think />;
else if (c.agent && typeof c.text === 'string') body = c.text.split(' ').map((w, i) => <span key={i} className="dm-w">{w} </span>);
else if (typeof c.text === 'string') body = mentions(c.text, handles);
const n = (c.agrees ?? 0) + (mine ? 1 : 0);
return (
<div className={cx('dm-cmx-c', c.agent && 'dm-ag', e.className)} style={e.style}>
<Avatar initials={c.author.initials} color={c.author.color} />
<div className="dm-b">
<div className="dm-n">
<b>{c.author.name}</b><span className="dm-t">{c.time}</span>
{/* the quiet Agree button shows on hover or keyboard focus, and always on a touch screen */}
<div className="dm-cmx-tools">
<Tip label="Agree"><button type="button" className="dm-ib dm-cmx-rx" aria-label="Agree" aria-pressed={mine} onClick={onAgree}><Icon name="up-thumb" size="xs" /></button></Tip>
</div>
</div>
<div className="dm-tx" style={c.thinking ? { color: 'var(--dm-accent-mark, var(--dm-accent))' } : undefined}>{body}</div>
{n > 0 && (
<div className="dm-cmx-rs">
<button type="button" className="dm-cmx-rc" aria-pressed={mine} aria-label={'Agree, ' + n + (n === 1 ? ' person' : ' people') + (mine ? ', including you' : '')} onClick={onAgree}>
<Icon name="up-thumb" size="xs" /><span className="dm-num">{n}</span>
</button>
</div>
)}
{(c.resolution || !!c.actions?.length) && (
<div className={cx('dm-act', e.className)}>
{c.resolution
? <span className="dm-cmx-rv dm-enter"><Icon name="ok" size="xs" />{c.resolution}</span>
: c.actions!.map((a, i) => <button type="button" key={i} className={cx('dm-pill dm-sm', a.primary ? 'dm-primary' : 'dm-line')} onClick={a.onClick}>{a.label}</button>)}
</div>
)}
</div>
</div>
);
}
/** A comment thread on a design, where you can @mention the agent and it replies. */
export function Comments({ title, pin = 1, comments, people, value, defaultValue = '', onValueChange, onSend, placeholder = 'Reply, or @agent to ask', resolved, defaultResolved = false, onResolvedChange, agreed, defaultAgreed = [], onAgreedChange, className }: CommentsProps) {
const [draft, setDraft] = useControllable(value, defaultValue, onValueChange);
const [done, setDone] = useControllable(resolved, defaultResolved, onResolvedChange);
const [yes, setYes] = useControllable(agreed, defaultAgreed, onAgreedChange);
const handles = people ? people.flatMap(p => (p.handle ? [p.handle.toLowerCase()] : [])) : null;
const agree = (id: string) => setYes(yes.includes(id) ? yes.filter(x => x !== id) : [...yes, id]);
// typing @ and the start of a handle offers the people it could be; Escape puts the menu away until the text changes
const [dismissed, setDismissed] = useState<string | null>(null);
const typed = draft.match(/@(\w*)$/);
const matches = typed ? (people ?? []).filter(p => p.handle?.toLowerCase().startsWith(typed[1].toLowerCase())) : [];
const menuOpen = matches.length > 0 && dismissed !== draft;
const pick = (p: CommentsPerson) => setDraft(draft.replace(/@\w*$/, '@' + p.handle + ' '));
// the highlighted person: the up and down arrows move it and wrap, and it starts on the first whenever the list changes
const [hl, setHl] = useState({ at: 0, for: '' });
const at = hl.for === draft ? Math.min(hl.at, matches.length - 1) : 0;
const id = useId();
const send = () => { const v = draft.trim(); if (!v) return; setDraft(''); onSend?.(v); };
const key = (e: KeyboardEvent<HTMLInputElement>) => {
if (menuOpen && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); setHl({ at: (at + (e.key === 'ArrowDown' ? 1 : -1) + matches.length) % matches.length, for: draft }); return; }
if (e.key === 'Enter') { e.preventDefault(); if (menuOpen) pick(matches[at]); else send(); }
if (e.key === 'Escape') setDismissed(draft);
};
const [head, ...replies] = comments;
const one = (c: CommentsEntry) => <Comment key={c.id} c={c} handles={handles} mine={yes.includes(c.id)} onAgree={() => agree(c.id)} />;
// the thread keeps no room for replies to come: it eases taller as they arrive and as the agent's words stream in, and the
// reply field under it glides down with it
const [thRoot, thInner] = useGrow();
return (
<div data-dm="" className={cx('dm-cmx dm-panel', done && 'dm-done', className)}>
<div className="dm-cmx-h">
<span className="dm-cmx-pin" aria-hidden="true">{pin}</span>
<b>{title}</b>
{/* the head says nothing the thread already shows (no count of the replies); once resolved, a green chip says so */}
<span className="dm-cmx-st">{done && <span className="dm-tag dm-ok dm-enter">Resolved</span>}</span>
<Tip label={done ? 'Reopen thread' : 'Resolve thread'}>
<button type="button" className="dm-ib dm-cmx-res" aria-label="Resolve thread" aria-pressed={done} onClick={() => setDone(!done)}>
<Icon name={done ? 'undo' : 'check'} size="xs" />
</button>
</Tip>
</div>
<div ref={thRoot} className="dm-cmx-th dm-growing" aria-live="polite">
<div ref={thInner} className="dm-grow">
{head && one(head)}
{replies.length > 0 && <div className="dm-cmx-rp" role="group" aria-label="Replies">{replies.map(one)}</div>}
</div>
</div>
<div className="dm-cmx-in" inert={done}>
<div className="dm-cmx-box">
<input placeholder={placeholder} aria-label="Reply" spellCheck={false} autoComplete="off" value={draft} onChange={e => setDraft(e.target.value)} onKeyDown={key}
role="combobox" aria-expanded={menuOpen} aria-autocomplete="list" aria-controls={`${id}-men`} aria-activedescendant={menuOpen ? `${id}-${at}` : undefined} />
<button type="button" className="dm-cmx-go" aria-label="Send" disabled={!draft.trim()} onClick={send}><Icon name="up" size="xs" /></button>
</div>
<div className={cx('dm-pop dm-cmx-men', menuOpen && 'dm-open')} role="listbox" id={`${id}-men`} aria-label="Mention" inert={!menuOpen}>
{matches.map((p, i) => (
// mousedown, so the field keeps its focus
<button type="button" key={p.handle} id={`${id}-${i}`} tabIndex={-1} className={cx('dm-mi', i === at && 'dm-hl')} role="option" aria-selected={i === at}
onMouseEnter={() => setHl({ at: i, for: draft })} onMouseDown={e => { e.preventDefault(); pick(p); }}>
<span className="dm-av" style={{ background: p.color, color: avatarInk(p.color), width: 20, height: 20, fontSize: 9 }} aria-hidden="true">{p.initials}</span>
<span>{p.name}<span className="dm-d">@{p.handle}</span></span>
</button>
))}
</div>
</div>
</div>
);
}
comments.cssReact · 110 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Comments ---------- */
/* a thread on one spot of a design: the first comment, then its replies indented on a thin line. Each comment is an avatar,
a name, a time and the text; its Agree button shows on hover or keyboard focus (always, on a touch screen). The card's
content is 16px from every edge in every style, and it keeps no room for replies still to come: it grows as they arrive
(grow()) and stays centred in its stage (owner, 17 and 18 Nov). Hovers are a quiet fill that shows in light mode too */
.dm-cmx{padding:var(--dm-s-4);display:flex;flex-direction:column;gap:var(--dm-s-4);--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
/* the head sits on the comments' columns: the pin centred in the avatars' 24px column, the title where their words start,
and Resolve's glyph on the right edge the Send button ends on, its hover box reaching out round it */
.dm-cmx-h{display:flex;align-items:center;gap:var(--dm-s-3);min-height:20px;padding-bottom:var(--dm-s-4);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:13.5px;line-height:20px}
.dm-cmx-h b{font-weight:500}
.dm-cmx-st{flex:1;min-width:0;display:flex}
.dm-cmx-pin{width:20px;height:20px;margin:0 2px;border-radius:50% 50% 50% var(--dm-r-xs);background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;font-size:11px;font-weight:500;flex:none;transition:background var(--dm-t)}
.dm-cmx.dm-done .dm-cmx-pin{background:var(--dm-ok);color:var(--dm-surface)}
/* the resolve button is the library's icon button as it is (30px, its own colour), its box 16px in from the card's top and
right edges like every control in a head (check-rules R1 and R7, 27 Nov), so the head is as tall as it */
.dm-cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 50%,var(--dm-surface));display:flex;flex-direction:column;gap:var(--dm-s-4);flex:1}
/* dark: the rail is close to the surface already, so the line keeps more of it to stay visible */
:root[data-theme="dark"] .dm-cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 80%,var(--dm-surface))}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]) .dm-cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 80%,var(--dm-surface))}}
/* a reply's avatar starts where the words of the comment it answers start (12px + 24px in), so the thread keeps one column */
.dm-cmx-rp{--dm-cmx-x:calc(-1 * var(--dm-s-6) - .75px);display:flex;flex-direction:column;gap:var(--dm-s-4);margin-left:var(--dm-s-3);padding-left:var(--dm-s-6);position:relative}
/* one unbroken line (owner, 21 Nov: "these lines are not connected"): it starts just below the first comment's avatar,
centred under it, and runs straight down to the last reply's branch, where it ends. Every piece of it is drawn the same
way, a 1.5px left border at the same x, and each piece overlaps the next, so they meet with no seam */
:is(.dm-cmx-th,.dm-cmx-th>.dm-grow)>.dm-cmx-c:first-child{position:relative}
:is(.dm-cmx-th,.dm-cmx-th>.dm-grow)>.dm-cmx-c:first-child:has(+ .dm-cmx-rp)::before{content:'';position:absolute;width:0;border-left:1.5px solid var(--dm-cmx-ln);pointer-events:none;left:calc(var(--dm-s-3) - .75px);top:calc(24px + var(--dm-s-1));bottom:calc(-1 * var(--dm-s-4))}
/* each reply: a branch leaves the line and turns into its avatar's centre (rounded in Soft and Studio, square in Blueprint);
under every reply but the last the line carries straight on past the branch, and as a reply arrives the line draws itself
down to it */
.dm-cmx-rp>.dm-cmx-c{position:relative}
.dm-cmx-rp>.dm-cmx-c .dm-av{position:relative;z-index:1}
.dm-cmx-rp>.dm-cmx-c::before{content:'';position:absolute;left:var(--dm-cmx-x);top:calc(-1 * var(--dm-s-4));width:calc(var(--dm-s-6) + 1.75px);height:calc(var(--dm-s-4) + 12.75px);box-sizing:border-box;border-left:1.5px solid var(--dm-cmx-ln);border-bottom:1.5px solid var(--dm-cmx-ln);border-bottom-left-radius:10px;corner-shape:round;pointer-events:none}
.dm-cmx-rp>.dm-cmx-c:not(:last-child)::after{content:'';position:absolute;left:var(--dm-cmx-x);top:0;bottom:calc(-1 * var(--dm-s-4));width:0;border-left:1.5px solid var(--dm-cmx-ln);pointer-events:none;transform-origin:top;animation:dm-cmxrl var(--dm-t) var(--dm-ease) both}
@keyframes dm-cmxrl{from{transform:scaleY(0)}}
:root:not([data-style="soft"],[data-style="studio"]) .dm-cmx-rp>.dm-cmx-c:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::before{border-bottom-left-radius:0}
.dm-cmx-c{display:flex;gap:var(--dm-s-3);min-width:0}
.dm-cmx-c .dm-av{width:24px;height:24px;font-size:10px}
.dm-cmx-c .dm-b{flex:1;display:flex;flex-direction:column;min-width:0}
.dm-cmx-c .dm-n{display:flex;align-items:center;gap:var(--dm-s-2);height:24px;font-size:13px}
.dm-cmx-c .dm-n b{font-weight:500;white-space:nowrap}
.dm-cmx-c .dm-n .dm-t{font-size:12px;color:var(--dm-muted)}
.dm-cmx-c .dm-tx{font-size:13.5px;line-height:1.5;color:var(--dm-fg);overflow-wrap:anywhere}
/* an @mention: the accent's text on its tint, the tint reaching out round the word so the word stays on the text's column */
.dm-cmx-c .dm-m{color:var(--dm-accent-fg);background:var(--dm-sel);border-radius:var(--dm-r-xs);padding:0 2px;margin:0 -2px}
.dm-cmx-c.dm-ag .dm-tx .dm-w{animation:dm-cmw .4s var(--dm-ease) both}
@keyframes dm-cmw{from{opacity:0;filter:blur(3px)}to{opacity:1;filter:none}}
/* the agent's buttons wrap before they reach the column's right edge, so on a phone they never end a few pixels short of the
edge Send and Resolve end on */
.dm-cmx-c .dm-act{display:flex;flex-wrap:wrap;gap:var(--dm-s-2);margin-top:var(--dm-s-2);max-width:calc(100% - var(--dm-s-6))}
/* the quiet Agree button beside the time, its glyph on the same right edge as Resolve's */
.dm-cmx-tools{margin-left:auto;margin-right:-2px;display:flex;gap:var(--dm-s-1);transition:opacity var(--dm-t-fast)}
.dm-cmx-tools .dm-ib{width:26px;height:26px;color:var(--dm-muted)}
.dm-cmx-tools .dm-ib[aria-pressed="true"]{color:var(--dm-accent-fg)}
@media (hover:hover) and (pointer:fine){.dm-cmx-tools{opacity:0}}
.dm-cmx-c .dm-n:focus-within .dm-cmx-tools{opacity:1}
@media (hover:hover) and (pointer:fine){.dm-cmx-c:hover .dm-cmx-tools{opacity:1}}
/* how many agreed: a small chip under the text. Hovered it takes a quiet fill; once you have agreed it takes the accent's
tint with the accent's text, as a reaction of yours does (owner, 20 Nov: hover and selected are a quiet, deeper fill) */
.dm-cmx-rs{display:flex;margin-top:var(--dm-s-2)}
.dm-cmx-rs:has(.dm-cmx-rc[hidden]){display:none}
.dm-cmx-rc{display:inline-flex;align-items:center;gap:var(--dm-s-1);height:22px;padding:0 var(--dm-s-2);border-radius:var(--dm-r-pill);font-size:12px;color:var(--dm-fg2);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-line) 50%,transparent);transition:background-color var(--dm-t-fast),box-shadow var(--dm-t-fast),color var(--dm-t-fast)}
@media (hover:hover) and (pointer:fine){.dm-cmx-rc:hover{background:color-mix(in srgb,var(--dm-fg) 5%,var(--dm-surface))}}
/* in dark mode 5% barely shows on the dark surface, so the hover takes a step more (check-rules R6, 27 Nov) */
@media (prefers-color-scheme:dark){@media (hover:hover) and (pointer:fine){:root:not([data-theme="light"]) .dm-cmx-rc:not([aria-pressed="true"]):hover{background:color-mix(in srgb,var(--dm-fg) 9%,var(--dm-surface))}}}
@media (hover:hover) and (pointer:fine){:root[data-theme="dark"] .dm-cmx-rc:not([aria-pressed="true"]):hover{background:color-mix(in srgb,var(--dm-fg) 9%,var(--dm-surface))}}
.dm-cmx-rc[aria-pressed="true"]{color:var(--dm-accent-fg);background:var(--dm-accent-bg);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-accent-mark) 25%,transparent)}
@media (hover:hover) and (pointer:fine){.dm-cmx-rc[aria-pressed="true"]:hover{background:linear-gradient(color-mix(in srgb,var(--dm-fg) 4%,transparent),color-mix(in srgb,var(--dm-fg) 4%,transparent)),var(--dm-accent-bg)}}
/* the reply field: a dimmed edge at rest, one step stronger while it has the focus, and no ring. A half-strength hairline
sets it off from the thread, as one sets the head off (owner, 21 Nov) */
.dm-cmx-in{position:relative;display:grid;grid-template-rows:minmax(0,1fr);padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);transition:grid-template-rows var(--dm-t) var(--dm-ease),margin var(--dm-t) var(--dm-ease),padding var(--dm-t) var(--dm-ease),border-width var(--dm-t) var(--dm-ease),opacity var(--dm-t-fast) var(--dm-ease),visibility 0s}
.dm-cmx-box{display:flex;align-items:center;gap:6px;height:var(--dm-field-h);padding:0 5px 0 var(--dm-s-3);border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.dm-cmx-box{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.dm-cmx-box:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.dm-cmx-box input{flex:1;min-width:0;border:0;outline:0;background:transparent;font:inherit;font-size:13.5px;color:var(--dm-fg)}
.dm-cmx-box input::placeholder{color:var(--dm-muted)}
.dm-cmx-go{width:30px;height:30px;border-radius:50%;background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;flex:none;transition:background var(--dm-t-fast),transform .15s}
@media (hover:hover) and (pointer:fine){.dm-cmx-go:hover{background:var(--dm-accent-2)}}
.dm-cmx-go[disabled]{opacity:1;cursor:not-allowed;background:var(--dm-dis-hatch),var(--dm-dis-fill);color:var(--dm-dis);box-shadow:var(--dm-soft-ring);transform:none}
@media (hover:hover) and (pointer:fine){.dm-cmx-go[disabled]:hover{opacity:1;cursor:not-allowed;background:var(--dm-dis-hatch),var(--dm-dis-fill);color:var(--dm-dis);box-shadow:var(--dm-soft-ring);transform:none}}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink Send alone presses */
.dm-cmx :is(.dm-ib,.dm-pill,.dm-cmx-go,.dm-cmx-rc):active,:root[data-style="studio"] .dm-cmx .dm-ib:active,:root [data-style="studio"] .dm-cmx .dm-ib:active,:root [data-style="studio"].dm-cmx .dm-ib:active{transform:none}
/* the mention list opens upward from the field, over the thread */
.dm-cmx-men{bottom:46px;left:0;min-width:210px;--dm-origin:bottom left}
/* resolved: the thread stays as it is, in full colour (owner, 20 Nov: nothing fades to say it is past), the pin turns green,
a green Resolved chip says so, and the reply field folds away while the card eases to its new height; Reopen brings it back */
.dm-cmx.dm-done .dm-cmx-in{grid-template-rows:minmax(0,0fr);margin-top:calc(-1 * var(--dm-s-4));padding-top:0;border-top-width:0;opacity:0;overflow:hidden;visibility:hidden;transition:grid-template-rows var(--dm-t) var(--dm-ease),margin var(--dm-t) var(--dm-ease),padding var(--dm-t) var(--dm-ease),border-width var(--dm-t) var(--dm-ease),opacity var(--dm-t-fast) var(--dm-ease),visibility 0s var(--dm-t)}
@media (prefers-reduced-motion:reduce){.dm-cmx-in{transition:none!important}.dm-cmx-rp>.dm-cmx-c::after{animation:none}}
.dm-cmx-st .dm-tag{margin-left:calc(-1 * var(--dm-s-1))}
/* the agent's change applied: a neutral line with the green tick (owner, 18 Nov: a finished state has no green words or fill) */
.dm-cmx-rv{font-size:12.5px;line-height:28px;color:var(--dm-fg2);display:flex;align-items:center;gap:6px}
.dm-cmx-rv svg{color:var(--dm-ok-mark)}
:root:not([data-style="soft"],[data-style="studio"]) .dm-cmx-c .dm-m:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:inset 0 -1px 0 var(--dm-accent-mark)}
/* Studio: the head is a strip, its controls on the content's 16px column, and the reply field sits in a foot strip that folds
away with it once the thread is resolved (owner, 21 Nov). Send is the field's own Send (see the Studio section): 5px from
the field's edges, its corners the field's less those 5px. The agent's words fade in without a blur */
:root[data-style="studio"] .dm-cmx-h,:root [data-style="studio"] .dm-cmx-h,:root [data-style="studio"].dm-cmx-h{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) 0;padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .dm-cmx-res,:root [data-style="studio"] .dm-cmx-res,:root [data-style="studio"].dm-cmx-res{margin:0}
:root[data-style="studio"] .dm-cmx-in,:root [data-style="studio"] .dm-cmx-in,:root [data-style="studio"].dm-cmx-in{margin:0 calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4));padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .dm-cmx.dm-done .dm-cmx-in,:root [data-style="studio"] .dm-cmx.dm-done .dm-cmx-in,:root [data-style="studio"].dm-cmx.dm-done .dm-cmx-in{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) 0;padding-block:0;border-top-width:0}
/* Agree, once agreed, sits on Studio's selected fill in its round shape, as a rated thumb does (owner, 23 Nov) */
:root[data-style="studio"] .dm-cmx-tools .dm-ib[aria-pressed="true"],:root [data-style="studio"] .dm-cmx-tools .dm-ib[aria-pressed="true"],:root [data-style="studio"].dm-cmx-tools .dm-ib[aria-pressed="true"]{background:var(--dm-row-on)}
:root[data-style="studio"] .dm-cmx-men,:root [data-style="studio"] .dm-cmx-men,:root [data-style="studio"].dm-cmx-men{bottom:54px;left:var(--dm-s-4)}
:root[data-style="studio"] .dm-cmx-go,:root [data-style="studio"] .dm-cmx-go,:root [data-style="studio"].dm-cmx-go{border-radius:calc(var(--dm-r-field) - 5px)}
:root[data-style="studio"] .dm-cmx-c.dm-ag .dm-tx .dm-w,:root [data-style="studio"] .dm-cmx-c.dm-ag .dm-tx .dm-w,:root [data-style="studio"].dm-cmx-c.dm-ag .dm-tx .dm-w{animation:dm-cmwc var(--dm-t-slow) var(--dm-ease) both}
/* the reaction chip keeps its quiet edge and takes the one hover as a fill (owner, 21 Nov) */
:root[data-style="studio"] .dm-cmx-rc,:root [data-style="studio"] .dm-cmx-rc,:root [data-style="studio"].dm-cmx-rc{transition:background-color var(--dm-t-fast) var(--dm-ease),box-shadow var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-cmx-rc:not([aria-pressed="true"]):hover,:root [data-style="studio"] .dm-cmx-rc:not([aria-pressed="true"]):hover,:root [data-style="studio"].dm-cmx-rc:not([aria-pressed="true"]):hover{background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-line) 50%,transparent),inset 0 0 0 99px var(--dm-row)}}
@keyframes dm-cmwc{from{opacity:0}to{opacity:1}}
Comments.astroAstro · 28 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Comments: A design thread where you can @mention the agent and it replies.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change comments.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './comments.css';
export interface Props extends HTMLAttributes<'div'> {
/** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="comments" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="cmx panel">
<div class="cmx-h"><span class="cmx-pin" aria-hidden="true">1</span><b>Pricing, frame 2</b><span class="cmx-st num"></span><button class="ib cmx-res" aria-label="Resolve thread" aria-pressed="false" data-tip="Resolve thread"><svg class="i xs"><use href="#i-check"/></svg></button></div>
<div class="cmx-th" aria-live="polite"></div>
<div class="cmx-in"><div class="cmx-box"><input placeholder="Reply, or @agent to ask" aria-label="Reply" spellcheck="false" autocomplete="off"><button class="cmx-go" aria-label="Send" disabled><svg class="i xs"><use href="#i-up"/></svg></button></div><div class="pop cmx-men" role="listbox"></div></div>
</div>
</Fragment></div>
</div>
<script>
import './comments.js';
</script>
comments.htmlHTML · 10 lines
<div class="card" data-c="comments">
<div class="stage-in">
<div class="cmx panel">
<div class="cmx-h"><span class="cmx-pin" aria-hidden="true">1</span><b>Pricing, frame 2</b><span class="cmx-st num"></span><button class="ib cmx-res" aria-label="Resolve thread" aria-pressed="false" data-tip="Resolve thread"><svg class="i xs"><use href="#i-check"/></svg></button></div>
<div class="cmx-th" aria-live="polite"></div>
<div class="cmx-in"><div class="cmx-box"><input placeholder="Reply, or @agent to ask" aria-label="Reply" spellcheck="false" autocomplete="off"><button class="cmx-go" aria-label="Send" disabled><svg class="i xs"><use href="#i-up"/></svg></button></div><div class="pop cmx-men" role="listbox"></div></div>
</div>
</div>
</div>
comments.cssHTML · 109 lines
/* ---------- Comments ---------- */
/* a thread on one spot of a design: the first comment, then its replies indented on a thin line. Each comment is an avatar,
a name, a time and the text; its Agree button shows on hover or keyboard focus (always, on a touch screen). The card's
content is 16px from every edge in every style, and it keeps no room for replies still to come: it grows as they arrive
(grow()) and stays centred in its stage (owner, 17 and 18 Nov). Hovers are a quiet fill that shows in light mode too */
.cmx{padding:var(--dm-s-4);display:flex;flex-direction:column;gap:var(--dm-s-4);--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
/* the head sits on the comments' columns: the pin centred in the avatars' 24px column, the title where their words start,
and Resolve's glyph on the right edge the Send button ends on, its hover box reaching out round it */
.cmx-h{display:flex;align-items:center;gap:var(--dm-s-3);min-height:20px;padding-bottom:var(--dm-s-4);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:13.5px;line-height:20px}
.cmx-h b{font-weight:500}
.cmx-st{flex:1;min-width:0;display:flex}
.cmx-pin{width:20px;height:20px;margin:0 2px;border-radius:50% 50% 50% var(--dm-r-xs);background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;font-size:11px;font-weight:500;flex:none;transition:background var(--dm-t)}
.cmx.done .cmx-pin{background:var(--dm-ok);color:var(--dm-surface)}
/* the resolve button is the library's icon button as it is (30px, its own colour), its box 16px in from the card's top and
right edges like every control in a head (check-rules R1 and R7, 27 Nov), so the head is as tall as it */
.cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 50%,var(--dm-surface));display:flex;flex-direction:column;gap:var(--dm-s-4);flex:1}
/* dark: the rail is close to the surface already, so the line keeps more of it to stay visible */
:root[data-theme="dark"] .cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 80%,var(--dm-surface))}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]) .cmx-th{--dm-cmx-ln:color-mix(in srgb,var(--dm-rail) 80%,var(--dm-surface))}}
/* a reply's avatar starts where the words of the comment it answers start (12px + 24px in), so the thread keeps one column */
.cmx-rp{--dm-cmx-x:calc(-1 * var(--dm-s-6) - .75px);display:flex;flex-direction:column;gap:var(--dm-s-4);margin-left:var(--dm-s-3);padding-left:var(--dm-s-6);position:relative}
/* one unbroken line (owner, 21 Nov: "these lines are not connected"): it starts just below the first comment's avatar,
centred under it, and runs straight down to the last reply's branch, where it ends. Every piece of it is drawn the same
way, a 1.5px left border at the same x, and each piece overlaps the next, so they meet with no seam */
:is(.cmx-th,.cmx-th>.dm-grow)>.cmx-c:first-child{position:relative}
:is(.cmx-th,.cmx-th>.dm-grow)>.cmx-c:first-child:has(+ .cmx-rp)::before{content:'';position:absolute;width:0;border-left:1.5px solid var(--dm-cmx-ln);pointer-events:none;left:calc(var(--dm-s-3) - .75px);top:calc(24px + var(--dm-s-1));bottom:calc(-1 * var(--dm-s-4))}
/* each reply: a branch leaves the line and turns into its avatar's centre (rounded in Soft and Studio, square in Blueprint);
under every reply but the last the line carries straight on past the branch, and as a reply arrives the line draws itself
down to it */
.cmx-rp>.cmx-c{position:relative}
.cmx-rp>.cmx-c .av{position:relative;z-index:1}
.cmx-rp>.cmx-c::before{content:'';position:absolute;left:var(--dm-cmx-x);top:calc(-1 * var(--dm-s-4));width:calc(var(--dm-s-6) + 1.75px);height:calc(var(--dm-s-4) + 12.75px);box-sizing:border-box;border-left:1.5px solid var(--dm-cmx-ln);border-bottom:1.5px solid var(--dm-cmx-ln);border-bottom-left-radius:10px;corner-shape:round;pointer-events:none}
.cmx-rp>.cmx-c:not(:last-child)::after{content:'';position:absolute;left:var(--dm-cmx-x);top:0;bottom:calc(-1 * var(--dm-s-4));width:0;border-left:1.5px solid var(--dm-cmx-ln);pointer-events:none;transform-origin:top;animation:cmxrl var(--dm-t) var(--dm-ease) both}
@keyframes cmxrl{from{transform:scaleY(0)}}
:root:not([data-style="soft"],[data-style="studio"]) .cmx-rp>.cmx-c:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::before{border-bottom-left-radius:0}
.cmx-c{display:flex;gap:var(--dm-s-3);min-width:0}
.cmx-c .av{width:24px;height:24px;font-size:10px}
.cmx-c .b{flex:1;display:flex;flex-direction:column;min-width:0}
.cmx-c .n{display:flex;align-items:center;gap:var(--dm-s-2);height:24px;font-size:13px}
.cmx-c .n b{font-weight:500;white-space:nowrap}
.cmx-c .n .t{font-size:12px;color:var(--dm-muted)}
.cmx-c .tx{font-size:13.5px;line-height:1.5;color:var(--dm-fg);overflow-wrap:anywhere}
/* an @mention: the accent's text on its tint, the tint reaching out round the word so the word stays on the text's column */
.cmx-c .m{color:var(--dm-accent-fg);background:var(--dm-sel);border-radius:var(--dm-r-xs);padding:0 2px;margin:0 -2px}
.cmx-c.ag .tx .w{animation:cmw .4s var(--dm-ease) both}
@keyframes cmw{from{opacity:0;filter:blur(3px)}to{opacity:1;filter:none}}
/* the agent's buttons wrap before they reach the column's right edge, so on a phone they never end a few pixels short of the
edge Send and Resolve end on */
.cmx-c .act{display:flex;flex-wrap:wrap;gap:var(--dm-s-2);margin-top:var(--dm-s-2);max-width:calc(100% - var(--dm-s-6))}
/* the quiet Agree button beside the time, its glyph on the same right edge as Resolve's */
.cmx-tools{margin-left:auto;margin-right:-2px;display:flex;gap:var(--dm-s-1);transition:opacity var(--dm-t-fast)}
.cmx-tools .ib{width:26px;height:26px;color:var(--dm-muted)}
.cmx-tools .ib[aria-pressed="true"]{color:var(--dm-accent-fg)}
@media (hover:hover) and (pointer:fine){.cmx-tools{opacity:0}}
.cmx-c .n:focus-within .cmx-tools{opacity:1}
@media (hover:hover) and (pointer:fine){.cmx-c:hover .cmx-tools{opacity:1}}
/* how many agreed: a small chip under the text. Hovered it takes a quiet fill; once you have agreed it takes the accent's
tint with the accent's text, as a reaction of yours does (owner, 20 Nov: hover and selected are a quiet, deeper fill) */
.cmx-rs{display:flex;margin-top:var(--dm-s-2)}
.cmx-rs:has(.cmx-rc[hidden]){display:none}
.cmx-rc{display:inline-flex;align-items:center;gap:var(--dm-s-1);height:22px;padding:0 var(--dm-s-2);border-radius:var(--dm-r-pill);font-size:12px;color:var(--dm-fg2);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-line) 50%,transparent);transition:background-color var(--dm-t-fast),box-shadow var(--dm-t-fast),color var(--dm-t-fast)}
@media (hover:hover) and (pointer:fine){.cmx-rc:hover{background:color-mix(in srgb,var(--dm-fg) 5%,var(--dm-surface))}}
/* in dark mode 5% barely shows on the dark surface, so the hover takes a step more (check-rules R6, 27 Nov) */
@media (prefers-color-scheme:dark){@media (hover:hover) and (pointer:fine){:root:not([data-theme="light"]) .cmx-rc:not([aria-pressed="true"]):hover{background:color-mix(in srgb,var(--dm-fg) 9%,var(--dm-surface))}}}
@media (hover:hover) and (pointer:fine){:root[data-theme="dark"] .cmx-rc:not([aria-pressed="true"]):hover{background:color-mix(in srgb,var(--dm-fg) 9%,var(--dm-surface))}}
.cmx-rc[aria-pressed="true"]{color:var(--dm-accent-fg);background:var(--dm-accent-bg);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-accent-mark) 25%,transparent)}
@media (hover:hover) and (pointer:fine){.cmx-rc[aria-pressed="true"]:hover{background:linear-gradient(color-mix(in srgb,var(--dm-fg) 4%,transparent),color-mix(in srgb,var(--dm-fg) 4%,transparent)),var(--dm-accent-bg)}}
/* the reply field: a dimmed edge at rest, one step stronger while it has the focus, and no ring. A half-strength hairline
sets it off from the thread, as one sets the head off (owner, 21 Nov) */
.cmx-in{position:relative;display:grid;grid-template-rows:minmax(0,1fr);padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);transition:grid-template-rows var(--dm-t) var(--dm-ease),margin var(--dm-t) var(--dm-ease),padding var(--dm-t) var(--dm-ease),border-width var(--dm-t) var(--dm-ease),opacity var(--dm-t-fast) var(--dm-ease),visibility 0s}
.cmx-box{display:flex;align-items:center;gap:6px;height:var(--dm-field-h);padding:0 5px 0 var(--dm-s-3);border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.cmx-box{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.cmx-box:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.cmx-box input{flex:1;min-width:0;border:0;outline:0;background:transparent;font:inherit;font-size:13.5px;color:var(--dm-fg)}
.cmx-box input::placeholder{color:var(--dm-muted)}
.cmx-go{width:30px;height:30px;border-radius:50%;background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;flex:none;transition:background var(--dm-t-fast),transform .15s}
@media (hover:hover) and (pointer:fine){.cmx-go:hover{background:var(--dm-accent-2)}}
.cmx-go[disabled]{opacity:1;cursor:not-allowed;background:var(--dm-dis-hatch),var(--dm-dis-fill);color:var(--dm-dis);box-shadow:var(--dm-soft-ring);transform:none}
@media (hover:hover) and (pointer:fine){.cmx-go[disabled]:hover{opacity:1;cursor:not-allowed;background:var(--dm-dis-hatch),var(--dm-dis-fill);color:var(--dm-dis);box-shadow:var(--dm-soft-ring);transform:none}}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink Send alone presses */
.cmx :is(.ib,.pill,.cmx-go,.cmx-rc):active,:root[data-style="studio"] .cmx .ib:active,:root [data-style="studio"] .cmx .ib:active,:root [data-style="studio"].cmx .ib:active{transform:none}
/* the mention list opens upward from the field, over the thread */
.cmx-men{bottom:46px;left:0;min-width:210px;--dm-origin:bottom left}
/* resolved: the thread stays as it is, in full colour (owner, 20 Nov: nothing fades to say it is past), the pin turns green,
a green Resolved chip says so, and the reply field folds away while the card eases to its new height; Reopen brings it back */
.cmx.done .cmx-in{grid-template-rows:minmax(0,0fr);margin-top:calc(-1 * var(--dm-s-4));padding-top:0;border-top-width:0;opacity:0;overflow:hidden;visibility:hidden;transition:grid-template-rows var(--dm-t) var(--dm-ease),margin var(--dm-t) var(--dm-ease),padding var(--dm-t) var(--dm-ease),border-width var(--dm-t) var(--dm-ease),opacity var(--dm-t-fast) var(--dm-ease),visibility 0s var(--dm-t)}
@media (prefers-reduced-motion:reduce){.cmx-in{transition:none!important}.cmx-rp>.cmx-c::after{animation:none}}
.cmx-st .tag{margin-left:calc(-1 * var(--dm-s-1))}
/* the agent's change applied: a neutral line with the green tick (owner, 18 Nov: a finished state has no green words or fill) */
.cmx-rv{font-size:12.5px;line-height:28px;color:var(--dm-fg2);display:flex;align-items:center;gap:6px}
.cmx-rv svg{color:var(--dm-ok-mark)}
:root:not([data-style="soft"],[data-style="studio"]) .cmx-c .m:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:inset 0 -1px 0 var(--dm-accent-mark)}
/* Studio: the head is a strip, its controls on the content's 16px column, and the reply field sits in a foot strip that folds
away with it once the thread is resolved (owner, 21 Nov). Send is the field's own Send (see the Studio section): 5px from
the field's edges, its corners the field's less those 5px. The agent's words fade in without a blur */
:root[data-style="studio"] .cmx-h,:root [data-style="studio"] .cmx-h,:root [data-style="studio"].cmx-h{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) 0;padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .cmx-res,:root [data-style="studio"] .cmx-res,:root [data-style="studio"].cmx-res{margin:0}
:root[data-style="studio"] .cmx-in,:root [data-style="studio"] .cmx-in,:root [data-style="studio"].cmx-in{margin:0 calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4));padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .cmx.done .cmx-in,:root [data-style="studio"] .cmx.done .cmx-in,:root [data-style="studio"].cmx.done .cmx-in{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) 0;padding-block:0;border-top-width:0}
/* Agree, once agreed, sits on Studio's selected fill in its round shape, as a rated thumb does (owner, 23 Nov) */
:root[data-style="studio"] .cmx-tools .ib[aria-pressed="true"],:root [data-style="studio"] .cmx-tools .ib[aria-pressed="true"],:root [data-style="studio"].cmx-tools .ib[aria-pressed="true"]{background:var(--dm-row-on)}
:root[data-style="studio"] .cmx-men,:root [data-style="studio"] .cmx-men,:root [data-style="studio"].cmx-men{bottom:54px;left:var(--dm-s-4)}
:root[data-style="studio"] .cmx-go,:root [data-style="studio"] .cmx-go,:root [data-style="studio"].cmx-go{border-radius:calc(var(--dm-r-field) - 5px)}
:root[data-style="studio"] .cmx-c.ag .tx .w,:root [data-style="studio"] .cmx-c.ag .tx .w,:root [data-style="studio"].cmx-c.ag .tx .w{animation:cmwc var(--dm-t-slow) var(--dm-ease) both}
/* the reaction chip keeps its quiet edge and takes the one hover as a fill (owner, 21 Nov) */
:root[data-style="studio"] .cmx-rc,:root [data-style="studio"] .cmx-rc,:root [data-style="studio"].cmx-rc{transition:background-color var(--dm-t-fast) var(--dm-ease),box-shadow var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .cmx-rc:not([aria-pressed="true"]):hover,:root [data-style="studio"] .cmx-rc:not([aria-pressed="true"]):hover,:root [data-style="studio"].cmx-rc:not([aria-pressed="true"]):hover{background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-line) 50%,transparent),inset 0 0 0 99px var(--dm-row)}}
@keyframes cmwc{from{opacity:0}to{opacity:1}}
comments.jsHTML · 73 lines
DM.def('comments', (r, c) => {
r.innerHTML = r.innerHTML.replace('{check}', I('check','xs')).replace('{up}', I('up','xs'));
const root = $('.cmx', r), th = $('.cmx-th', r), inp = $('.cmx-box input', r), go = $('.cmx-go', r), men = $('.cmx-men', r), st = $('.cmx-st', r), rs = $('.cmx-res', r);
const P = { MK:['Maya Kim','var(--dm-av-l)','MK-g03'], JO:['Jon Ortiz','var(--dm-av-m)','JO-g01'], DA:['Design agent','var(--dm-av-b)'] };
const esc = t => t.replace(/[&<>"]/g, ch => ({ '&':'&', '<':'<', '>':'>', '"':'"' })[ch]);
const fmt = t => esc(t).replace(/@(agent|maya|jon)\b/gi, m => `<span class="m">${m}</span>`);
// the first comment starts the thread; every later one is a reply, indented on a thin line under it
let rp = null;
// the head says nothing the thread below already shows (owner, 19 Nov: no count of the replies); once the thread is
// resolved, a green Resolved chip says so
const count = () => { const d = root.classList.contains('done'), had = !!st.firstChild; if (d === had) return; st.innerHTML = d ? '<span class="tag ok">Resolved</span>' : ''; if (d) enter(st.firstChild); };
function add(who, t, when, ag, agreed = 0){
const el = html(`<div class="cmx-c${ag ? ' ag' : ''}">${AV(who, P[who][1], P[who][2])}<div class="b"><div class="n"><b>${P[who][0]}</b><span class="t">${when}</span><div class="cmx-tools"><button class="ib cmx-rx" aria-label="Agree" aria-pressed="false" data-tip="Agree">${I('up-thumb','xs')}</button></div></div><div class="tx">${ag ? '' : fmt(t)}</div><div class="cmx-rs"><button class="cmx-rc" aria-pressed="false" hidden>${I('up-thumb','xs')}<span class="num"></span></button></div></div></div>`);
el._agree = { n:agreed, mine:false }; agree(el);
$('.cmx-rx', el).onclick = () => agree(el, true); $('.cmx-rc', el).onclick = () => agree(el, true);
// (once the thread grows with what it holds, its comments live in grow()'s wrapper)
const box = $(':scope>.dm-grow', th) || th;
if (!box.firstElementChild) box.appendChild(el);
else { if (!rp){ rp = html('<div class="cmx-rp" role="group" aria-label="Replies"></div>'); box.appendChild(rp); } rp.appendChild(el); }
enter(el); count(); return el;
}
// Agree: the button by the time and the chip under the text both toggle yours, and the chip counts everyone's
function agree(el, flip){
const a = el._agree; if (flip) a.mine = !a.mine;
const n = a.n + (a.mine ? 1 : 0), b = $('.cmx-rx', el), chip = $('.cmx-rc', el), had = document.activeElement === chip;
b.setAttribute('aria-pressed', a.mine); chip.setAttribute('aria-pressed', a.mine);
chip.setAttribute('aria-label', 'Agree, ' + n + (n === 1 ? ' person' : ' people') + (a.mine ? ', including you' : ''));
$('.num', chip).textContent = n; chip.hidden = !n;
if (had && !n) b.focus({ preventScroll:true });
}
add('MK', 'The secondary button feels too faint next to the CTA.', '2h', false, 1);
add('JO', 'Agree. Can we keep it outlined though?', '1h');
async function agent(q){
const el = add('DA', '', 'now', true), tx = $('.tx', el); tx.innerHTML = '<span class="think on" style="color:var(--dm-accent-mark,var(--dm-accent))"><i></i><i></i><i></i><i></i></span>'; await c.wait(900); tx.innerHTML = '';
const a = /outline|border/i.test(q + ' outlined') ? 'Kept it outlined and raised the text to #5B6472, which passes AA at 5.9 : 1. Want me to apply it to the other 2 frames?' : 'On it. I will post the change here when it is ready.';
for (const w of a.split(' ')){ tx.insertAdjacentHTML('beforeend', `<span class="w">${w} </span>`); await c.wait(40); }
const act = html(`<div class="act"><button class="pill primary sm">Apply to all</button><button class="pill line sm">Just this one</button></div>`); $('.b', el).appendChild(act); enter(act);
$$('button', act).forEach((b, i) => b.onclick = () => { act.innerHTML = `<span class="cmx-rv">${I('ok','xs')}${i ? 'Applied to frame 2' : 'Applied to 3 frames'}</span>`; enter(act.firstChild); });
}
function send(){ const v = inp.value.trim(); if (!v) return; add('MK', v, 'now'); inp.value = ''; go.disabled = true; shut(); if (/@agent/i.test(v)) c.run(() => agent(v)); }
const opts = [['DA','agent','Design agent'],['MK','maya','Maya Kim'],['JO','jon','Jon Ortiz']];
// the reply box drives the list of people to mention: it is a combobox, and the highlighted row is its active option
men.id = 'cmx-m-' + Math.random().toString(36).slice(2, 7); men.setAttribute('aria-label', 'Mention');
inp.setAttribute('role', 'combobox'); inp.setAttribute('aria-autocomplete', 'list'); inp.setAttribute('aria-expanded', 'false'); inp.setAttribute('aria-controls', men.id);
let hl = 0;
const mens = () => $$('.mi', men);
const light = k => { const all = mens(); if (!all.length){ inp.removeAttribute('aria-activedescendant'); return; } hl = (k + all.length) % all.length; all.forEach((b, j) => { b.classList.toggle('hl', j === hl); b.setAttribute('aria-selected', j === hl); }); inp.setAttribute('aria-activedescendant', all[hl].id); };
const shut = () => { men.classList.remove('open'); inp.setAttribute('aria-expanded', 'false'); inp.removeAttribute('aria-activedescendant'); };
inp.oninput = () => { go.disabled = !inp.value.trim(); const m = inp.value.match(/@(\w*)$/);
if (m){ const list = opts.filter(o => o[1].startsWith(m[1].toLowerCase())); men.innerHTML = list.map(o => `<button class="mi" role="option" tabindex="-1" id="${men.id}-${o[1]}" data-h="${o[1]}">${AV(o[0], P[o[0]][1], P[o[0]][2]).replace('class="av" style="', 'class="av" style="width:20px;height:20px;font-size:9px;')}<span>${o[2]}<span class="d">@${o[1]}</span></span></button>`).join(''); men.classList.toggle('open', list.length > 0); inp.setAttribute('aria-expanded', list.length > 0); light(0);
$$('.mi', men).forEach(b => b.onmousedown = e => { e.preventDefault(); inp.value = inp.value.replace(/@\w*$/, '@' + b.dataset.h + ' '); shut(); go.disabled = false; inp.focus({ preventScroll:true }); }); }
else shut(); };
// with the mention list open, the up and down arrows move through it and wrap, Enter picks, and Escape closes it
inp.onkeydown = e => {
const open = men.classList.contains('open') && mens().length;
if (open && (e.key === 'ArrowDown' || e.key === 'ArrowUp')){ e.preventDefault(); light(hl + (e.key === 'ArrowDown' ? 1 : -1)); return; }
if (e.key === 'Enter'){ const f = mens()[hl]; if (open && f){ f.onmousedown(e); } else send(); }
if (e.key === 'Escape') shut(); };
go.onclick = send;
// Resolve turns the pin green, says Resolved and folds the reply field away; the thread keeps its colours. Pressed again
// it reopens
rs.onclick = () => { const d = root.classList.toggle('done'); hideTip(); rs.innerHTML = I(d ? 'undo' : 'check', 'xs'); rs.setAttribute('aria-pressed', d); rs.dataset.tip = d ? 'Reopen thread' : 'Resolve thread'; count(); };
// no room is kept for what is to come: the thread eases taller as replies arrive and the agent's words stream in (grow()),
// and the reply field under it glides down with it, never cut; the card follows, centred in its stage. grow() starts once the
// card's entrance (which scales it) has ended, so it measures the thread at its real size
Promise.resolve().then(() => Promise.all(root.getAnimations().map(a => a.finished.catch(() => {})))).then(() => { if (!c.dead && th.isConnected) c.offs.push(grow(th)); });
// the preview asks the agent in the thread on its own; clicking, focusing or typing in it takes over, and what it had
// typed goes. The agent replying is an agent at work (DM.PLAYS): it carries on under the pointer, while the person's own
// typing and sending wait for a mouse resting on the thread to leave, so nothing moves under it
const free = async () => { while (r.matches(':hover')) await c.step(200); };
c.auto(1000, () => c.run(async () => { await free(); await c.type(inp, '@agent can you keep it outlined but darker?', { ms:28, each:() => inp.oninput(), keep:true }); shut(); await c.step(300); await free(); send(); }));
});
Questions
What people ask about it.
- How do I stream the agent's reply into the thread?
- Add a comment with
agent: trueandthinking: true, then setthinkingto false and keep updating itstextas tokens arrive. Each word fades in as it is added. - Does the component call my agent when someone types @agent?
- No.
onSendgives you the reply text, and you decide what happens. The example checks for @agent, adds the person's comment, then adds the agent's reply. - How do I let the person approve the agent's change?
- Give the agent's comment
actions, such as Apply to all and Just this one. In eachonClick, apply the change and setresolutionto a short line that replaces the buttons. - How do I save who agreed with a comment?
- Pass
agreedwith the ids of the comments the current person agreed with, and update it inonAgreedChange. Put everyone else's count in each comment'sagrees.
More in Collaboration
Threads, inboxes and boards for teams working alongside an agent.