Health score
An account's health: a score ring, four factors that open, and the agent's next move. 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 health-scoreReact
npx designme add health-score --reactAstro
npx designme add health-score --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/health-score.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/health-score.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.
One account's health at a glance: the score out of 100 in a small ring with its verdict (Healthy, Watch or At risk), how many factors are on track and how the score moved in 30 days. Under it, the four factors (contact, deals on time, win chance and next step) as rows under hairlines, each with its status dot and figure; click one to read its detail right under it. At the foot, the agent's next move with a button: pressing it books or drafts, and the factors it changes update, so the ring and the score move with them. The demo switches between three accounts, one in each state.
- In a CRM's account sheet or details panel, where a rep needs to know whether an account needs attention and why.
- When an agent watches accounts and can take the next step itself, like booking a check-in or drafting an email.
- For any score made of a few weighted factors, each with its own status and figure.
- The score sits in a small ring that fills to it and takes the verdict's colour: green from 70, orange from 50 and red below. The verdict word beside it is in the same colour.
- A line such as "Account health, 2 of 4 on track", and the change against the score 30 days ago, such as "−13 in 30 days".
- Four full-width rows split by hairlines, each with a status dot, its name, its figure ("11d ago", "0 late", "61%", "None booked") and a chevron. Each dot sits on the content's left edge, where the title and the ring start, each name starts 12px after its dot, and the figures and chevrons end on the right edge with the change in the header. No card, fill or shadow per factor. In Studio the rows have no hairlines: they are rounded rows under one quiet grey fill that glides to the row under the pointer, the account sits in an off-white head strip, and the agent's next move sits in an off-white foot strip.
- The weakest factor that is off track has a grey Weakest tag beside its name. Colour only marks state, in the dots and the ring.
- Clicking a row opens its detail right under it: what happened, and its points out of its maximum. One row is open at a time.
- The agent's suggestion is a plain row with the spark icon on the content's left edge, its words 12px after it, and a button on the content's right edge. Pressing it shows a spinner, then a done chip such as "Booked", and the factors it changed update, for example 58 becoming 78 with Next step turning green. When its words take a line more or less, the row eases to its new height.
- Switching accounts sweeps the ring and counts the score to the new value, and the words and figures crossfade. An open row stays open on the same factor.
- In Soft and Blueprint, under 360px of room the agent's button goes under its words, on their column, so it fits a narrow sheet; Studio keeps it beside them. In React,
account,onActionandopendrive it from your own data.
- The ring is an image labelled with the score, the verdict and the change, such as "Health 58 of 100, watch, down 13 in 30 days".
- Each row is a button with aria-expanded and aria-controls, labelled with its factor, what it means and its status, plus "the weakest factor" where that applies.
- A closed detail is hidden and out of the tab order.
- The agent's button sets aria-busy while it works, and a polite live region announces what it did. Focus moves to the done chip if it was on the button.
- With reduced motion the ring, the score, the crossfades and the opening rows finish at once.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { HealthScore } from '@/components/designme/health-score/HealthScore';React example
The demo above as a React component, 85 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: three accounts behind a switch. The story plays
// once: Watch is showing, the person books the check-in the agent suggests and Next step turns green, then they switch to
// the account at risk. Each account keeps what the agent did for it.
import { useRef, useState } from 'react';
import { HealthScore, type HealthAccount, type HealthFactor } from './HealthScore';
import { Seg } from '../lib/motion';
import { Demo } from '../lib/Demo';
import { useStory, useWait } from '../lib/useScript';
/* today is Mon Nov 9. A factor's points add up to the score: contact 30, deals on time 25, win chance 25, next step 20 */
type Pick = 'healthy' | 'watch' | 'risk';
const ACCOUNTS: Record<Pick, HealthAccount & { after?: Partial<HealthFactor> }> = {
healthy: { name: 'Granite Peak Systems', segment: 'Strategic, Americas', previous: 85,
factors: [
{ key: 'contact', label: 'Contact', status: 'ok', value: '2d', unit: 'ago', summary: 'last touch 2 days ago', points: 28, max: 30,
detail: ['Last touch Nov 7, a pricing call with Dana Ruiz.', 'In touch every week for the last 6 weeks.'] },
{ key: 'late', label: 'On time', status: 'ok', value: '0', unit: 'late', summary: 'no deal past its close date', points: 25, max: 25,
detail: ['3 open deals, none past its close date.', 'Next to close: Platform renewal, Nov 24.'] },
{ key: 'win', label: 'Win chance', status: 'ok', value: '62%', summary: '62% across the open deals', points: 16, max: 25,
detail: ['62% weighted across 3 open deals.', 'Up from 54% six weeks ago.'] },
{ key: 'next', label: 'Next step', status: 'ok', value: 'Thu', unit: 'in 3 days', summary: 'pricing call on Thursday', points: 20, max: 20,
detail: ['Pricing call, Thu Nov 12, 9am, with Dana Ruiz.'] }
],
suggestion: { text: 'The pricing call is on Thursday. Send Dana the updated quote before it.', action: 'Draft email', icon: 'mail',
doneText: 'Email to Dana drafted with the updated quote. It waits in your outbox for review.', doneLabel: 'Drafted' } },
watch: { name: 'Fernway Travel', segment: 'Mid-market, Asia Pacific', previous: 71,
factors: [
{ key: 'contact', label: 'Contact', status: 'warn', value: '11d', unit: 'ago', summary: 'quiet for 11 days', points: 18, max: 30,
detail: ['Last touch Oct 29, an email to Sam Patel. No reply yet.', 'In touch in 5 of the last 6 weeks.'] },
{ key: 'late', label: 'On time', status: 'ok', value: '0', unit: 'late', summary: 'no deal past its close date', points: 25, max: 25,
detail: ['2 open deals, both before their close date.', 'Next to close: First contract, Dec 15.'] },
{ key: 'win', label: 'Win chance', status: 'ok', value: '61%', summary: '61% across the open deals', points: 15, max: 25,
detail: ['61% weighted across 2 open deals.', 'Down from 66% six weeks ago.'] },
{ key: 'next', label: 'Next step', status: 'warn', value: 'None', unit: 'booked', summary: 'no next step booked', points: 0, max: 20,
detail: ['Nothing is booked with Fernway Travel.', 'Booking a meeting adds 20 points.'] }
],
suggestion: { text: 'Quiet for 11 days with nothing booked. Book a check-in with Sam this week.', action: 'Book check-in', icon: 'cal',
doneText: 'Check-in with Sam booked for Wed Nov 11, 10am. Health 58 to 78.', doneLabel: 'Booked' },
after: { key: 'next', status: 'ok', value: 'Wed', unit: 'in 2 days', summary: 'check-in on Wednesday', points: 20,
detail: ['Check-in, Wed Nov 11, 10am, with Sam Patel.', 'Booked by the agent just now.'] } },
risk: { name: 'Tidewell Energy', segment: 'Enterprise, Asia Pacific', previous: 41,
factors: [
{ key: 'contact', label: 'Contact', status: 'bad', value: '38d', unit: 'ago', summary: 'quiet for 38 days', points: 0, max: 30,
detail: ['Last touch Oct 2, a demo follow-up with Priya Shah.', 'In touch in 1 of the last 6 weeks.'] },
{ key: 'late', label: 'On time', status: 'bad', value: '1', unit: 'late', summary: '1 deal 6 days past its close date', points: 9, max: 25,
detail: ['Renewal was due Nov 3 and is still open, 6 days late.', '1 of 2 open deals is past its close date.'] },
{ key: 'win', label: 'Win chance', status: 'warn', value: '33%', summary: '33% across the open deals', points: 8, max: 25,
detail: ['33% weighted across 2 open deals.', 'Down from 52% six weeks ago.'] },
{ key: 'next', label: 'Next step', status: 'bad', value: '6d', unit: 'overdue', summary: 'next step overdue since Nov 3', points: 0, max: 20,
detail: ['Renewal call, due Tue Nov 3. Not held or moved.'] }
],
suggestion: { text: '38 days quiet and the renewal is 6 days late. Call Priya to reset the date.', action: 'Book call', icon: 'cal',
doneText: 'Call with Priya booked for Tue Nov 10, 9am. Health 17 to 37, still at risk.', doneLabel: 'Booked' },
after: { key: 'next', status: 'ok', value: 'Tue', unit: 'tomorrow', summary: 'renewal call tomorrow', points: 20,
detail: ['Renewal call, Tue Nov 10, 9am, with Priya Shah.', 'Booked by the agent just now, in place of the overdue step.'] } }
};
export default function HealthScoreDemo() {
const [pick, setPick] = useState<Pick>('watch');
const [accounts, setAccounts] = useState(ACCOUNTS);
const wait = useWait();
// the agent takes a moment, then the suggestion is done and the factor it changed updates (on that account, whichever shows)
const act = (p: Pick) => async () => {
await wait(900);
setAccounts(all => {
const a = all[p], after = a.after;
return { ...all, [p]: { ...a, suggestion: a.suggestion && { ...a.suggestion, done: true },
factors: after ? a.factors.map(f => (f.key === after.key ? { ...f, ...after } : f)) : a.factors } };
});
};
const ref = useRef<HTMLDivElement>(null);
useStory(ref, async ({ wait, press }) => {
await wait(2500);
press('.dm-hsc-go');
await wait(3400);
press('.dm-seg2 button:nth-of-type(3)');
});
return (
<Demo ref={ref} switcher={<Seg label="Account" value={pick} onChange={setPick} options={[{ value: 'healthy', label: 'Healthy' }, { value: 'watch', label: 'Watch' }, { value: 'risk', label: 'At risk' }]} />}>
<HealthScore account={accounts[pick]} onAction={act(pick)} />
</Demo>
);
}
Astro
In a page in src/pages. It plays the demo above; change its health-score.js to show your own data. Attributes like class go on its root element.
---
import HealthScore from '../components/designme/health-score/HealthScore.astro';
---
<HealthScore />
<HealthScore data-style="soft" class="my-class" />Props
Everything HealthScore takes.
| Prop | Type | What it does |
|---|---|---|
accountrequired | HealthAccount | The account the block shows. Pass another one (or the same one, changed) and the ring sweeps, the score counts and what changed crossfades |
label | string | Starts the line under the verdict, like "Account health, 2 of 4 on track" |
period | string | The change's period, like "30 days" |
bands | [number, number] | The verdict's lower bounds: [Healthy from, Watch from]. Below the second it is At risk |
verdicts | Partial<Record<HealthStatus, string>> | The verdict words, by status |
open | string | null | The open factor, by key, or null for none. Leave it out to let the rows toggle themselves |
defaultOpen | string | null | |
onOpenChange | (key: string | null) => void | |
onAction | (account: HealthAccount) => void | Promise<unknown> | Called by the suggestion's button. Return a promise and the button spins until it settles; then pass the account back with `suggestion.done` set and the factors it changed |
className | string |
Code
The full source, as the CLI installs it.
HealthScore.tsxReact · 193 lines
'use client';
import { Fragment, useEffect, useId, useRef, useState } from 'react';
import { cx } from '../lib/cx';
import { useControllable, useTween } from '../lib/hooks';
import { Icon, type IconName } from '../lib/icons';
import { Fold, Spin, Swap, useGrow } from '../lib/motion';
import { useHoverGlide } from '../lib/glide';
import '../designme.css';
import './health-score.css';
export type HealthStatus = 'ok' | 'warn' | 'bad';
/** @deprecated The rows no longer draw a trend (owner, 9 Nov): kept so existing data still type-checks, and ignored */
export type HealthTrend = { kind: 'dots'; values: boolean[] } | { kind: 'marks'; values: boolean[] } | { kind: 'spark'; values: number[] };
export interface HealthFactor {
/** Identifies the factor, for `open` */
key: string;
/** Like "Contact" */
label: string;
/** Its dot and how the score counts it: on track, watch or at risk */
status: HealthStatus;
/** The figure, like "11d", "0", "61%" or "None" */
value: string;
/** Quieter words after the figure, like "ago", "late" or "booked" */
unit?: string;
/** What screen readers hear for the row, like "quiet for 11 days" */
summary: string;
/** Its share of the score: `points` of `max`. The factors' points add up to the score unless you pass `score` */
points: number;
max: number;
/** @deprecated Ignored: the rows no longer draw a trend */
trend?: HealthTrend;
/** The lines its detail shows when the row is open */
detail?: string[];
}
export interface HealthSuggestion {
/** The agent's next move, like "Quiet for 11 days with nothing booked. Book a check-in with Sam this week." */
text: string;
/** The button's label, like "Book check-in" */
action: string;
icon?: IconName;
/** Once true, the button gives way to a done chip and `doneText` replaces `text` */
done?: boolean;
doneText?: string;
/** The chip's label, like "Booked". Defaults to "Done" */
doneLabel?: string;
}
export interface HealthAccount {
/** Shown above the score when set. Leave it out in a sheet that already names the account */
name?: string;
/** A line under the name, like "Mid-market, Asia Pacific" */
segment?: string;
factors: HealthFactor[];
/** 0 to 100. Defaults to the factors' points added up */
score?: number;
/** The score a period ago, for the change beside the verdict, like "−13 in 30 days" */
previous?: number;
suggestion?: HealthSuggestion;
}
export interface HealthScoreProps {
/** The account the block shows. Pass another one (or the same one, changed) and the ring sweeps, the score counts and
what changed crossfades */
account: HealthAccount;
/** Starts the line under the verdict, like "Account health, 2 of 4 on track" */
label?: string;
/** The change's period, like "30 days" */
period?: string;
/** The verdict's lower bounds: [Healthy from, Watch from]. Below the second it is At risk */
bands?: [number, number];
/** The verdict words, by status */
verdicts?: Partial<Record<HealthStatus, string>>;
/** The open factor, by key, or null for none. Leave it out to let the rows toggle themselves */
open?: string | null;
defaultOpen?: string | null;
onOpenChange?: (key: string | null) => void;
/** Called by the suggestion's button. Return a promise and the button spins until it settles; then pass the account back
with `suggestion.done` set and the factors it changed */
onAction?: (account: HealthAccount) => void | Promise<unknown>;
className?: string;
}
const RING = 2 * Math.PI * 18;
const WORD: Record<HealthStatus, string> = { ok: 'On track', warn: 'Watch', bad: 'At risk' };
/** An account's health: the score in a small ring with its verdict and change, a row per factor under a hairline with its
status dot and figure (open one for its detail, right under it), and the agent's next move with its button. The rows share
the head's columns: each dot under the ring, each name where the verdict starts. Colour only marks state: the dots and the
ring. Fits a 440px details sheet; under 360px of room the button goes under the agent's line. */
export function HealthScore({ account, label = 'Account health', period = '30 days', bands = [70, 50], verdicts, open, defaultOpen = null, onOpenChange, onAction, className }: HealthScoreProps) {
const [opened, setOpened] = useControllable<string | null>(open, defaultOpen, onOpenChange);
const { factors, suggestion: sug } = account;
const score = Math.round(account.score ?? factors.reduce((t, f) => t + f.points, 0));
const band: HealthStatus = score >= bands[0] ? 'ok' : score >= bands[1] ? 'warn' : 'bad';
const verdict = { ok: 'Healthy', warn: 'Watch', bad: 'At risk', ...verdicts }[band];
const onTrack = factors.filter(f => f.status === 'ok').length;
const line = `${label}, ${onTrack === factors.length ? `all ${onTrack}` : `${onTrack} of ${factors.length}`} on track`;
const change = account.previous === undefined ? null : score - account.previous;
// the weakest factor that is off track: the lowest share of its points, the first one on a tie
const weak = factors.filter(f => f.status !== 'ok').reduce<HealthFactor | null>((w, f) => !w || f.points / (f.max || 1) < w.points / (w.max || 1) ? f : w, null);
// the ring fills and the score counts a moment after the block appears; after that they follow the account
const [drawn, setDrawn] = useState(false);
useEffect(() => { const t = setTimeout(() => setDrawn(true), 140); return () => clearTimeout(t); }, []);
const shown = useTween(drawn ? score : 0, 900, 0);
// the button is busy for the account it was pressed for; done is the account's own (suggestion.done)
const who = account.name ?? '';
const [busy, setBusy] = useState<string | null>(null);
const btn = useRef<HTMLButtonElement>(null), chip = useRef<HTMLSpanElement>(null), had = useRef(false);
// Studio's one hover: a highlight that glides from factor to factor
const factorsRef = useRef<HTMLDivElement>(null);
useHoverGlide(factorsRef, '.dm-hsc-t');
const [width, setWidth] = useState<number | undefined>();
const act = async () => {
if (busy !== null || !onAction || sug?.done) return;
had.current = document.activeElement === btn.current;
setWidth(btn.current?.offsetWidth); setBusy(who);
try { await onAction(account); } finally { setBusy(b => (b === who ? null : b)); setWidth(undefined); }
};
const done = !!sug?.done;
useEffect(() => { if (done && had.current) { had.current = false; chip.current?.focus(); } }, [done]);
// what changes is announced once: the agent's work when it lands
const [say, setSay] = useState('');
const wasDone = useRef(done), wasWho = useRef(who);
useEffect(() => {
if (done && !wasDone.current && wasWho.current === who && sug) setSay(sug.doneText ?? sug.text);
wasDone.current = done; wasWho.current = who;
}, [done, who, sug]);
const ids = 'dm-hsc' + useId();
// the agent's line eases to a new line count when it changes, so the block grows and shrinks smoothly
const [sayBox, sayIn] = useGrow<HTMLSpanElement>();
return (
<div data-dm="" className={cx('dm-hsc dm-panel', className)} data-v={band} role="group" aria-label={label}>
{account.name && <div className="dm-hsc-ac"><b><Swap>{account.name}</Swap></b>{account.segment && <Swap>{account.segment}</Swap>}</div>}
<div className="dm-hsc-h">
<div className="dm-hsc-ring" role="img" aria-label={`Health ${score} of 100, ${verdict.toLowerCase()}${change === null ? '' : `, ${change >= 0 ? 'up' : 'down'} ${Math.abs(change)} in ${period}`}`}>
<svg viewBox="0 0 44 44" aria-hidden="true">
<circle className="dm-tr" cx="22" cy="22" r="18" />
<circle className="dm-fl" cx="22" cy="22" r="18" strokeDasharray={RING.toFixed(2)} style={{ strokeDashoffset: (RING * (1 - (drawn ? score : 0) / 100)).toFixed(2) }} />
</svg>
<b className="dm-num" aria-hidden="true">{Math.round(shown)}</b>
</div>
<div className="dm-hsc-ht">
<Swap className="dm-hsc-vd">{verdict}</Swap><Swap className="dm-hsc-sub">{line}</Swap>
{change !== null && <Swap className="dm-hsc-dl dm-num">{`${change >= 0 ? '+' : '−'}${Math.abs(change)} in ${period}`}</Swap>}
</div>
</div>
<div ref={factorsRef} className="dm-hsc-l">
{factors.map((f, j) => (
<Fragment key={f.key}>
<button type="button" className="dm-hsc-t" data-s={f.status} data-weak={f === weak ? '' : undefined} aria-expanded={f.key === opened} aria-controls={`${ids}-${j}`}
aria-label={`${f.label}: ${f.summary}. ${WORD[f.status]}${f === weak ? ', the weakest factor' : ''}`} onClick={() => setOpened(f.key === opened ? null : f.key)}>
<span className="dm-hsc-k"><i className="dm-hsc-dot" /><span className="dm-hsc-n">{f.label}</span><span className="dm-tag dm-hsc-wk" aria-hidden="true">Weakest</span></span>
<span className="dm-hsc-v"><b className="dm-num"><Swap>{f.value}</Swap></b><Swap>{f.unit ?? ''}</Swap></span>
<Icon name="chev-d" size="xs" className="dm-hsc-cv" />
</button>
<Fold open={f.key === opened} className="dm-hsc-d">
<div id={`${ids}-${j}`} role="region" aria-label={`${f.label} details`}>
{f.key === opened && (
<div className="dm-hsc-dc dm-enter" key={who + f.key}>
{(f.detail ?? []).map((l, i) => <p key={i} className="dm-hsc-dp">{l}</p>)}
<p className="dm-hsc-pt dm-num"><span>{f.points} of {f.max} points</span><i /><span>{WORD[f.status]}</span></p>
</div>
)}
</div>
</Fold>
</Fragment>
))}
</div>
{sug && (
<div className="dm-hsc-s">
<span ref={sayBox} className="dm-hsc-say dm-growing"><span ref={sayIn} className="dm-grow">
<Icon name="spark" size="s" />
<Swap className="dm-hsc-st">{done ? sug.doneText ?? sug.text : sug.text}</Swap>
</span></span>
{done
? <span key={who + ':done'} ref={chip} className="dm-tag dm-ok dm-hsc-done dm-enter" tabIndex={-1}><Icon name="check" size="xs" />{sug.doneLabel ?? 'Done'}</span>
: onAction && <button key={who} ref={btn} type="button" className="dm-pill dm-primary dm-sm dm-hsc-go dm-enter" onClick={act} disabled={busy === who} aria-busy={busy === who || undefined}
style={busy === who && width ? { width } : undefined}>
{busy === who ? <><Spin /><span className="dm-hsc-sr">Working</span></> : <>{sug.icon && <Icon name={sug.icon} size="xs" />}{sug.action}</>}
</button>}
</div>
)}
<p className="dm-hsc-sr" aria-live="polite">{say}</p>
</div>
);
}
health-score.cssReact · 121 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Health score ---------- */
/* an account's health: the score in a small ring with its verdict, the four factors as rows under one another (each with its
status dot and its figure, opening its detail right under it) and the agent's next move with its button. The rows are split
by hairlines, with no fill, shadow or card of their own (owner, 9 Nov). The state shows only in the status dots and the
ring, and the weakest factor off track gets an ink label */
.dm-hsc{display:flex;flex-direction:column;gap:var(--dm-s-3);width:100%;padding:var(--dm-s-4);container-type:inline-size;--dm-vm:var(--dm-ok-mark);--dm-vf:var(--dm-ok);--dm-hsc-w:calc(8px + var(--dm-s-3));--dm-hsc-sw:calc(14px + var(--dm-s-3))}
.dm-hsc[data-v="warn"]{--dm-vm:var(--dm-warn-mark);--dm-vf:var(--dm-warn)}
.dm-hsc[data-v="bad"]{--dm-vm:var(--dm-bad-mark);--dm-vf:var(--dm-bad)}
.dm-hsc-sr{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
/* the account it is about, when the block stands on its own (a details sheet that names the account leaves it out) */
.dm-hsc-ac{display:flex;flex-direction:column;align-items:flex-start;padding-bottom:var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);line-height:1.4}
.dm-hsc-ac b{font-size:14px;font-weight:500}
.dm-hsc-ac>span{font-size:12.5px;color:var(--dm-muted)}
/* the header line: the score in its ring, the verdict and how it moved */
.dm-hsc-h{display:flex;align-items:center;gap:var(--dm-s-3)}
.dm-hsc-ring{position:relative;flex:none;width:44px;height:44px;display:grid;place-items:center}
.dm-hsc-ring svg{position:absolute;inset:0;width:100%;height:100%;transform:rotate(-90deg);overflow:visible}
.dm-hsc-ring circle{fill:none;stroke-width:4}
.dm-hsc-ring .dm-tr{stroke:var(--dm-line)}
.dm-hsc-ring .dm-fl{stroke:var(--dm-vm);stroke-linecap:round;transition:stroke-dashoffset .9s var(--dm-ease),stroke var(--dm-t) var(--dm-ease)}
.dm-hsc-ring b{position:relative;font-size:14px;font-weight:500;letter-spacing:-.01em;line-height:1}
/* the verdict over its line, and the change at the end of the verdict's line, on the verdict's baseline (owner, 23 Nov) */
.dm-hsc-ht{flex:1;min-width:0;display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:baseline;justify-items:start;line-height:1.4}
.dm-hsc-vd{grid-row:1;grid-column:1;font-size:14px;font-weight:500;color:var(--dm-vf);transition:color var(--dm-t) var(--dm-ease)}
.dm-hsc-sub{grid-row:2;grid-column:1;font-size:12.5px;color:var(--dm-muted);text-wrap:pretty}
.dm-hsc-dl{grid-row:1;grid-column:2;margin-left:var(--dm-s-3);font-size:12.5px;color:var(--dm-muted)}
/* the factors: a row each, a hairline above every row. A row is its status dot and name (and Weakest), its figure and unit,
and a chevron; its detail opens right under it */
.dm-hsc-l{display:flex;flex-direction:column}
.dm-hsc-t{display:grid;grid-template-columns:minmax(0,1fr) auto 16px;grid-template-areas:"k v cv";align-items:center;column-gap:var(--dm-s-3);width:100%;min-height:44px;padding:10px 0;border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);text-align:left;--dm-sm:var(--dm-ok-mark)}
.dm-hsc-t[data-s="warn"]{--dm-sm:var(--dm-warn-mark)}
.dm-hsc-t[data-s="bad"]{--dm-sm:var(--dm-bad-mark)}
.dm-hsc-t:focus-visible{outline-offset:-2px;border-radius:var(--dm-r-sm)}
.dm-hsc-k{grid-area:k;display:flex;align-items:center;gap:6px;min-width:0;font-size:13px;line-height:20px;color:var(--dm-fg2);transition:color var(--dm-t-fast)}
.dm-hsc-n{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-hsc-dot{flex:none;width:8px;height:8px;border-radius:50%;background:var(--dm-sm);transition:background var(--dm-t) var(--dm-ease)}
/* under the score's head the status dot sits on the content's left edge, where the title and the ring start (owner, 2 Dec:
"the padding on the left for these items is ridiculous", replacing the dot centred under the ring of 18 Nov), and the name
and an open row's detail start 12px after it (--dm-hsc-w: the dot, 12px). (Rows on their own, as in a sheet that shows only
the factors, keep the dot before the name) */
.dm-hsc-h~.dm-hsc-l .dm-hsc-k{position:relative;padding-left:var(--dm-hsc-w)}
.dm-hsc-h~.dm-hsc-l .dm-hsc-dot{position:absolute;left:0;top:6px}
.dm-hsc-h~.dm-hsc-l .dm-hsc-dc{padding-left:var(--dm-hsc-w)}
/* (Weakest keeps 8px after the name, and on a narrow block where it wraps under the name it starts on the name's column) */
.dm-hsc-h~.dm-hsc-l .dm-hsc-k{column-gap:var(--dm-s-2)}
.dm-hsc-h~.dm-hsc-l .dm-hsc-wk{margin-left:0}
/* the weakest factor that is off track says so with the library's grey tag (.tag), on the row's centre line */
.dm-hsc-wk{flex:none;display:none;margin-left:2px}
.dm-hsc-t[data-weak] .dm-hsc-wk{display:inline-flex}
.dm-hsc-v{grid-area:v;display:flex;align-items:baseline;justify-content:flex-end;gap:5px;white-space:nowrap;line-height:20px}
.dm-hsc-v b{font-size:14px;font-weight:500;letter-spacing:-.01em;color:var(--dm-fg)}
.dm-hsc-v>span{font-size:12px;color:var(--dm-muted)}
/* a figure with no unit (61%) ends on the same right edge as the others, with no gap kept for the missing unit */
.dm-hsc-v>span:empty{display:none}
.dm-hsc-cv{grid-area:cv;justify-self:end;color:var(--dm-muted);transition:transform var(--dm-t) var(--dm-ease),color var(--dm-t-fast)}
.dm-hsc-t[aria-expanded="true"] .dm-hsc-k{color:var(--dm-fg)}
.dm-hsc-t[aria-expanded="true"] .dm-hsc-cv{transform:rotate(180deg);color:var(--dm-fg2)}
@media (hover:hover) and (pointer:fine){
.dm-hsc-t:hover .dm-hsc-k{color:var(--dm-fg)}
.dm-hsc-t:hover .dm-hsc-cv{color:var(--dm-fg2)}
}
/* a row's detail: plain lines under its name, no card */
.dm-hsc-dc{padding:0 0 var(--dm-s-3) 14px}
.dm-hsc-dp{margin:0;font-size:12.5px;line-height:1.5;color:var(--dm-fg);text-wrap:pretty}
.dm-hsc-dp+.dm-hsc-dp{margin-top:2px;color:var(--dm-fg2)}
.dm-hsc-pt{display:flex;align-items:center;gap:var(--dm-s-2);margin:var(--dm-s-2) 0 0;font-size:12px;color:var(--dm-muted)}
.dm-hsc-pt i{width:4px;height:4px;border-radius:50%;background:var(--dm-faint)}
/* the agent's next move: a plain row under a hairline, the spark on the content's left edge on the first line of its words,
the words 12px after it (--dm-hsc-sw: the spark, 12px), and its button on the content's right edge, centred on the words
(owner, 2 Dec) */
/* the foot's hairline closes the last factor row, as each row's own hairline opens it, so that row sits evenly between its
two lines (11px each way; check-rules R2, 27 Nov), with no extra gap before it */
.dm-hsc-s{display:flex;align-items:center;gap:var(--dm-s-3);min-height:44px;margin-top:calc(-1 * var(--dm-s-3));padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:12.5px;line-height:1.45;color:var(--dm-fg2)}
.dm-hsc-say{flex:1;min-width:0;display:flex;align-items:flex-start}
.dm-hsc-say .dm-i{flex:none;margin:2px var(--dm-s-3) 0 0;color:var(--dm-accent-mark,var(--dm-accent))}
/* its words ease to a new line count rather than jump (grow()), the spark and words staying side by side */
.dm-hsc-say>.dm-grow{flex:1 1 auto;min-width:0;flex-direction:row;align-items:flex-start}
.dm-hsc-st{flex:1;min-width:0;text-wrap:pretty}
.dm-hsc-s .dm-pill{flex:none}
.dm-hsc-s .dm-pill .dm-spin{width:12px;height:12px}
.dm-hsc-done{flex:none;outline:0}
.dm-hsc-done .dm-i{margin-left:-1px}
/* Blueprint: square marks, labels in small capitals */
:root:not([data-style="soft"],[data-style="studio"]) :is(.dm-hsc-k,.dm-hsc-pt):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){font-size:11px;font-weight:500;letter-spacing:.04em;text-transform:uppercase}
:root:not([data-style="soft"],[data-style="studio"]) .dm-hsc-done:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){font-size:11px}
/* Studio (owner, 18 Nov): the content 16px in from every edge; a factor row's hover is a quiet fill as wide as the content (the
ring's box) with rounded corners, in place of the hairlines round it, reaching 8px out round the row into the padding, so
the dot, the figure and the chevron stay on the content's columns (owner, 26 Nov). The spark is the quiet grey of Studio's
chrome */
:root[data-style="studio"] .dm-hsc-h~.dm-hsc-l .dm-hsc-t,:root [data-style="studio"] .dm-hsc-h~.dm-hsc-l .dm-hsc-t,:root [data-style="studio"].dm-hsc-h~.dm-hsc-l .dm-hsc-t{width:calc(100% + 2 * var(--dm-s-2));margin:0 calc(-1 * var(--dm-s-2));padding-inline:var(--dm-s-2);transition:background-color var(--dm-t-fast) var(--dm-ease),border-color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .dm-hsc-say .dm-i,:root [data-style="studio"] .dm-hsc-say .dm-i,:root [data-style="studio"].dm-hsc-say .dm-i{color:var(--dm-fg2)}
/* (Weakest's grey tag turns white on a row under the pointer, so it still reads on the hover fill, as Parallel agents' tags do) */
:root[data-style="studio"] .dm-hsc-wk,:root [data-style="studio"] .dm-hsc-wk,:root [data-style="studio"].dm-hsc-wk{transition:background-color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-hsc-t:hover .dm-hsc-wk,:root [data-style="studio"] .dm-hsc-t:hover .dm-hsc-wk,:root [data-style="studio"].dm-hsc-t:hover .dm-hsc-wk{background:var(--dm-surface)}}
/* Studio (owner, 21 Nov: "clean up the bottom part… make it look more like the Studio component… try not to break the text into
three lines… if you have to, make the text span full width and add a button below that… Studio is just Soft with a different
corner radius"). The account sits in an off-white head strip and the agent's next move in an off-white foot strip, each
under a hairline, edge to edge. In the foot its words run the strip's width (two lines at most) 12px after the
spark, which sits on the content's left edge, and its button (or Booked) sits beside them on the content's right edge. The factors are Studio's 10px rows with no
hairlines between them, under one gliding hover (hoverGlide); the ring's track is sunk with Studio's inner shadow */
:root[data-style="studio"] .dm-hsc.dm-panel,:root [data-style="studio"] .dm-hsc.dm-panel,:root [data-style="studio"].dm-hsc.dm-panel{padding:0 16px}
:root[data-style="studio"] .dm-hsc-ac,:root [data-style="studio"] .dm-hsc-ac,:root [data-style="studio"].dm-hsc-ac{margin:0 -16px;padding:var(--dm-strip-y) 16px;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-hsc-h,:root [data-style="studio"] .dm-hsc-h,:root [data-style="studio"].dm-hsc-h{margin-top:4px}
:root[data-style="studio"] .dm-hsc-ring .dm-tr,:root [data-style="studio"] .dm-hsc-ring .dm-tr,:root [data-style="studio"].dm-hsc-ring .dm-tr{stroke:transparent}
:root[data-style="studio"] .dm-hsc-ring::before,:root [data-style="studio"] .dm-hsc-ring::before,:root [data-style="studio"].dm-hsc-ring::before{content:"";position:absolute;inset:calc(100% * 2 / 44);border-radius:50%;background:var(--dm-soft);box-shadow:var(--dm-track-ring);-webkit-mask:radial-gradient(circle closest-side,transparent calc(80% - .5px),#000 80%);mask:radial-gradient(circle closest-side,transparent calc(80% - .5px),#000 80%)}
:root[data-style="studio"] .dm-hsc-h~.dm-hsc-l,:root [data-style="studio"] .dm-hsc-h~.dm-hsc-l,:root [data-style="studio"].dm-hsc-h~.dm-hsc-l{gap:2px}
:root[data-style="studio"] .dm-hsc-h~.dm-hsc-l .dm-hsc-t,:root [data-style="studio"] .dm-hsc-h~.dm-hsc-l .dm-hsc-t,:root [data-style="studio"].dm-hsc-h~.dm-hsc-l .dm-hsc-t{border-top:0;border-radius:10px}
:root[data-style="studio"] .dm-hsc-s,:root [data-style="studio"] .dm-hsc-s,:root [data-style="studio"].dm-hsc-s{align-items:center;gap:var(--dm-s-3);margin:4px -16px 0;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
/* the suggestion and its button on one line, as in Soft and Blueprint (owner, 28 Nov) */
/* (on a narrow block the foot keeps its one column: the words, then the button under them, never a second column) */
:root[data-style="studio"] .dm-hsc-s,:root [data-style="studio"] .dm-hsc-s,:root [data-style="studio"].dm-hsc-s{flex-wrap:nowrap}
/* a narrow block (a phone, a slim sheet): the button goes under the agent's line */
@container (max-width:359px){
.dm-hsc-h~.dm-hsc-l .dm-hsc-k{flex-wrap:wrap;row-gap:var(--dm-s-1)}
.dm-hsc-s{flex-wrap:wrap;row-gap:var(--dm-s-2)}
.dm-hsc-say{flex:1 1 100%}
.dm-hsc-s :is(.dm-pill,.dm-hsc-done){margin-left:var(--dm-hsc-sw)}
}
HealthScore.astroAstro · 37 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Health score: An account's health: a score ring, four factors that open, and the agent's next move.
// 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 health-score.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './health-score.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="health-score" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="hsc-dm dm"><div class="dm-main">
<div class="hsc panel" role="group" aria-label="Account health">
<div class="hsc-ac"><b></b><span></span></div>
<div class="hsc-h">
<div class="hsc-ring" role="img" aria-label="Health score"><svg viewBox="0 0 44 44" aria-hidden="true"><circle class="tr" cx="22" cy="22" r="18"/><circle class="fl" cx="22" cy="22" r="18" stroke-dasharray="113.1" stroke-dashoffset="113.1"/></svg><b class="num" aria-hidden="true">0</b></div>
<div class="hsc-ht"><b class="hsc-vd"></b><span class="hsc-sub"></span><span class="hsc-dl num"></span></div>
</div>
<div class="hsc-l"></div>
<div class="hsc-s"><span class="hsc-say"><svg class="i s"><use href="#i-spark"/></svg><span class="hsc-st"></span></span><button type="button" class="pill primary sm hsc-go"></button></div>
<p class="hsc-sr" aria-live="polite"></p>
</div>
</div>
<div class="demo"><div class="seg2" role="group" aria-label="Account"><button aria-pressed="false" data-v="0">Healthy</button><button aria-pressed="true" data-v="1">Watch</button><button aria-pressed="false" data-v="2">At risk</button></div></div>
</div>
</Fragment></div>
</div>
<script>
import './health-score.js';
</script>
health-score.htmlHTML · 19 lines
<div class="card" data-c="health-score">
<div class="stage-in">
<div class="hsc-dm dm"><div class="dm-main">
<div class="hsc panel" role="group" aria-label="Account health">
<div class="hsc-ac"><b></b><span></span></div>
<div class="hsc-h">
<div class="hsc-ring" role="img" aria-label="Health score"><svg viewBox="0 0 44 44" aria-hidden="true"><circle class="tr" cx="22" cy="22" r="18"/><circle class="fl" cx="22" cy="22" r="18" stroke-dasharray="113.1" stroke-dashoffset="113.1"/></svg><b class="num" aria-hidden="true">0</b></div>
<div class="hsc-ht"><b class="hsc-vd"></b><span class="hsc-sub"></span><span class="hsc-dl num"></span></div>
</div>
<div class="hsc-l"></div>
<div class="hsc-s"><span class="hsc-say"><svg class="i s"><use href="#i-spark"/></svg><span class="hsc-st"></span></span><button type="button" class="pill primary sm hsc-go"></button></div>
<p class="hsc-sr" aria-live="polite"></p>
</div>
</div>
<div class="demo"><div class="seg2" role="group" aria-label="Account"><button aria-pressed="false" data-v="0">Healthy</button><button aria-pressed="true" data-v="1">Watch</button><button aria-pressed="false" data-v="2">At risk</button></div></div>
</div>
</div>
</div>
health-score.cssHTML · 120 lines
/* ---------- Health score ---------- */
/* an account's health: the score in a small ring with its verdict, the four factors as rows under one another (each with its
status dot and its figure, opening its detail right under it) and the agent's next move with its button. The rows are split
by hairlines, with no fill, shadow or card of their own (owner, 9 Nov). The state shows only in the status dots and the
ring, and the weakest factor off track gets an ink label */
.hsc{display:flex;flex-direction:column;gap:var(--dm-s-3);width:100%;padding:var(--dm-s-4);container-type:inline-size;--dm-vm:var(--dm-ok-mark);--dm-vf:var(--dm-ok);--dm-hsc-w:calc(8px + var(--dm-s-3));--dm-hsc-sw:calc(14px + var(--dm-s-3))}
.hsc[data-v="warn"]{--dm-vm:var(--dm-warn-mark);--dm-vf:var(--dm-warn)}
.hsc[data-v="bad"]{--dm-vm:var(--dm-bad-mark);--dm-vf:var(--dm-bad)}
.hsc-sr{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
/* the account it is about, when the block stands on its own (a details sheet that names the account leaves it out) */
.hsc-ac{display:flex;flex-direction:column;align-items:flex-start;padding-bottom:var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);line-height:1.4}
.hsc-ac b{font-size:14px;font-weight:500}
.hsc-ac>span{font-size:12.5px;color:var(--dm-muted)}
/* the header line: the score in its ring, the verdict and how it moved */
.hsc-h{display:flex;align-items:center;gap:var(--dm-s-3)}
.hsc-ring{position:relative;flex:none;width:44px;height:44px;display:grid;place-items:center}
.hsc-ring svg{position:absolute;inset:0;width:100%;height:100%;transform:rotate(-90deg);overflow:visible}
.hsc-ring circle{fill:none;stroke-width:4}
.hsc-ring .tr{stroke:var(--dm-line)}
.hsc-ring .fl{stroke:var(--dm-vm);stroke-linecap:round;transition:stroke-dashoffset .9s var(--dm-ease),stroke var(--dm-t) var(--dm-ease)}
.hsc-ring b{position:relative;font-size:14px;font-weight:500;letter-spacing:-.01em;line-height:1}
/* the verdict over its line, and the change at the end of the verdict's line, on the verdict's baseline (owner, 23 Nov) */
.hsc-ht{flex:1;min-width:0;display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:baseline;justify-items:start;line-height:1.4}
.hsc-vd{grid-row:1;grid-column:1;font-size:14px;font-weight:500;color:var(--dm-vf);transition:color var(--dm-t) var(--dm-ease)}
.hsc-sub{grid-row:2;grid-column:1;font-size:12.5px;color:var(--dm-muted);text-wrap:pretty}
.hsc-dl{grid-row:1;grid-column:2;margin-left:var(--dm-s-3);font-size:12.5px;color:var(--dm-muted)}
/* the factors: a row each, a hairline above every row. A row is its status dot and name (and Weakest), its figure and unit,
and a chevron; its detail opens right under it */
.hsc-l{display:flex;flex-direction:column}
.hsc-t{display:grid;grid-template-columns:minmax(0,1fr) auto 16px;grid-template-areas:"k v cv";align-items:center;column-gap:var(--dm-s-3);width:100%;min-height:44px;padding:10px 0;border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);text-align:left;--dm-sm:var(--dm-ok-mark)}
.hsc-t[data-s="warn"]{--dm-sm:var(--dm-warn-mark)}
.hsc-t[data-s="bad"]{--dm-sm:var(--dm-bad-mark)}
.hsc-t:focus-visible{outline-offset:-2px;border-radius:var(--dm-r-sm)}
.hsc-k{grid-area:k;display:flex;align-items:center;gap:6px;min-width:0;font-size:13px;line-height:20px;color:var(--dm-fg2);transition:color var(--dm-t-fast)}
.hsc-n{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hsc-dot{flex:none;width:8px;height:8px;border-radius:50%;background:var(--dm-sm);transition:background var(--dm-t) var(--dm-ease)}
/* under the score's head the status dot sits on the content's left edge, where the title and the ring start (owner, 2 Dec:
"the padding on the left for these items is ridiculous", replacing the dot centred under the ring of 18 Nov), and the name
and an open row's detail start 12px after it (--dm-hsc-w: the dot, 12px). (Rows on their own, as in a sheet that shows only
the factors, keep the dot before the name) */
.hsc-h~.hsc-l .hsc-k{position:relative;padding-left:var(--dm-hsc-w)}
.hsc-h~.hsc-l .hsc-dot{position:absolute;left:0;top:6px}
.hsc-h~.hsc-l .hsc-dc{padding-left:var(--dm-hsc-w)}
/* (Weakest keeps 8px after the name, and on a narrow block where it wraps under the name it starts on the name's column) */
.hsc-h~.hsc-l .hsc-k{column-gap:var(--dm-s-2)}
.hsc-h~.hsc-l .hsc-wk{margin-left:0}
/* the weakest factor that is off track says so with the library's grey tag (.tag), on the row's centre line */
.hsc-wk{flex:none;display:none;margin-left:2px}
.hsc-t[data-weak] .hsc-wk{display:inline-flex}
.hsc-v{grid-area:v;display:flex;align-items:baseline;justify-content:flex-end;gap:5px;white-space:nowrap;line-height:20px}
.hsc-v b{font-size:14px;font-weight:500;letter-spacing:-.01em;color:var(--dm-fg)}
.hsc-v>span{font-size:12px;color:var(--dm-muted)}
/* a figure with no unit (61%) ends on the same right edge as the others, with no gap kept for the missing unit */
.hsc-v>span:empty{display:none}
.hsc-cv{grid-area:cv;justify-self:end;color:var(--dm-muted);transition:transform var(--dm-t) var(--dm-ease),color var(--dm-t-fast)}
.hsc-t[aria-expanded="true"] .hsc-k{color:var(--dm-fg)}
.hsc-t[aria-expanded="true"] .hsc-cv{transform:rotate(180deg);color:var(--dm-fg2)}
@media (hover:hover) and (pointer:fine){
.hsc-t:hover .hsc-k{color:var(--dm-fg)}
.hsc-t:hover .hsc-cv{color:var(--dm-fg2)}
}
/* a row's detail: plain lines under its name, no card */
.hsc-dc{padding:0 0 var(--dm-s-3) 14px}
.hsc-dp{margin:0;font-size:12.5px;line-height:1.5;color:var(--dm-fg);text-wrap:pretty}
.hsc-dp+.hsc-dp{margin-top:2px;color:var(--dm-fg2)}
.hsc-pt{display:flex;align-items:center;gap:var(--dm-s-2);margin:var(--dm-s-2) 0 0;font-size:12px;color:var(--dm-muted)}
.hsc-pt i{width:4px;height:4px;border-radius:50%;background:var(--dm-faint)}
/* the agent's next move: a plain row under a hairline, the spark on the content's left edge on the first line of its words,
the words 12px after it (--dm-hsc-sw: the spark, 12px), and its button on the content's right edge, centred on the words
(owner, 2 Dec) */
/* the foot's hairline closes the last factor row, as each row's own hairline opens it, so that row sits evenly between its
two lines (11px each way; check-rules R2, 27 Nov), with no extra gap before it */
.hsc-s{display:flex;align-items:center;gap:var(--dm-s-3);min-height:44px;margin-top:calc(-1 * var(--dm-s-3));padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:12.5px;line-height:1.45;color:var(--dm-fg2)}
.hsc-say{flex:1;min-width:0;display:flex;align-items:flex-start}
.hsc-say .i{flex:none;margin:2px var(--dm-s-3) 0 0;color:var(--dm-accent-mark,var(--dm-accent))}
/* its words ease to a new line count rather than jump (grow()), the spark and words staying side by side */
.hsc-say>.dm-grow{flex:1 1 auto;min-width:0;flex-direction:row;align-items:flex-start}
.hsc-st{flex:1;min-width:0;text-wrap:pretty}
.hsc-s .pill{flex:none}
.hsc-s .pill .spin{width:12px;height:12px}
.hsc-done{flex:none;outline:0}
.hsc-done .i{margin-left:-1px}
/* Blueprint: square marks, labels in small capitals */
:root:not([data-style="soft"],[data-style="studio"]) :is(.hsc-k,.hsc-pt):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){font-size:11px;font-weight:500;letter-spacing:.04em;text-transform:uppercase}
:root:not([data-style="soft"],[data-style="studio"]) .hsc-done:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){font-size:11px}
/* Studio (owner, 18 Nov): the content 16px in from every edge; a factor row's hover is a quiet fill as wide as the content (the
ring's box) with rounded corners, in place of the hairlines round it, reaching 8px out round the row into the padding, so
the dot, the figure and the chevron stay on the content's columns (owner, 26 Nov). The spark is the quiet grey of Studio's
chrome */
:root[data-style="studio"] .hsc-h~.hsc-l .hsc-t,:root [data-style="studio"] .hsc-h~.hsc-l .hsc-t,:root [data-style="studio"].hsc-h~.hsc-l .hsc-t{width:calc(100% + 2 * var(--dm-s-2));margin:0 calc(-1 * var(--dm-s-2));padding-inline:var(--dm-s-2);transition:background-color var(--dm-t-fast) var(--dm-ease),border-color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .hsc-say .i,:root [data-style="studio"] .hsc-say .i,:root [data-style="studio"].hsc-say .i{color:var(--dm-fg2)}
/* (Weakest's grey tag turns white on a row under the pointer, so it still reads on the hover fill, as Parallel agents' tags do) */
:root[data-style="studio"] .hsc-wk,:root [data-style="studio"] .hsc-wk,:root [data-style="studio"].hsc-wk{transition:background-color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .hsc-t:hover .hsc-wk,:root [data-style="studio"] .hsc-t:hover .hsc-wk,:root [data-style="studio"].hsc-t:hover .hsc-wk{background:var(--dm-surface)}}
/* Studio (owner, 21 Nov: "clean up the bottom part… make it look more like the Studio component… try not to break the text into
three lines… if you have to, make the text span full width and add a button below that… Studio is just Soft with a different
corner radius"). The account sits in an off-white head strip and the agent's next move in an off-white foot strip, each
under a hairline, edge to edge. In the foot its words run the strip's width (two lines at most) 12px after the
spark, which sits on the content's left edge, and its button (or Booked) sits beside them on the content's right edge. The factors are Studio's 10px rows with no
hairlines between them, under one gliding hover (hoverGlide); the ring's track is sunk with Studio's inner shadow */
:root[data-style="studio"] .hsc.panel,:root [data-style="studio"] .hsc.panel,:root [data-style="studio"].hsc.panel{padding:0 16px}
:root[data-style="studio"] .hsc-ac,:root [data-style="studio"] .hsc-ac,:root [data-style="studio"].hsc-ac{margin:0 -16px;padding:var(--dm-strip-y) 16px;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"] .hsc-h,:root [data-style="studio"] .hsc-h,:root [data-style="studio"].hsc-h{margin-top:4px}
:root[data-style="studio"] .hsc-ring .tr,:root [data-style="studio"] .hsc-ring .tr,:root [data-style="studio"].hsc-ring .tr{stroke:transparent}
:root[data-style="studio"] .hsc-ring::before,:root [data-style="studio"] .hsc-ring::before,:root [data-style="studio"].hsc-ring::before{content:"";position:absolute;inset:calc(100% * 2 / 44);border-radius:50%;background:var(--dm-soft);box-shadow:var(--dm-track-ring);-webkit-mask:radial-gradient(circle closest-side,transparent calc(80% - .5px),#000 80%);mask:radial-gradient(circle closest-side,transparent calc(80% - .5px),#000 80%)}
:root[data-style="studio"] .hsc-h~.hsc-l,:root [data-style="studio"] .hsc-h~.hsc-l,:root [data-style="studio"].hsc-h~.hsc-l{gap:2px}
:root[data-style="studio"] .hsc-h~.hsc-l .hsc-t,:root [data-style="studio"] .hsc-h~.hsc-l .hsc-t,:root [data-style="studio"].hsc-h~.hsc-l .hsc-t{border-top:0;border-radius:10px}
:root[data-style="studio"] .hsc-s,:root [data-style="studio"] .hsc-s,:root [data-style="studio"].hsc-s{align-items:center;gap:var(--dm-s-3);margin:4px -16px 0;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
/* the suggestion and its button on one line, as in Soft and Blueprint (owner, 28 Nov) */
/* (on a narrow block the foot keeps its one column: the words, then the button under them, never a second column) */
:root[data-style="studio"] .hsc-s,:root [data-style="studio"] .hsc-s,:root [data-style="studio"].hsc-s{flex-wrap:nowrap}
/* a narrow block (a phone, a slim sheet): the button goes under the agent's line */
@container (max-width:359px){
.hsc-h~.hsc-l .hsc-k{flex-wrap:wrap;row-gap:var(--dm-s-1)}
.hsc-s{flex-wrap:wrap;row-gap:var(--dm-s-2)}
.hsc-say{flex:1 1 100%}
.hsc-s :is(.pill,.hsc-done){margin-left:var(--dm-hsc-sw)}
}
health-score.jsHTML · 171 lines
/* three accounts on Mon Nov 9. A factor's points add up to the score: contact 30, deals on time 25, win chance 25 and next
step 20. Each factor has its status (ok, warn, bad), its figure and unit, a line for screen readers (say) and the lines its
detail shows. The agent's suggestion has its button, what it says once done, and the factors it changes (after) */
const HSC = [
{ n:'Granite Peak Systems', seg:'Strategic, Americas', was:85,
f:{
contact:{ s:'ok', fig:'2d', unit:'ago', say:'last touch 2 days ago', pts:28, max:30,
lines:['Last touch Nov 7, a pricing call with Dana Ruiz.', 'In touch every week for the last 6 weeks.'] },
late:{ s:'ok', fig:'0', unit:'late', say:'no deal past its close date', pts:25, max:25,
lines:['3 open deals, none past its close date.', 'Next to close: Platform renewal, Nov 24.'] },
win:{ s:'ok', fig:'62%', unit:'', say:'62% across the open deals', pts:16, max:25,
lines:['62% weighted across 3 open deals.', 'Up from 54% six weeks ago.'] },
next:{ s:'ok', fig:'Thu', unit:'in 3 days', say:'pricing call on Thursday', pts:20, max:20,
lines:['Pricing call, Thu Nov 12, 9am, with Dana Ruiz.'] }
},
sug:{ t:'The pricing call is on Thursday. Send Dana the updated quote before it.', b:'Draft email', ic:'mail',
done:'Email to Dana drafted with the updated quote. It waits in your outbox for review.', tag:'Drafted' } },
{ n:'Fernway Travel', seg:'Mid-market, Asia Pacific', was:71,
f:{
contact:{ s:'warn', fig:'11d', unit:'ago', say:'quiet for 11 days', pts:18, max:30,
lines:['Last touch Oct 29, an email to Sam Patel. No reply yet.', 'In touch in 5 of the last 6 weeks.'] },
late:{ s:'ok', fig:'0', unit:'late', say:'no deal past its close date', pts:25, max:25,
lines:['2 open deals, both before their close date.', 'Next to close: First contract, Dec 15.'] },
win:{ s:'ok', fig:'61%', unit:'', say:'61% across the open deals', pts:15, max:25,
lines:['61% weighted across 2 open deals.', 'Down from 66% six weeks ago.'] },
next:{ s:'warn', fig:'None', unit:'booked', say:'no next step booked', pts:0, max:20,
lines:['Nothing is booked with Fernway Travel.', 'Booking a meeting adds 20 points.'] }
},
sug:{ t:'Quiet for 11 days with nothing booked. Book a check-in with Sam this week.', b:'Book check-in', ic:'cal',
done:'Check-in with Sam booked for Wed Nov 11, 10am. Health 58 to 78.', tag:'Booked',
after:{ next:{ s:'ok', fig:'Wed', unit:'in 2 days', say:'check-in on Wednesday', pts:20,
lines:['Check-in, Wed Nov 11, 10am, with Sam Patel.', 'Booked by the agent just now.'] } } } },
{ n:'Tidewell Energy', seg:'Enterprise, Asia Pacific', was:41,
f:{
contact:{ s:'bad', fig:'38d', unit:'ago', say:'quiet for 38 days', pts:0, max:30,
lines:['Last touch Oct 2, a demo follow-up with Priya Shah.', 'In touch in 1 of the last 6 weeks.'] },
late:{ s:'bad', fig:'1', unit:'late', say:'1 deal 6 days past its close date', pts:9, max:25,
lines:['Renewal was due Nov 3 and is still open, 6 days late.', '1 of 2 open deals is past its close date.'] },
win:{ s:'warn', fig:'33%', unit:'', say:'33% across the open deals', pts:8, max:25,
lines:['33% weighted across 2 open deals.', 'Down from 52% six weeks ago.'] },
next:{ s:'bad', fig:'6d', unit:'overdue', say:'next step overdue since Nov 3', pts:0, max:20,
lines:['Renewal call, due Tue Nov 3. Not held or moved.'] }
},
sug:{ t:'38 days quiet and the renewal is 6 days late. Call Priya to reset the date.', b:'Book call', ic:'cal',
done:'Call with Priya booked for Tue Nov 10, 9am. Health 17 to 37, still at risk.', tag:'Booked',
after:{ next:{ s:'ok', fig:'Tue', unit:'tomorrow', say:'renewal call tomorrow', pts:20,
lines:['Renewal call, Tue Nov 10, 9am, with Priya Shah.', 'Booked by the agent just now, in place of the overdue step.'] } } } }
];
DM.def('health-score', (r, c) => {
r.innerHTML = r.innerHTML.replace('{spark}', I('spark', 's'));
// each account keeps what the agent did for it, so switching away and back shows the booking still there
const AC = JSON.parse(JSON.stringify(HSC));
const K = ['contact', 'late', 'win', 'next'], L = { contact:'Contact', late:'On time', win:'Win chance', next:'Next step' };
const SW = { ok:'On track', warn:'Watch', bad:'At risk' }, VD = { ok:'Healthy', warn:'Watch', bad:'At risk' }, C = 2 * Math.PI * 18;
const id = 'hsc' + Math.random().toString(36).slice(2, 7);
let A = AC[1];
const score = () => K.reduce((t, k) => t + A.f[k].pts, 0);
const band = v => v >= 70 ? 'ok' : v >= 50 ? 'warn' : 'bad';
const delta = v => (v - A.was >= 0 ? '+' : '−') + Math.abs(v - A.was) + ' in 30 days';
const onTrack = () => { const n = K.filter(k => A.f[k].s === 'ok').length; return n === K.length ? `all ${n} on track` : `${n} of ${K.length} on track`; };
// the weakest factor that is off track: the lowest share of its points, the first one on a tie. None when all are on track
const weakest = () => K.filter(k => A.f[k].s !== 'ok').sort((a, b) => A.f[a].pts / A.f[a].max - A.f[b].pts / A.f[b].max || K.indexOf(a) - K.indexOf(b))[0];
// a row and, right under it, the detail it opens
const row = (k, i) => `<button type="button" class="hsc-t" data-k="${k}" aria-expanded="false" aria-controls="${id}-d${i}">
<span class="hsc-k"><i class="hsc-dot"></i><span class="hsc-n">${L[k]}</span><span class="tag hsc-wk" aria-hidden="true">Weakest</span></span>
<span class="hsc-v"><b class="num"></b><span></span></span>${I('chev-d', 'xs hsc-cv')}</button>
<div class="fold shut hsc-d" id="${id}-d${i}" role="region" aria-label="${L[k]} details"><div><div class="hsc-dc"></div></div></div>`;
const root = $('.hsc', r), list = $('.hsc-l', root);
// Studio's one hover: a highlight that glides from factor to factor (hoverGlide)
c.offs.push(hoverGlide(list, '.hsc-t'));
list.innerHTML = K.map(row).join('');
const ring = $('.hsc-ring', root), fl = $('.fl', ring), num = $('b', ring), an = $('.hsc-ac b', root), as = $('.hsc-ac span', root);
const vd = $('.hsc-vd', root), sub = $('.hsc-sub', root), dl = $('.hsc-dl', root), sr = $('.hsc-sr', root);
const rows = $$('.hsc-t', root), regs = $$('.hsc-d', root), sug = $('.hsc-s', root), st = $('.hsc-st', sug);
// ---- paint: the header, the rows and an open detail follow the factors. After the first time everything that changes
// crossfades, the ring sweeps and the score counts to its new value
let shown = 0, run = 0, open = null;
function paint(first){
const v = score(), b = band(v), w = weakest();
root.dataset.v = b;
ring.setAttribute('aria-label', `Health ${v} of 100, ${VD[b].toLowerCase()}, ${v - A.was >= 0 ? 'up' : 'down'} ${Math.abs(v - A.was)} in 30 days`);
const sweep = () => { fl.style.strokeDashoffset = (C * (1 - v / 100)).toFixed(2); const t = ++run; tween(shown, v, 900, n => { if (t !== run) return; shown = n; num.textContent = Math.round(n); }); };
first ? c.later(140, sweep) : sweep();
const words = [VD[b], `Account health, ${onTrack()}`, delta(v)];
[vd, sub, dl].forEach((el, i) => first ? el.textContent = words[i] : swap(el, words[i]));
rows.forEach(t => {
const k = t.dataset.k, f = A.f[k], fig = $('.hsc-v b', t), unit = $('.hsc-v span', t);
t.dataset.s = f.s; t.toggleAttribute('data-weak', k === w);
t.setAttribute('aria-label', `${L[k]}: ${f.say}. ${SW[f.s]}${k === w ? ', the weakest factor' : ''}`);
if (first){ fig.textContent = f.fig; unit.textContent = f.unit; }
else { swap(fig, f.fig); swap(unit, f.unit); }
});
}
// ---- a row opens its detail right under it; one at a time
function fill(k, how){
const f = A.f[k], dc = $('.hsc-dc', regs[K.indexOf(k)]);
dc.innerHTML = f.lines.map(l => `<p class="hsc-dp">${l}</p>`).join('') + `<p class="hsc-pt num"><span>${f.pts} of ${f.max} points</span><i></i><span>${SW[f.s]}</span></p>`;
if (how === 'enter') enter(dc);
else if (how === 'fade' && !REDUCE) dc.animate([{ opacity:0 }, { opacity:1 }], { duration:260, easing:'ease-out' });
}
function toggle(k){
open = open === k ? null : k;
if (open) fill(open, 'enter');
regs.forEach((reg, j) => reg.classList.toggle('shut', K[j] !== open));
rows.forEach(t => t.setAttribute('aria-expanded', String(t.dataset.k === open)));
}
rows.forEach(t => t.onclick = () => toggle(t.dataset.k));
// ---- the agent's suggestion: its button works, shows it is busy, says what it did, and the factors it changes update.
// The work belongs to the account it was pressed for, even if another account is showing by the time it lands
const draw = (go, acct) => {
if (!acct.busy){ go.disabled = false; go.removeAttribute('aria-busy'); go.style.width = ''; go.innerHTML = I(acct.sug.ic, 'xs') + acct.sug.b; return; }
if (go.offsetWidth) go.style.width = go.offsetWidth + 'px';
go.disabled = true; go.setAttribute('aria-busy', 'true'); go.innerHTML = '<span class="spin" aria-hidden="true"></span><span class="hsc-sr">Working</span>';
};
function control(){
if (A.done) return html(`<span class="tag ok hsc-done" tabindex="-1">${I('check', 'xs')}${A.sug.tag}</span>`);
const go = html('<button type="button" class="pill primary sm hsc-go"></button>'), acct = A;
draw(go, acct); go.onclick = () => act(acct, go);
return go;
}
function act(acct, go){
if (acct.busy || acct.done) return;
const had = document.activeElement === go;
acct.busy = true; draw(go, acct);
c.run(async () => {
await c.wait(900);
acct.busy = false; acct.done = true;
const after = acct.sug.after || {};
Object.keys(after).forEach(k => Object.assign(acct.f[k], after[k]));
if (acct !== A) return;
const n = control(); $('.hsc-go,.hsc-done', sug).replaceWith(n); enter(n); if (had) n.focus();
swap(st, acct.sug.done);
paint(false); if (open) fill(open, null);
sr.textContent = acct.sug.done;
});
}
// ---- an account: its name, its factors and its suggestion. Switching crossfades what changes, and an open row stays
// open on the same factor of the new account
function show(i, first){
A = AC[i];
const words = [A.n, A.seg, A.done ? A.sug.done : A.sug.t];
[an, as, st].forEach((el, j) => first ? el.textContent = words[j] : swap(el, words[j]));
const n = control(); $('.hsc-go,.hsc-done', sug).replaceWith(n); if (!first) enter(n);
paint(first);
if (open) fill(open, 'fade');
if (!first) sr.textContent = `${A.n}, health ${score()} of 100, ${VD[band(score())].toLowerCase()}`;
}
const sg = $('.demo .seg2', r);
seg(sg, v => show(+v));
show(1, true);
// the agent's line eases to a new line count when it changes (an account switch, the agent's work landing), so the card grows
// and shrinks smoothly, centred in its stage
const say = $('.hsc-say', sug);
Promise.resolve().then(() => Promise.all(root.getAnimations().map(a => a.finished.catch(() => {})))).then(() => { if (!c.dead && say.isConnected) c.offs.push(grow(say)); });
// the preview's story, once: Watch is showing, the person books the check-in the agent suggests and Next step turns green,
// then they switch to the account at risk. After that it stays as it is, for the visitor
c.story(async s => {
await s.beat(5);
await s.tap($('.hsc-go', sug)); s.away();
await s.until(() => AC[1].done); await s.beat(5);
await s.tap($$('button', sg)[2]); s.away();
// played once: ending the story here, rather than returning, skips the core's replay loop
throw 'stop';
});
});
Questions
What people ask about it.
- How is the score worked out?
- Each factor has
pointsout of itsmax, and by default the score is the points added up, so the maxima should add up to 100 (the demo uses 30, 25, 25 and 20). Passscoreto show your own number instead. - How do I let the agent act?
- Give the account a
suggestionand passonAction. Return a promise that settles once the agent is done, then pass the account back withsuggestion.doneset and the factors it changed. The button gives way to a done chip,doneTextreplaces the line, and the ring and score move to the new total. - Can I use it in a details sheet that already names the account?
- Yes. Leave out
nameand the block starts at the score. It is made for a sheet about 440px wide and fits narrower ones too. - Can I change the bands and the words?
- Pass
bandswith the lower bounds for Healthy and Watch (70 and 50 by default), andverdictsto rename them.labelstarts the line under the verdict andperiodnames the change's period.
More in Charts and tables
Lightweight charts and tables for dashboards and reports, drawn in plain SVG and HTML.