@namewta/skills-hub 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/licenses/dashboard-design-skill-MIT.txt +21 -0
- package/package.json +1 -1
- package/skills/dev/dev-build/references/behavior-preserving-refactor.md +7 -5
- package/skills/dev/dev-build/references/feature-delivery.md +5 -5
- package/skills/dev/dev-debug/references/diagnostic-method.md +1 -1
- package/skills/dev/dev-deploy/SKILL.md +28 -6
- package/skills/dev/dev-deploy/agents/openai.yaml +3 -3
- package/skills/dev/dev-formal-verify/SKILL.md +4 -2
- package/skills/dev/dev-formal-verify/assets/verify-skill.md +2 -2
- package/skills/dev/dev-formal-verify/references/create-check.md +4 -2
- package/skills/dev/dev-formal-verify/references/example.md +2 -0
- package/skills/dev/dev-formal-verify/references/maintain-check.md +1 -1
- package/skills/dev/dev-formal-verify/references/tla-guide.md +3 -1
- package/skills/dev/dev-formal-verify/references/tool-choice.md +2 -0
- package/skills/dev/dev-grill/SKILL.md +9 -7
- package/skills/dev/dev-grill/agents/openai.yaml +3 -3
- package/skills/dev/dev-grill/references/clarification.md +2 -2
- package/skills/dev/dev-grill/references/decision-interview.md +3 -3
- package/skills/dev/dev-grill/references/interview-entry.md +1 -1
- package/skills/dev/dev-help/SKILL.md +2 -2
- package/skills/dev/dev-help/references/capabilities.md +12 -10
- package/skills/dev/dev-help/references/guide-personal.md +2 -2
- package/skills/dev/dev-help/references/guide-recipes.md +13 -2
- package/skills/dev/dev-help/references/guide-routing.md +12 -18
- package/skills/dev/dev-help/references/guide-setup.md +1 -1
- package/skills/dev/dev-help/references/guide-verification.md +9 -5
- package/skills/dev/dev-help/references/help-method.md +17 -7
- package/skills/dev/dev-help/references/recipes.md +7 -1
- package/skills/dev/dev-intake/SKILL.md +15 -11
- package/skills/dev/dev-intake/agents/openai.yaml +3 -3
- package/skills/dev/dev-intake/assets/brief.md +7 -2
- package/skills/dev/dev-intake/references/input-evidence.md +4 -2
- package/skills/dev/dev-intake/references/requirement-triage.md +24 -21
- package/skills/dev/dev-issue-triage/SKILL.md +3 -1
- package/skills/dev/dev-issue-triage/references/triage-method.md +2 -0
- package/skills/dev/dev-learn/SKILL.md +1 -1
- package/skills/dev/dev-personalize/SKILL.md +19 -9
- package/skills/dev/dev-personalize/agents/openai.yaml +3 -3
- package/skills/dev/dev-personalize/references/authoring-a-skill.md +3 -3
- package/skills/dev/dev-plan/SKILL.md +3 -1
- package/skills/dev/dev-plan/references/local-work-records.md +2 -2
- package/skills/dev/dev-plan/references/uncertainty-map.md +5 -5
- package/skills/dev/dev-prototype/SKILL.md +2 -2
- package/skills/dev/dev-review/SKILL.md +2 -2
- package/skills/dev/dev-review/references/review-report.md +1 -1
- package/skills/dev/dev-review/references/review-triage.md +1 -1
- package/skills/dev/dev-review/references/two-axis-review.md +9 -5
- package/skills/dev/dev-setup/SKILL.md +1 -1
- package/skills/dev/dev-setup/references/formal-options.md +13 -15
- package/skills/dev/dev-sharpen/SKILL.md +4 -4
- package/skills/dev/dev-sharpen/agents/openai.yaml +3 -3
- package/skills/dev/dev-sharpen/assets/request.md +2 -0
- package/skills/dev/dev-sharpen/references/deepen-task.md +1 -1
- package/skills/dev/dev-spec/SKILL.md +10 -8
- package/skills/dev/dev-spec/agents/openai.yaml +3 -3
- package/skills/dev/{dev-intake → dev-spec}/references/implementation-brief.md +6 -2
- package/skills/dev/dev-spec/references/spec-template.md +2 -2
- package/skills/dev/dev-spec/references/specification-method.md +4 -4
- package/skills/dev/dev-statechart/SKILL.md +4 -4
- package/skills/dev/dev-statechart/agents/openai.yaml +1 -1
- package/skills/dev/dev-statechart/references/render.md +1 -1
- package/skills/dev/dev-statechart/references/runtime.md +1 -1
- package/skills/dev/dev-statechart/references/statechart-method.md +8 -6
- package/skills/dev/dev-verify/SKILL.md +5 -3
- package/skills/dev/dev-verify/references/verification-authoring.md +3 -1
- package/skills/dev/dev-verify/references/verification-maintenance.md +2 -2
- package/skills/dev/dev-workflow/SKILL.md +15 -12
- package/skills/dev/dev-workflow/agents/openai.yaml +1 -1
- package/skills/dev/dev-workflow/assets/decision-trail.md +2 -0
- package/skills/dev/dev-workflow/references/decision-trail.md +6 -2
- package/skills/dev/dev-workflow/references/execution-support.md +3 -3
- package/skills/dev/dev-workflow/references/method-handoffs.md +12 -3
- package/skills/dev/dev-workflow/references/operating-method.md +5 -5
- package/skills/dev/dev-workflow/references/workflow-routing.md +9 -9
- package/skills/dev/dev-writing/references/skill-format.md +1 -1
- package/upstream-skills/zh-dashboard-design/SKILL.md +68 -0
- package/upstream-skills/zh-dashboard-design/references/case-study-datafast.md +23 -0
- package/upstream-skills/zh-dashboard-design/references/case-study-school-dashboard.md +51 -0
- package/upstream-skills/zh-dashboard-design/references/components.md +188 -0
- package/upstream-skills/zh-dashboard-design/references/layout.md +45 -0
- package/upstream-skills/zh-dashboard-design/references/perception.md +130 -0
- package/upstream-skills/zh-dashboard-design/references/qa.md +99 -0
- package/upstream-skills/zh-dashboard-design/references/snippets.md +231 -0
- package/upstream-skills/zh-dashboard-design/references/sources.md +79 -0
- package/upstream-skills/zh-dashboard-design/references/swiftui.md +208 -0
- package/upstream-skills/zh-dashboard-design/references/tokens.md +56 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# 代码片段
|
|
2
|
+
|
|
3
|
+
这些小巧、没有额外依赖的片段,用于那些很容易出现微妙错误的功能。采用 React + Tailwind v4,并使用 [tokens.md](tokens.md) 的 Token;逻辑可以移植到任何技术栈。纯 HTML 保留逻辑,在相同 Token 上把类名转换为 CSS(例如 `bg-accent/15` → `background: color-mix(in srgb, var(--color-accent) 15%, transparent)`)。
|
|
4
|
+
|
|
5
|
+
## 数字
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const compact = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 }); // 1.2k, 3.4M
|
|
9
|
+
export const int = (n: number) => Math.round(n).toLocaleString('en');
|
|
10
|
+
export const usd = (n: number, digits = 0) => n.toLocaleString('en', { style: 'currency', currency: 'USD', maximumFractionDigits: digits });
|
|
11
|
+
/** Share of a total: never "0.0%" for a real but tiny share. */
|
|
12
|
+
export const share = (v: number) => (v === 0 ? '0%' : v < 0.1 ? '<0.1%' : v < 1 ? v.toFixed(1) + '%' : Math.round(v) + '%');
|
|
13
|
+
/** Seconds as a duration; round first, so 119.6 is "2m 0s", not "1m 60s". */
|
|
14
|
+
export const duration = (s: number) => { const t = Math.round(s); return t >= 60 ? `${Math.floor(t / 60)}m ${t % 60}s` : `${t}s`; };
|
|
15
|
+
export const plural = (n: number, word: string) => `${int(n)} ${word}${n === 1 ? '' : 's'}`;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 圆整的坐标轴刻度
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
/** 0 and evenly spaced round ticks covering max: 0, 500, 1k, 1.5k… (steps of 1, 2, 2.5 or 5 × 10^n). */
|
|
22
|
+
export function niceTicks(max: number, count = 4): number[] {
|
|
23
|
+
if (!(max > 0)) return [0];
|
|
24
|
+
const raw = max / count, pow = 10 ** Math.floor(Math.log10(raw));
|
|
25
|
+
const step = [1, 2, 2.5, 5, 10].map(m => m * pow).find(s => s >= raw)!;
|
|
26
|
+
return Array.from({ length: Math.ceil(max / step) + 1 }, (_, i) => +(i * step).toFixed(10));
|
|
27
|
+
}
|
|
28
|
+
// chart top = last tick, label each with compact.format(tick)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 涨跌差标签
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
/** Change vs the previous period. Tiny bases say what they were instead of shouting a percentage. */
|
|
35
|
+
export function Delta({ cur, prev, format = int, min = 5, invert = false, vs }: { cur: number; prev: number; format?: (n: number) => string; min?: number; invert?: boolean; vs?: string }) {
|
|
36
|
+
if (!prev) return null; // nothing to compare with
|
|
37
|
+
if (prev < min) return <span className="text-[12px] text-muted tnum">was {format(prev)}</span>;
|
|
38
|
+
const d = ((cur - prev) / prev) * 100, r = Math.round(d);
|
|
39
|
+
if (r === 0) return <span className="text-[12px] text-muted">±0%</span>;
|
|
40
|
+
const good = invert ? d < 0 : d > 0, text = Math.abs(d) > 999 ? (d > 0 ? '10×+' : '−99%') : `${d > 0 ? '▲' : '▼'} ${Math.abs(r)}%`;
|
|
41
|
+
return (
|
|
42
|
+
<span className="inline-flex items-center gap-1.5 text-[12px] tnum" title={`${vs ?? 'Previous period'}: ${format(prev)}`}>
|
|
43
|
+
<span className={`font-medium ${good ? 'text-up' : 'text-down'}`}>{text}</span>
|
|
44
|
+
{vs && <span className="text-muted">{vs}</span>}{/* one or two words: "vs Sep", "yesterday" */}
|
|
45
|
+
</span>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 按相同已过去时长比较的周期窗口
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
/** Previous window for a range starting at local midnight `start` and ending at `end` (now, for "last N days"):
|
|
54
|
+
* the same number of days right before it, cut at the same elapsed time. Today 00:00–15:00 → yesterday 00:00–15:00. */
|
|
55
|
+
export function previousWindow(start: number, end: number, days: number, midnightOf: (daysBefore: number) => number) {
|
|
56
|
+
const prevStart = midnightOf(days); // local midnight `days` days before `start` (DST-safe)
|
|
57
|
+
return { start: prevStart, end: Math.min(start, prevStart + (end - start) + 1) };
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 带选中填充的 KPI 指标格
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
<button aria-pressed={selected} onClick={onSelect} title={explain}
|
|
65
|
+
className="group relative border-b border-r border-line p-2 text-left last:border-r-0 focus-visible:outline-none">
|
|
66
|
+
<div className={`h-full rounded-xl px-4 py-3 transition-colors group-focus-visible:ring-2 group-focus-visible:ring-accent ${selected
|
|
67
|
+
? (money ? 'bg-money/[.07] ring-1 ring-inset ring-money/25' : 'bg-accent/[.06] ring-1 ring-inset ring-accent/20')
|
|
68
|
+
: 'group-hover:bg-soft/70'}`}>
|
|
69
|
+
<div className={`flex items-center justify-between gap-2 text-[14px] ${selected ? 'font-medium text-ink' : 'text-ink-2'}`}>{label}<Delta cur={cur} prev={prev} format={format} /></div>
|
|
70
|
+
<div className={`mt-1 text-[32px] font-semibold leading-[1.15] tracking-[-.03em] tnum ${selected ? 'text-ink' : 'text-ink-2'}`}>{format(cur)}</div>
|
|
71
|
+
{/* no explanatory sub-line: `explain` ("3% of visitors") is the tile's title / tooltip */}
|
|
72
|
+
<Spark values={series /* same window as the main chart */} color={!selected ? 'var(--color-muted)' : money ? 'var(--color-money)' : 'var(--color-accent)'} />
|
|
73
|
+
</div>
|
|
74
|
+
</button>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 底部带细占比条的排名列表行
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const Bar = ({ pct, money }: { pct: number; money?: boolean }) => (
|
|
81
|
+
<span aria-hidden className="absolute inset-x-3 bottom-[5px] h-[3px] overflow-hidden rounded-full bg-line/70">
|
|
82
|
+
<span className={`absolute inset-y-0 left-0 rounded-full opacity-75 transition-opacity group-hover:opacity-100 ${money ? 'bg-money' : 'bg-accent'}`}
|
|
83
|
+
style={{ width: `${Math.max(1.5, Math.min(100, pct))}%` }} />
|
|
84
|
+
</span>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
<button className="group relative flex h-11 w-full items-center gap-3 rounded-[10px] px-3 pb-1.5 text-left text-[14px] hover:bg-soft/60" onClick={() => filterBy(row.x)}>
|
|
88
|
+
<Bar pct={(100 * row.y) / max} />
|
|
89
|
+
<span className="relative flex min-w-0 flex-1 items-center gap-2.5">{icon}<span className="truncate">{row.name}</span></span>
|
|
90
|
+
<span className="relative tnum text-ink">{int(row.y)}</span>
|
|
91
|
+
<span className="relative w-11 text-right tnum text-[13px] text-muted">{share((100 * row.y) / total)}</span>
|
|
92
|
+
</button>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 日期范围日历(单月、无需第三方库)
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
'use client';
|
|
99
|
+
import { useState } from 'react';
|
|
100
|
+
|
|
101
|
+
const DAY = 864e5, ymd = (t: number) => new Date(t).toISOString().slice(0, 10);
|
|
102
|
+
const monthOf = (d: string) => d.slice(0, 7) + '-01';
|
|
103
|
+
const addMonths = (first: string, n: number) => { const d = new Date(first); d.setUTCMonth(d.getUTCMonth() + n); return ymd(d.getTime()); };
|
|
104
|
+
|
|
105
|
+
/** Click the first day, then the last; a click before the start moves the start. Dates are YYYY-MM-DD at UTC midnight. */
|
|
106
|
+
export function RangeCalendar({ from, to, max, min, onChange }: { from: string; to: string; max: string; min?: string; onChange: (from: string, to: string) => void }) {
|
|
107
|
+
const [month, setMonth] = useState(() => monthOf(to || from || max));
|
|
108
|
+
const [hover, setHover] = useState('');
|
|
109
|
+
const start = Date.parse(month), lead = (new Date(start).getUTCDay() + 6) % 7; // Monday first
|
|
110
|
+
const days = Array.from({ length: 42 }, (_, i) => ymd(start + (i - lead) * DAY)); // 6 rows: no height jump
|
|
111
|
+
const end = to || (from && hover > from ? hover : ''); // band follows the pointer
|
|
112
|
+
const pick = (d: string) => (!from || to || d < from ? onChange(d, '') : onChange(from, d));
|
|
113
|
+
const title = new Date(start).toLocaleDateString('en', { month: 'long', year: 'numeric', timeZone: 'UTC' });
|
|
114
|
+
return (
|
|
115
|
+
<div className="select-none" onPointerLeave={() => setHover('')}>
|
|
116
|
+
<div className="mb-2 flex items-center justify-between">
|
|
117
|
+
<button type="button" aria-label="Previous month" disabled={!!min && month <= monthOf(min)} onClick={() => setMonth(m => addMonths(m, -1))} className="grid size-8 place-items-center rounded-full hover:bg-soft disabled:opacity-30">‹</button>
|
|
118
|
+
<div className="text-[13.5px] font-medium" aria-live="polite">{title}</div>
|
|
119
|
+
<button type="button" aria-label="Next month" disabled={month >= monthOf(max)} onClick={() => setMonth(m => addMonths(m, 1))} className="grid size-8 place-items-center rounded-full hover:bg-soft disabled:opacity-30">›</button>
|
|
120
|
+
</div>
|
|
121
|
+
<div className="grid grid-cols-7 text-center text-[11px] font-medium text-muted">{['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'].map(w => <div key={w} className="pb-1.5">{w}</div>)}</div>
|
|
122
|
+
<div className="grid grid-cols-7 gap-y-0.5" role="grid" aria-label={title}>
|
|
123
|
+
{days.map((d, i) => {
|
|
124
|
+
const out = d.slice(0, 7) !== month.slice(0, 7), off = d > max || (!!min && d < min);
|
|
125
|
+
const isStart = d === from, isEnd = !!end && d === end, inside = !!from && !!end && d > from && d < end;
|
|
126
|
+
const band = 'absolute inset-y-0 bg-accent/10';
|
|
127
|
+
return (
|
|
128
|
+
<div key={d} className="relative flex h-9 items-center justify-center">
|
|
129
|
+
{(inside || (isEnd && !isStart)) && <span aria-hidden className={`${band} left-0 right-1/2 ${i % 7 === 0 ? 'rounded-l-full' : ''}`} />}
|
|
130
|
+
{(inside || (isStart && !!end && end !== from)) && <span aria-hidden className={`${band} left-1/2 right-0 ${i % 7 === 6 ? 'rounded-r-full' : ''}`} />}
|
|
131
|
+
<button type="button" disabled={off} aria-pressed={isStart || isEnd} onClick={() => pick(d)} onPointerEnter={() => setHover(d)}
|
|
132
|
+
aria-label={new Date(d).toLocaleDateString('en', { dateStyle: 'full', timeZone: 'UTC' })}
|
|
133
|
+
className={`relative grid size-9 place-items-center rounded-full text-[13px] tnum disabled:pointer-events-none disabled:text-line-strong
|
|
134
|
+
${isStart || isEnd ? 'bg-accent font-medium text-on-accent' : inside ? 'text-ink' : out ? 'text-muted/60 hover:bg-soft' : 'text-ink hover:bg-soft'}`}>
|
|
135
|
+
{+d.slice(8)}
|
|
136
|
+
{d === max && <span aria-hidden className={`absolute bottom-1 size-1 rounded-full ${isStart || isEnd ? 'bg-on-accent' : 'bg-accent'}`} />}
|
|
137
|
+
</button>
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
})}
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
下面的页脚显示选中日期范围(“2026 年 10 月 6 日–17 日”)、天数,以及一个强调色“应用”按钮;两个端点未选齐前禁用。传入 `max`,其值是站点所在时区的今天(不是浏览器所在时区)。
|
|
148
|
+
|
|
149
|
+
## 忽略过时的响应
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const seq = useRef(0);
|
|
153
|
+
async function load() {
|
|
154
|
+
const n = ++seq.current;
|
|
155
|
+
const body = await fetch(url).then(r => (r.ok ? r.json() : null)).catch(() => null);
|
|
156
|
+
if (n !== seq.current) return; // a newer request started: this answer is for a site/range no longer shown
|
|
157
|
+
body ? setData(body) : setError('Couldn’t refresh. These are the last numbers loaded; retrying in a minute.');
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 热力图分档与单元格
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
/** Classed tiers at meaningful thresholds; the problem tier is warm, so the worst cell is the most visible. */
|
|
165
|
+
/** Intensity grows toward the problem: healthiest palest. Ink text everywhere (accent on accent fails 4.5:1). */
|
|
166
|
+
const tier = (rate: number) => rate >= 95 ? 't1' : rate >= 90 ? 't2' : rate >= 85 ? 't3' : 'warn';
|
|
167
|
+
const TIER = {
|
|
168
|
+
t1: 'bg-accent/[.07] text-ink-2', t2: 'bg-accent/15 text-ink', t3: 'bg-accent/25 text-ink',
|
|
169
|
+
warn: 'bg-warn/30 text-ink underline decoration-2 underline-offset-2', // non-colour cue survives greyscale
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
<div role="table" aria-label="Attendance by class and day, %" className="grid gap-2"
|
|
173
|
+
style={{ gridTemplateColumns: `52px repeat(${days.length}, minmax(0, 1fr))` }}>
|
|
174
|
+
<span />
|
|
175
|
+
{days.map((d, i) => <span key={d.iso} className="text-center text-[12px] text-muted">{d.short}<b className={`block text-[13px] tnum ${i === days.length - 1 ? 'text-accent' : 'text-ink-2'}`}>{d.day}</b></span>)}
|
|
176
|
+
{rows.map(r => <Fragment key={r.name}>
|
|
177
|
+
<span className="text-[13px] font-semibold text-ink-2" title={r.owner}>{r.name}</span>
|
|
178
|
+
{r.cells.map((c, i) => c == null
|
|
179
|
+
? <button key={i} onClick={() => remind(r)} aria-label={`${r.name}, ${days[i].label}: not marked. Remind ${r.owner}`}
|
|
180
|
+
className="grid h-9 place-items-center rounded-[10px] border-[1.5px] border-dashed border-warn/75 bg-warn/[.07] text-warn">{bell}</button>
|
|
181
|
+
: <span key={i} tabIndex={0} title={`${r.name} · ${days[i].label} · ${c.present}/${c.size}`}
|
|
182
|
+
className={`grid h-9 place-items-center rounded-[10px] text-[13px] font-semibold tnum ${TIER[tier(c.rate)]}`}>{Math.round(c.rate)}</span>)}
|
|
183
|
+
</Fragment>)}
|
|
184
|
+
</div>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## 子弹图
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
/** Few's spec: bar a third of the track, target as a perpendicular line, ranges darker for poor. */
|
|
191
|
+
export function Bullet({ value, target, ranges, max, label }: { value: number; target: number; ranges: number[]; max: number; label: string }) {
|
|
192
|
+
const pct = (v: number) => `${Math.min(100, (v / max) * 100)}%`;
|
|
193
|
+
const shade = ['bg-ink/40', 'bg-ink/25', 'bg-ink/10']; // ranges = ends of poor, fair, good; drawn poor on top
|
|
194
|
+
return (
|
|
195
|
+
<div className="relative isolate h-6" role="img" aria-label={`${label}: ${value} of target ${target}`}>
|
|
196
|
+
{ranges.map((r, i) => <span key={i} className={`absolute inset-y-0 left-0 ${shade[i]}`} style={{ width: pct(r), zIndex: -i }} />)}
|
|
197
|
+
<span className="absolute left-0 top-1/3 h-1/3 rounded-sm bg-ink" style={{ width: pct(value) }} />
|
|
198
|
+
<span className="absolute inset-y-1 w-[2px] bg-ink" style={{ left: pct(target) }} />
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## 分段占比条
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
<div className="flex gap-1.5" role="img" aria-label={parts.map(p => `${p.label} ${compact.format(p.value)}`).join(', ')}>
|
|
208
|
+
{parts.filter(p => p.value > 0).map(p => (
|
|
209
|
+
<span key={p.label} title={`${p.label}: ${usd(p.value)} · ${share((100 * p.value) / total)}`}
|
|
210
|
+
className="h-2.5 min-w-2.5 rounded-full" style={{ flex: p.value, background: p.color }} />
|
|
211
|
+
))}
|
|
212
|
+
</div>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 全屏共用一个工具提示
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
/** Any element with data-tip gets the same dark tooltip, on hover and on keyboard focus. */
|
|
219
|
+
const tip = document.getElementById('tip')!;
|
|
220
|
+
const show = (el: HTMLElement) => {
|
|
221
|
+
tip.textContent = el.dataset.tip!; tip.classList.add('show');
|
|
222
|
+
const r = el.getBoundingClientRect(), w = tip.offsetWidth, h = tip.offsetHeight;
|
|
223
|
+
tip.style.left = `${Math.max(8, Math.min(innerWidth - w - 8, r.left + r.width / 2 - w / 2))}px`;
|
|
224
|
+
tip.style.top = `${r.top - h - 8 < 8 ? r.bottom + 8 : r.top - h - 8}px`; // flip below near the top edge
|
|
225
|
+
};
|
|
226
|
+
const hide = () => tip.classList.remove('show');
|
|
227
|
+
for (const type of ['pointerover', 'focusin'] as const)
|
|
228
|
+
document.addEventListener(type, e => { const el = (e.target as Element).closest<HTMLElement>('[data-tip]'); el ? show(el) : hide(); });
|
|
229
|
+
document.addEventListener('scroll', hide, true);
|
|
230
|
+
document.addEventListener('keydown', e => { if (e.key === 'Escape') hide(); });
|
|
231
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# 参考来源(各自最值得借鉴的部分)
|
|
2
|
+
|
|
3
|
+
研究时间为 2026 年 10 月;以下均是我们自己的表述,与所列产品没有隶属关系。进行重大重设计之前,应重新查看仍在线的产品,它们可能已经变化。
|
|
4
|
+
|
|
5
|
+
## 书籍与研究
|
|
6
|
+
|
|
7
|
+
2026 年 10 月,通过作者公开发表的论文与规格,以及可靠的书籍摘要进行研究;没有转载书籍原文。相关规则见 [perception.md](perception.md)。
|
|
8
|
+
|
|
9
|
+
- **Stephen Few** — *Information Dashboard Design*(2006/2013):十三种常见错误、单屏监测、每个数字都要有对比背景。perceptualedge.com 上的文章:“Why Most Dashboards Fail”(2007,监测的阅读顺序;灰色界面配一个红色异常标记)、“Practical Rules for Using Color in Charts”(2008,九条原则:三档强度、数量采用单一色相、避免红绿搭配、不加特效)、“Bullet Graph Design Specification”(2013)。
|
|
10
|
+
- **Edward Tufte** — *The Visual Display of Quantitative Information*:数据墨水比、图表垃圾、说谎因子、小倍数图;迷你趋势图见 *Beautiful Evidence*。
|
|
11
|
+
- **Cole Nussbaumer Knaflic** — *Storytelling with Data*:去除杂乱、有节制地使用前注意特征、“目光首先落在哪里?”的测试。
|
|
12
|
+
- **Steve Wexler、Jeffrey Shaffer、Andy Cotgreave** — *The Big Book of Dashboards*:重视场景而非模板;答案优先,相关指标分组。
|
|
13
|
+
- **Cleveland & McGill**(1984、1985),经 **Nielsen Norman Group** 的“Dashboards: Making Charts and Graphs Easier to Understand”介绍:位置和长度优于面积和角度;颜色用于类别而非表示数量大小;监测界面不要用仪表盘、3D 或树图。
|
|
14
|
+
- **Tableau 眼动追踪研究**(2016–2018):大数字更早、更容易被看见;顶部获得最多注视时间;重复元素上的注意力逐渐下降。这是供应商研究,只作为方向性证据。
|
|
15
|
+
- **Lisa Charlotte Muth,Datawrapper** — “Which color scale to use”:顺序色阶与发散色阶(需要有意义的中点)、分档与连续色阶(阈值、可读区间)。
|
|
16
|
+
- **IBM Carbon** — 展示型与探索型仪表盘、F 形扫视优先级、各处同一数据集统一颜色、留白。
|
|
17
|
+
- **WCAG 2.2** — 1.4.1(不能只靠颜色)、1.4.11(数据标记的 3:1 对比度)、1.4.3(图中文字)、1.1.1(每张图都要有文字替代)。
|
|
18
|
+
|
|
19
|
+
## Apple(WWDC 讲座:文字记录,以及从视频截取的关键画面)
|
|
20
|
+
|
|
21
|
+
- **Design an effective chart**(WWDC22):根据真实数据选图形标记;固定与动态坐标范围;约四条、间隔符合直觉的网格线;标题写结论;放大触控区域;颜色均衡、名称可区分且绝不单独承载意义;语音标签先说上下文。
|
|
22
|
+
- **Design app experiences with charts**(WWDC22):何时需要图表(随时间变化、整体中的部分、相互比较);宏观/中观/微观摘要可作为可点击的统计指标;第一眼 → 交互 → 展开并保持连续性;采用熟悉的形式,有意识地表达差异。该讲座建议用完整句子描述每张图;为了保持界面少文字,本技能把这些信息放入标题数字和工具提示。
|
|
23
|
+
- **Bring accessibility to charts in your app**(WWDC21):图表作为可导航容器,通过 `AXChartDescriptor` 提供声音图形,长系列按时间区间分组,避免红绿和蓝黄两组易混颜色。
|
|
24
|
+
- **Writing for interfaces**(WWDC22):目的、预期、上下文、共情;用视觉承载含义;明确的操作标签;能够引导的空状态;指出修复办法的错误状态;术语表;本地化。
|
|
25
|
+
- **Explore pie charts and interactivity in Swift Charts**(WWDC23):饼图用于轻量的部分占整体,圆环中心标签、选中时弱化其他部分、长系列可滚动。
|
|
26
|
+
- **Bring Swift Charts to the third dimension**(WWDC25):仅当数据真正有三个维度、需要通过旋转探索,且形状比精确值更重要时才使用 3D。
|
|
27
|
+
|
|
28
|
+
## 设计师
|
|
29
|
+
|
|
30
|
+
- **Marcel Kargul**(Kargul Studio;x.com/marcelkargul)— 大量已交付的仪表盘作品:浅灰页面与白色卡片、胶囊形工具栏、单色图标方块和单词基准的 KPI 卡片、圆角数字胶囊热力图、中心数值和百分比图例的环形图(表示一个占比,而不是当仪表盘)、带实色端帽的浅色堆叠柱、仅展示一个大数值的深色工具提示,以及表示总体构成的分段胶囊。它是“页面自己就能说清楚”的最佳例子。
|
|
31
|
+
|
|
32
|
+
## 分析类产品(在线演示)
|
|
33
|
+
|
|
34
|
+
- **Plausible** — plausible.io/plausible.io — 被选中指标卡的填充、分组日期菜单和字母快捷键、日期菜单内的对比选项、克制的单色相图表、同时展示两个周期的工具提示。
|
|
35
|
+
- **Fathom** — usefathom.com/demo — 含预设侧栏和柔和范围带的双月日期选择器;尚未结束的一天用点线;“+ Add comparison”标签;事件表包含转化率和价值列。
|
|
36
|
+
- **Simple Analytics** — simpleanalytics.com/simpleanalytics.com — 大号浅色数字、灰色的 0% 差值、日历上方的预设胶囊、时区页脚。
|
|
37
|
+
- **DataFast** — datafa.st(公开演示与试用账户)— 访客趋势上的营收柱(右侧美元坐标轴)、销售峰值旁的来源 Logo、用完整句子写的 Insights 页面(购买前访问次数/天数/小时、工作日×小时热力图)、“Now”时间范围、推荐筛选标签、空状态遮罩下的示例数据、“Set up with AI”可复制提示词、3D 实时地球仪、Goal/Funnel/User/Journey 标签。案例研究:[case-study-datafast.md](case-study-datafast.md)。
|
|
38
|
+
- **Pirsch** — pirsch.pirsch.io — 对比菜单(前一周期、去年同期、匹配星期几);排名条目底部使用细线条。它也展示了原生日期输入看上去像未完成控件的情况。
|
|
39
|
+
- **Vemetric** — app.vemetric.com/public/snappify.com — 指标卡中的色块同时作为图例;多指标叠加。
|
|
40
|
+
- **OpenPanel** — demo.openpanel.dev — 每张指标卡带迷你柱状图;自然语言筛选输入框。
|
|
41
|
+
- **GoatCounter** — 每行配一张迷你趋势图和涨跌差。
|
|
42
|
+
- **Matomo** — 在周期弹窗里同时提供对比复选框与 Apply(整体设计相对老旧且密集)。
|
|
43
|
+
- **Databuddy、Cabin、Counter.dev、Swetrix、PostHog、Umami、Mixpanel** — 补充案例(预设横条、堆叠柱、错误状态、百分比胶囊)。
|
|
44
|
+
|
|
45
|
+
## 营收与 SaaS
|
|
46
|
+
|
|
47
|
+
- **Baremetrics** — demo.baremetrics.com — 日期选择器展示各预设解析后的具体日期;醒目数字旁显示“之前为 $X”;MRR 历史行(1/3/6/12 个月前);目标进度条用文字表示进度;实时资金动态。
|
|
48
|
+
- **TrustMRR** — trustmrr.com/stats — 每行一条 3 px 的细线,右侧显示百分比;用“已验证”建立可信感。
|
|
49
|
+
- **Shopify** — 细条末端显示数值;上一周期以点线叠加。
|
|
50
|
+
- **Mercury** — 收入与支出的细点状轨道条;保留小数位。
|
|
51
|
+
- **Stripe、Lemon Squeezy、Polar、Lago、Metronome、RevenueCat、ProfitWell** — 金额格式、收入与成本之间的阴影差值(Polar)、“数据与其他系统不同的原因是……”这样的真实性说明(RevenueCat)。
|
|
52
|
+
|
|
53
|
+
## 设计系统
|
|
54
|
+
|
|
55
|
+
- **Tremor** — KPI 卡片、面积图约定(其 BarList 使用了应避免的整行带色背景样式)。
|
|
56
|
+
- **shadcn/ui** — 日期范围日历(柔和范围带、实色端点日)、带日期范围选择的图表卡片页头。
|
|
57
|
+
- **Untitled UI** — 左侧预设列加双月日历、今天日期的环形标记。
|
|
58
|
+
- **React Aria** — 可访问的 DateRangePicker:网格角色、键盘操作(方向键、PageUp/Down、Home/End)。
|
|
59
|
+
- **Radix Themes** — 模式切换的分段控件(灰色轨道、凸起的白色滑块)。
|
|
60
|
+
- **Material 3、Ant、Carbon、Atlassian、Mantine** — 日期文本输入切换、格式掩码输入、图表结构核对清单。
|
|
61
|
+
- **Apple HIG(图表)** — 强调唯一重要的数据系列,避免装饰。
|
|
62
|
+
|
|
63
|
+
## 灵感画廊
|
|
64
|
+
|
|
65
|
+
- **SaaSFrame、Dribbble**(热门“analytics dashboard”“date range picker”“KPI cards”)— 适合观察紧凑日期选择器的模式;同时是应该避免的“AI 风格”症状(玻璃效果、霓虹、3D 图标、三块扇形圆环)的典型集合。
|
|
66
|
+
|
|
67
|
+
## X 上的设计师(2026 年 11 月 9 日搜索“dashboard design”及“saas dashboard ui”的热门帖子)
|
|
68
|
+
|
|
69
|
+
近期最优秀的仪表盘来自一小群发布完整作品而非模板的设计师。重设计之前,应查看他们的实时帖子;以下是我们自己的总结。
|
|
70
|
+
|
|
71
|
+
- **Akanksha(@uiakanksha_),“Meridian”**(2026 年 11 月 9 日)— 带刻度条的嵌套目标卡片、带涨跌标签的统计指标条、阴影斜线填充的 MRR 变化条、单一青绿色面积图配深色工具提示、分组侧栏(Analytics / Planning / Workspace),Targets 旁有“3/4”计数。它是 components.md 中目标卡片模式的参考。
|
|
72
|
+
- **Marcel Kargul(@marcelkargul,Kargul Studio)** — “this is the perfect dashboard design”(2025 年 10 月,1200 赞、11.6 万浏览):钱包卡片带刻度条,用紫/橙/绿柱体表示影响,“This Month / 60D / 90D”分段日期范围。他还在 2026 年 10 月发布免费的仪表盘 Figma 文件,可研究间距、排版和布局。
|
|
73
|
+
- **rico(@_heyrico,ace design)** — “Dashboard design cheatsheet”(2026 年 2 月):14 px 基础文字、16 px 图标、1 / 1.2 / 1.5 描边,优先 medium 而非 semibold。他的仪表盘将深色侧栏与相同刻度条结合。
|
|
74
|
+
- **Augustas(@AugustasDesign)** — 基于 shadcn 的开源布局“square-ui”(LN,@ln_dev7)的设计者;提供免费的 Figma 文件和可运行的 Next.js 实现。
|
|
75
|
+
- **Josh tried coding(@joshtriedcoding)** — 借鉴 Cloudflare 仪表盘的一项小交互,用他的话说能让 UI 体验明显变好;回复里把它与 Vercel 侧栏的预览交互作对比。重点在细节而非布局。
|
|
76
|
+
|
|
77
|
+
这些作品的共性(现已写进本技能):安静的浅色表面与细线、大数字旁紧贴目标、细刻度条取代厚实色块、图表保持单一色相、涨跌差显示为小胶囊、14 px 字号。
|
|
78
|
+
|
|
79
|
+
同一批搜索结果中应保持怀疑的内容:没有真实在线产品的“完美仪表盘”“设计师收 $5,000”帖子、AI 生成的多页演示,以及靠霓虹/玻璃概念收获点赞却违反真实性原则的设计。
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# SwiftUI(iOS、iPadOS、macOS)
|
|
2
|
+
|
|
3
|
+
SKILL.md 的规则与 components.md 的组件模式适用于所有平台。本文件把它们映射到 SwiftUI 和 Swift Charts,并以模拟器 QA 取代浏览器 QA。目标版本为 iOS 17 / macOS 14 及以上。
|
|
4
|
+
|
|
5
|
+
## 设计 Token
|
|
6
|
+
|
|
7
|
+
- 颜色放在资源目录(Asset Catalog),分别定义 Any 和 Dark 外观:`Accent`(流量、人员、选中)、`Money`(营收)、`Warn`(低于阈值)、`Up`、`Down`。其余优先使用系统语义颜色:`.primary`、`.secondary`、`.tertiary`;分隔线来自 `Color(.separator)`(iOS)或 `Color(nsColor: .separatorColor)`(macOS)。
|
|
8
|
+
- 淡色填充 = Token 加不透明度:选中态 `Color.accentColor.opacity(0.06)`,日期范围带 `.opacity(0.10)`,占比条轨道 `.quaternary`。
|
|
9
|
+
- 数字:所有不断变化的数值使用 `.monospacedDigit()`;文字使用 `.title`、`.headline`、`.caption` 等样式以支持 Dynamic Type,绝不把文字锁死在固定点数。
|
|
10
|
+
|
|
11
|
+
## 数字
|
|
12
|
+
|
|
13
|
+
```swift
|
|
14
|
+
extension Double {
|
|
15
|
+
var compact: String { formatted(.number.notation(.compactName).precision(.fractionLength(0...1))) } // 1.2K
|
|
16
|
+
var usd: String { formatted(.currency(code: "USD").precision(.fractionLength(0))) }
|
|
17
|
+
/// Share of a total in percent: never "0.0%" for a real but tiny share.
|
|
18
|
+
var share: String { self == 0 ? "0%" : self < 0.1 ? "<0.1%" : self < 1 ? String(format: "%.1f%%", self) : "\(Int(rounded()))%" }
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
涨跌规则与 Web 版本一致:没有上期值 → 不显示;上期基数低于约 5 → 用 `.secondary` 显示“之前是 1”;其他情况显示带正负号的百分比,用 `Up` / `Down` 表示含义,`±0%` 使用 `.secondary`。
|
|
23
|
+
|
|
24
|
+
## KPI 指标格与选中填充
|
|
25
|
+
|
|
26
|
+
```swift
|
|
27
|
+
struct KPITile: View {
|
|
28
|
+
let label: String, value: String, explain: String, delta: Text?, series: [Double] // delta: "▲ 13% vs Sep"
|
|
29
|
+
let selected: Bool, money: Bool
|
|
30
|
+
var tint: Color { money ? Color("Money") : .accentColor }
|
|
31
|
+
var body: some View {
|
|
32
|
+
VStack(alignment: .leading, spacing: 4) {
|
|
33
|
+
HStack { Text(label).fontWeight(selected ? .medium : .regular); Spacer(); delta }.font(.subheadline)
|
|
34
|
+
Text(value).font(.title.weight(.semibold)).monospacedDigit().foregroundStyle(selected ? .primary : .secondary)
|
|
35
|
+
Sparkline(values: series, color: selected ? tint : .secondary) // same window as the main chart
|
|
36
|
+
}
|
|
37
|
+
.padding(12)
|
|
38
|
+
.background(selected ? tint.opacity(0.06) : .clear, in: .rect(cornerRadius: 12))
|
|
39
|
+
.overlay { if selected { RoundedRectangle(cornerRadius: 12).strokeBorder(tint.opacity(0.22)) } }
|
|
40
|
+
.contentShape(.rect)
|
|
41
|
+
.help(explain) // the explanation is a tooltip, never a sub-line
|
|
42
|
+
.accessibilityHint(explain)
|
|
43
|
+
.accessibilityAddTraits(selected ? [.isButton, .isSelected] : .isButton)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
所有指标格应放在一个容器里,由细线(格子间使用 `Divider()`)分隔,而不是分散的悬浮卡片。
|
|
49
|
+
|
|
50
|
+
## 图表(Swift Charts)
|
|
51
|
+
|
|
52
|
+
```swift
|
|
53
|
+
Chart {
|
|
54
|
+
ForEach(previous) { p in // the period before: grey, dashed, behind
|
|
55
|
+
LineMark(x: .value("Day", p.day), y: .value("Value", p.value), series: .value("Period", "Before"))
|
|
56
|
+
.foregroundStyle(.gray.opacity(0.6)).lineStyle(StrokeStyle(lineWidth: 1.5, dash: [4, 3]))
|
|
57
|
+
}
|
|
58
|
+
ForEach(current) { p in
|
|
59
|
+
AreaMark(x: .value("Day", p.day), y: .value("Value", p.value), series: .value("Period", "Now"))
|
|
60
|
+
.foregroundStyle(.linearGradient(colors: [tint.opacity(0.15), tint.opacity(0)], startPoint: .top, endPoint: .bottom))
|
|
61
|
+
LineMark(x: .value("Day", p.day), y: .value("Value", p.value), series: .value("Period", "Now"))
|
|
62
|
+
.foregroundStyle(tint).lineStyle(StrokeStyle(lineWidth: 2))
|
|
63
|
+
}
|
|
64
|
+
if let day = selectedDay { // hover / scrub hairline with the value
|
|
65
|
+
RuleMark(x: .value("Day", day)).foregroundStyle(.secondary.opacity(0.4))
|
|
66
|
+
.annotation(position: .top, overflowResolution: .init(x: .fit, y: .disabled)) { Tooltip(day: day) }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
.chartYScale(domain: 0...ticks.last!) // ticks = niceTicks(max), ported from snippets.md
|
|
70
|
+
.chartYAxis { AxisMarks(position: .leading, values: ticks) { AxisGridLine(); AxisValueLabel() } }
|
|
71
|
+
.chartXAxis { AxisMarks(values: .automatic(desiredCount: 6)) }
|
|
72
|
+
.chartXSelection(value: $selectedDay)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- 圆整刻度:移植 `niceTicks` 并给坐标轴显式传入 `values:`;仅使用 `.automatic(desiredCount:)` 仍可能得到奇怪的刻度值。
|
|
76
|
+
- 今天尚未结束的区间:把最后一段画成独立的 `LineMark` 系列,设置 `dash: [2, 3]`。
|
|
77
|
+
- 营收视图:金额使用第二套刻度的 `BarMark` 效果很好;访客折线保持在前景。
|
|
78
|
+
- 迷你趋势图:复用相同 `Chart`,设置 `.chartXAxis(.hidden)`、`.chartYAxis(.hidden)`,高度约 32;无面积填充或仅使用淡填充。
|
|
79
|
+
- 可访问性:为标记提供 `.accessibilityLabel`/`.accessibilityValue`,或者提供完整 `.accessibilityChartDescriptor`,让 VoiceOver 用户访问 Audio Graphs。
|
|
80
|
+
|
|
81
|
+
## 底部有细占比条的排名列表
|
|
82
|
+
|
|
83
|
+
```swift
|
|
84
|
+
HStack(spacing: 10) {
|
|
85
|
+
icon.frame(width: 16)
|
|
86
|
+
Text(name).lineLimit(1)
|
|
87
|
+
Spacer()
|
|
88
|
+
Text(count, format: .number).monospacedDigit()
|
|
89
|
+
Text(sharePercent.share).font(.caption).foregroundStyle(.secondary).frame(width: 44, alignment: .trailing)
|
|
90
|
+
}
|
|
91
|
+
.padding(.vertical, 8)
|
|
92
|
+
.overlay(alignment: .bottom) {
|
|
93
|
+
GeometryReader { g in
|
|
94
|
+
Capsule().fill(.quaternary)
|
|
95
|
+
.overlay(alignment: .leading) { Capsule().fill(tint.opacity(0.75)).frame(width: max(2, g.size.width * barFraction)) }
|
|
96
|
+
}
|
|
97
|
+
.frame(height: 3)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 热力图(班级 × 日期)
|
|
102
|
+
|
|
103
|
+
```swift
|
|
104
|
+
Grid(horizontalSpacing: 6, verticalSpacing: 6) {
|
|
105
|
+
ForEach(rows) { row in
|
|
106
|
+
GridRow {
|
|
107
|
+
Text(row.name).font(.subheadline.weight(.semibold)).foregroundStyle(.secondary).help(row.owner)
|
|
108
|
+
ForEach(row.cells.indices, id: \.self) { i in
|
|
109
|
+
if let rate = row.cells[i] {
|
|
110
|
+
Text("\(Int(rate.rounded()))").font(.caption.weight(.semibold)).monospacedDigit()
|
|
111
|
+
.frame(maxWidth: .infinity, minHeight: 34)
|
|
112
|
+
.background(tierFill(rate), in: .rect(cornerRadius: 9))
|
|
113
|
+
.foregroundStyle(.primary) // never accent text on an accent tint
|
|
114
|
+
.underline(rate < 85) // non-colour cue for the problem tier
|
|
115
|
+
} else { // not marked: the cell is the action
|
|
116
|
+
Button { remind(row) } label: { Image(systemName: "bell").frame(maxWidth: .infinity, minHeight: 34) }
|
|
117
|
+
.buttonStyle(.plain).foregroundStyle(Color("Warn"))
|
|
118
|
+
.overlay(RoundedRectangle(cornerRadius: 9).strokeBorder(Color("Warn"), style: StrokeStyle(lineWidth: 1.5, dash: [4, 3])))
|
|
119
|
+
.accessibilityLabel("\(row.name): not marked. Remind \(row.owner)")
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
func tierFill(_ rate: Double) -> Color { // intensity grows toward the problem
|
|
127
|
+
rate >= 95 ? .accentColor.opacity(0.07) : rate >= 90 ? .accentColor.opacity(0.15)
|
|
128
|
+
: rate >= 85 ? .accentColor.opacity(0.26) : Color("Warn").opacity(0.30)
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 子弹图
|
|
133
|
+
|
|
134
|
+
```swift
|
|
135
|
+
Chart {
|
|
136
|
+
ForEach(ranges.indices.reversed(), id: \.self) { i in // good (light) behind, poor (dark) in front
|
|
137
|
+
BarMark(xStart: .value("From", 0), xEnd: .value("To", ranges[i]), y: .value("Metric", label), height: .ratio(1))
|
|
138
|
+
.foregroundStyle(.primary.opacity([0.40, 0.25, 0.10][i]))
|
|
139
|
+
}
|
|
140
|
+
BarMark(xStart: .value("From", 0), xEnd: .value("Value", value), y: .value("Metric", label), height: .ratio(0.33))
|
|
141
|
+
.foregroundStyle(.primary)
|
|
142
|
+
RuleMark(x: .value("Target", target)).foregroundStyle(.primary).lineStyle(StrokeStyle(lineWidth: 2))
|
|
143
|
+
}
|
|
144
|
+
.chartXScale(domain: 0...max).chartYAxis(.hidden).frame(height: 28)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 选中、滚动和圆环图
|
|
148
|
+
|
|
149
|
+
```swift
|
|
150
|
+
Chart(days) { d in
|
|
151
|
+
BarMark(x: .value("Day", d.date, unit: .day), y: .value("Sales", d.sales))
|
|
152
|
+
if let selected, Calendar.current.isDate(d.date, inSameDayAs: selected) {
|
|
153
|
+
RuleMark(x: .value("Selected", selected, unit: .day))
|
|
154
|
+
.foregroundStyle(.gray.opacity(0.3)).zIndex(-1)
|
|
155
|
+
.annotation(position: .top, overflowResolution: .init(x: .fit(to: .chart), y: .disabled)) {
|
|
156
|
+
ValuePopover(day: d) // big exact value, muted date line
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
.chartXSelection(value: $selected) // hover on macOS, touch on iOS
|
|
161
|
+
.chartScrollableAxes(.horizontal) // a year of days scrolls; 30 are visible
|
|
162
|
+
.chartXVisibleDomain(length: 3600 * 24 * 30)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
当某一个占比是核心结论时,可以使用圆环图:`SectorMark(angle:, innerRadius: .ratio(0.618), angularInset: 1.5)` 配 `.cornerRadius(5)`,通过 `chartBackground` 和绘图区 Frame 在中心放醒目数值,并在 `chartAngleSelection` 下将未选中扇区设为 `.opacity(0.3)`。
|
|
166
|
+
|
|
167
|
+
## 可访问性
|
|
168
|
+
|
|
169
|
+
- Swift Charts 为每个标记提供可访问性元素和声音图形;逐个设置 `.accessibilityLabel`/`.accessibilityValue`,先说上下文并读出完整词语(“6 月 1 日”“36 个松饼”)。
|
|
170
|
+
- 自定义图表应采用 `AXChart` 并返回 `AXChartDescriptor`:包含标题、一到两句话的摘要、轴描述(通过 `valueDescriptionProvider` 添加单位),以及每条系列自己的 `AXDataSeriesDescriptor`(折线使用 `isContinuous: true`)。
|
|
171
|
+
- 读取 `@Environment(\.accessibilityDifferentiateWithoutColor)`(增加形状)、`\.colorSchemeContrast`(增强颜色对比度)及 `\.accessibilityReduceTransparency`。
|
|
172
|
+
|
|
173
|
+
## 日期范围
|
|
174
|
+
|
|
175
|
+
- 使用 `Menu`(或 `.menu` 样式的 `Picker`)展示预设,当前项有勾选:今天、7/30/90 天、12 个月、昨天、本周、本月、上月,最后是“自定义范围…”。
|
|
176
|
+
- 自定义范围在 iOS 打开 Sheet,在 macOS 打开 Popover;把 snippets.md 中的单月网格移植成 `LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 0), count: 7))`:两个实色圆形端点之间是柔和范围带,今天有圆点,未来日期禁用,页脚显示“12 天”和“应用”。也可以退而使用两个图形化 `DatePicker` 分别选择起止日期;`MultiDatePicker` 只能选独立的多天,不能选连续范围。
|
|
177
|
+
- iPhone 的 Sheet 使用 `.presentationDetents([.medium, .large])`。
|
|
178
|
+
|
|
179
|
+
## 布局
|
|
180
|
+
|
|
181
|
+
- 面板:`LazyVGrid(columns: [GridItem(.adaptive(minimum: 320), spacing: 16)])` 随窗口增长增加列数,这是“宽度随屏幕增长”的原生形式(可调整大小的 Mac 窗口、iPad 分屏)。
|
|
182
|
+
- KPI 指标条:使用 `ViewThatFits` 从单行指标格切换到双列 `Grid`;当文字放大到无障碍字号(`dynamicTypeSize.isAccessibilitySize`)时,标签和值应上下堆叠,而不是截断。
|
|
183
|
+
- iPhone 导航:使用最多 5 个标签页的 `TabView`,或 `NavigationStack` 列表;绝不使用横向滚动导航。
|
|
184
|
+
- macOS:使用 `NavigationSplitView` 侧栏 + 内容区;工具栏包含日期范围菜单和筛选器。
|
|
185
|
+
|
|
186
|
+
## 状态
|
|
187
|
+
|
|
188
|
+
- 加载中:在真实布局上应用 `.redacted(reason: .placeholder)`。
|
|
189
|
+
- 空状态:使用带一个行动按钮的 `ContentUnavailableView`,或明确标注“Sample”的示例数据。
|
|
190
|
+
- 旧数据(新日期范围正在加载):把旧内容保留为 `.opacity(0.4)` 并设置 `.allowsHitTesting(false)`;取消或忽略旧 `Task`(`.task(id: range)` 会自动取消上一任务)。
|
|
191
|
+
- 错误:整个屏幕只显示一条横幅,不要每张卡都报一次。
|
|
192
|
+
- 动画:只有在 `accessibilityReduceMotion` 为 false 时才执行数字缓动(`.contentTransition(.numericText())`)。
|
|
193
|
+
|
|
194
|
+
## QA 流程(模拟器)
|
|
195
|
+
|
|
196
|
+
每次 UI 修改后:构建、运行、截图、查看、修复。全面检查之前,先核对已知总数(qa.md):使用人工计算了预期答案的固定示例数据,并为每个组件(KPI、图表数据、列表行)建立数值不一致就失败的 XCTest。然后进行全面检查:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
xcrun simctl boot "iPhone 16 Pro" # and a small one (iPhone SE) and an iPad
|
|
200
|
+
xcrun simctl ui booted appearance dark # then light
|
|
201
|
+
xcrun simctl ui booted content_size accessibility-extra-extra-extra-large # biggest Dynamic Type; reset to large
|
|
202
|
+
xcrun simctl io booted screenshot ~/Desktop/qa-iphone-dark-ax5.png
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
- 尺寸:最小的 iPhone、最大的 iPhone、iPad 竖屏与横屏;Mac 使用窄窗口和宽窗口(`screencapture -l <windowID>`,或在测试中对 View 使用 `ImageRenderer`)。
|
|
206
|
+
- 一次开启 Increase Contrast(`xcrun simctl ui booted increase_contrast enabled`),另一次开启 Reduce Motion(模拟器 Settings › Accessibility › Motion)。
|
|
207
|
+
- 打开每张截图,执行 qa.md 的一致性检查与异味清单;它们在原生端仍完全适用。
|
|
208
|
+
- 使用固定示例数据的 `#Preview` 覆盖每种状态(空、小样本、加载、错误),可在进入模拟器之前抓到大部分问题。
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# 设计 Token
|
|
2
|
+
|
|
3
|
+
亮色和暗色的每种颜色都只定义一次,然后使用 Token + Alpha 产生淡色填充(如 `bg-accent/10`),让填充色自动随主题变化。以下是一套起始定义(Tailwind v4 的 `@theme`;使用普通 CSS 变量也同样适用):
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
@import "tailwindcss";
|
|
7
|
+
|
|
8
|
+
@theme {
|
|
9
|
+
--color-page: #f8f8f6; /* app background */
|
|
10
|
+
--color-card: #ffffff; /* panels */
|
|
11
|
+
--color-soft: #f1f1ef; /* hover, segmented track */
|
|
12
|
+
--color-side: #f3f3f1; /* sidebar */
|
|
13
|
+
--color-ink: #17171a; /* primary text */
|
|
14
|
+
--color-ink-2: #48484d; /* secondary text, unselected values */
|
|
15
|
+
--color-muted: #66666d; /* labels, axes; >= 4.5:1 on every light surface */
|
|
16
|
+
--color-line: rgb(0 0 0 / .075); /* hairlines, bar tracks */
|
|
17
|
+
--color-line-strong: rgb(0 0 0 / .14); /* inputs, disabled text */
|
|
18
|
+
--color-accent: #3e63dd; /* traffic metrics, selection, focus */
|
|
19
|
+
--color-on-accent: #ffffff;
|
|
20
|
+
--color-money: #0f7f57; /* revenue metrics */
|
|
21
|
+
--color-up: #0f7f57; /* good change */
|
|
22
|
+
--color-down: #d23f45; /* bad change on a meaningful base */
|
|
23
|
+
--color-warn: #c98a00; /* below threshold: heatmap warn tier, overdue chips */
|
|
24
|
+
--color-tip: #1f2530; /* tooltip surface */
|
|
25
|
+
--color-live: #12a150; /* live dots */
|
|
26
|
+
--shadow-card: 0 1px 2px rgb(0 0 0 / .04), 0 1px 1px rgb(0 0 0 / .02);
|
|
27
|
+
--shadow-pop: 0 12px 32px -8px rgb(0 0 0 / .18), 0 0 0 1px rgb(0 0 0 / .06);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* dark: same names, new values. Follows the system unless the app pins a theme with data-theme. */
|
|
31
|
+
@media (prefers-color-scheme: dark) {
|
|
32
|
+
:root:not([data-theme="light"]) {
|
|
33
|
+
--color-page: #0b0b0d; --color-card: #141417; --color-soft: #1c1c20; --color-side: #101013;
|
|
34
|
+
--color-ink: #f3f3f5; --color-ink-2: #c4c4ca; --color-muted: #8c8c95;
|
|
35
|
+
--color-line: rgb(255 255 255 / .08); --color-line-strong: rgb(255 255 255 / .16);
|
|
36
|
+
--color-accent: #7b96ff; --color-money: #34c48b; --color-up: #34c48b; --color-down: #ff6b70;
|
|
37
|
+
--color-warn: #f6b100; --color-tip: #2a3548;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
:root[data-theme="dark"] { /* the same dark values again, for a pinned dark theme */ }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
(将这些深色取值也复制到固定主题的规则里;关键是一个名称对应两种取值。)若要让定义只出现一次,可以使用 `light-dark()` 给每个 Token 赋值(`--color-card: light-dark(#ffffff, #141417);`),并通过 `color-scheme` 决定选择哪种值:`:root { color-scheme: light dark }`、`[data-theme="light"] { color-scheme: light }`、`[data-theme="dark"] { color-scheme: dark }`。
|
|
44
|
+
|
|
45
|
+
## 规则
|
|
46
|
+
|
|
47
|
+
- 两个语义色相承载意义:`accent`(流量、人员、选中)与 `money`(营收),再加上表示“低于阈值”的 `warn`。其他颜色使用墨色、弱化色和分隔线。引入第三种色相必须有理由(例如第三种数据实体),不能只是装饰。
|
|
48
|
+
- 三个强度分别负责三种用途(Few):**浅色(pale)**(Token 的 7–20%)用于非数据和弱化元素,例如轨道、柱体填充、正常的热力图档位及头像底色;**中等强度(medium)**(Token 原色)用于数据标记;**亮色或深色(bright or dark)**仅用于需要关注之处。整屏都是中等和高强度,就再也没有可用来强调的东西。
|
|
49
|
+
- 热力图档位使用 Token + Alpha,从而适应亮、暗主题:正常档在卡片背景上使用 `accent` 的 26 / 15 / 7%,异常档使用 30% 的 `warn` 配深色文字。
|
|
50
|
+
- 淡色填充使用 Token + Alpha:选中态 `bg-accent/[.06] ring-accent/20`,日期范围带 `bg-accent/10`,柱体轨道 `bg-line/70`,悬停 `bg-soft/70`。
|
|
51
|
+
- 在亮、暗两种主题下,检查弱化文字在每一种实际背景(卡片、浅色填充、悬停、页面)上的对比度。
|
|
52
|
+
- 应用内的主题设置会覆盖系统配色;验证深色模式时,也要实际切换应用的主题。
|
|
53
|
+
|
|
54
|
+
## 密度标准(2026 年设计师共识)
|
|
55
|
+
|
|
56
|
+
基础文字为 **14 px**(密集表格和次级行可用 13 px),图标 **16 px**,描边粗细 **1 / 1.2 / 1.5**(导航列表用 1、默认用 1.2、选中或独立展示用 1.5);字重通常用 regular 和 medium,semibold 仅用于页面标题或醒目数字。rico 在 2026 年 2 月的速查表中认为这是专业仪表盘与模板化界面的分界;如能全局保持一致,也可以接受 13 px 的基础字号。同一行图标绝不要混用描边粗细。
|