diff --git a/docs/design-system.md b/docs/design-system.md new file mode 100644 index 0000000..815703d --- /dev/null +++ b/docs/design-system.md @@ -0,0 +1,317 @@ +# eNotify 设计契约(Design Contract v1.0) + +> 状态:冻结。本文件是 ONE-68 的交付物,是后续实现子单(令牌与基础组件 → 页面级重构 → 动效与响应式)的唯一契约依据。 +> 本文只定义规格,不含实现代码。令牌的唯一写入位置是 `web/src/index.css` 的 `@theme inline` 块,`.dark` 块维护同名 token。 + +## 0. 审计方法与证据 + +- 环境:本地 `pnpm dev`(Vite 8 + wrangler dev),实机注册 admin 账号、建库、播种 6 条订阅/重置型条目,覆盖「有数据」与「空骨架」两种状态。 +- 覆盖:19 个页面 + AppLayout,桌面(1440×900)与移动(390×844)两种视口,明暗两套主题,共 71 张截图(审计时存档,随交付评论抽样附上)。 +- 所有「文件:行号」均对照本仓库当前 HEAD。 + +### 代码侧关键证据(先于打分) + +| 证据 | 位置 | +|---|---| +| 设计令牌只有颜色与圆角两组,无字体/字号/行高/字重/字距/间距/阴影/缓动/时长任何 token | `web/src/index.css:4-30` | +| `body` 未声明 `font-family`,全站走浏览器默认系统栈 | `web/src/index.css:78-84` | +| 字号使用:`text-sm` 252 处、`text-xs` 145 处、`text-2xl` 14、`text-base` 9、`text-xl` 7、`text-lg` 3 —— 正文层级几乎只有 sm/xs 两档,标题层级塌陷 | 全仓 grep 统计 | +| `tracking-*` 全站仅 9 处、`leading-*` 仅 6 处;`tabular-nums` 仅 5 处(日期/倒计时大量数字未用等宽数字) | 全仓 grep 统计 | +| 阴影只有 `shadow-sm`(4 处)与 `shadow-lg`(20 处)两档,`shadow-lg` 被滥用于下拉菜单、弹层等所有浮层 | 全仓 grep 统计 | +| 全站 `duration-*` / `ease-*` **0 处**;所有过渡都是 `transition-colors` 默认值(150ms / cubic-bezier(0.4,0,0.2,1)) | 全仓 grep 统计 | +| 移动端「通知列表」把表格 7 列(名称/分类/模式/到期日/状态/提醒/操作)塞进卡片,单行 5 个操作按钮(编辑/停用/测试/重置/删除)挤在一排 | 截图 `items-mobile-light.png`;`ItemListPage.tsx`(40.4K) | +| 加载态全站用 `animate-pulse` 灰块占位(无骨架组件、无 stagger、无内容形态匹配) | `DashboardPage.tsx`、`SettingsPage.tsx:595,821`、`AdminUsersPage.tsx:215,365-369`、`AdminAppPage.tsx:55`、`AdminEmailPage.tsx:165`、`AdminSecurityPage.tsx:131` | +| 桌面端首屏骨架是 4 张等宽灰卡 + 一个灰块,与最终内容形态(统计条 + 时间线)完全不符,加载前后布局跳动 | 截图 `dashboard-desktop-light.png` / `dashboard-desktop-dark.png` | +| 详情页表单字段(名称/模式/分类/开始日期/周期/到期日/提前提醒/开关×2/日历模式/备注/渠道)全部单栏纵向堆叠,无分组、无分区标题,桌面 1440px 下表单挤在中栏、两侧大片空白 | 截图 `item-detail-desktop-light.png`;`ItemDetailPage.tsx`(46.9K) | +| 明暗主题仅替换色值,阴影/边框/层级关系在暗色下仍用浅色逻辑(`shadow-lg` 在纯黑背景上失效) | `index.css:54-73`(`.dark` 块无阴影定义) | + +--- + +## 1. 八维度现状打分(0-10) + +| 维度 | 分数 | 证据与问题描述 | +|---|---|---| +| typography | **2/10** | `body` 无 font-family(`index.css:78`);无字号阶梯 token;`text-sm`/`text-xs` 占全部字号使用的 86%(397/449),标题仅用 `text-xl font-bold`(AppLayout.tsx:183、各页 H1)与 `text-2xl` 混用,层级靠「加粗」而非字号阶梯区分;数字(日期、倒计时、金额)全站未用 `tabular-nums`(仅 5 处),列表上下行数字宽度抖动;中文正文 14px(text-sm)+ 默认行高 1.43 偏挤。 | +| whitespace | **3/10** | 间距全部用 Tailwind 原始刻度(`p-4`/`px-3 py-2`/`space-y-1`)散写,无语义级阶梯;组件内间距与区块间距同值(卡片内 `p-6` 与页面区块 `p-6` 同级),视觉无节奏;桌面详情页两侧大量死白(截图 `item-detail-desktop-light.png`),移动端卡片内 5 个按钮间无喘息(截图 `items-mobile-light.png`)。 | +| visual_hierarchy | **3/10** | 页面 H1(`text-2xl font-semibold`)与卡片标题(CardTitle `text-2xl font-semibold`,`card.tsx:46-50`)同级,层级撞车;仪表盘 4 张统计卡与下方列表视觉权重相同,无「主数据 → 次级」引导;列表行内名称/备注/日期/状态字号仅 sm/xs 两档差,扫读时找不到锚点(截图 `items-desktop-light.png`)。 | +| color | **4/10** | 仅 shadcn 默认 zinc/blue 双色板(`index.css:32-52`);语义色只有 destructive 一个,成功/警告/信息全靠临时硬编码(如 AppLayout 的 `bg-yellow-500/90`、`bg-blue-500/90`,AppLayout.tsx:221,240);无中性色阶 token(灰只有 muted 一档);暗色主色 `hsl(211 100% 50%)` 与亮色 `hsl(221.2 83.2% 53.3%)` 不是同一色相族,主题切换像换了一个品牌(`index.css:63` vs `:41`)。 | +| motion | **1/10** | 全站无 `duration-*`/`ease-*`,所有动效 = `transition-colors`(仅颜色插值,150ms 默认缓动);页面切换 0 过渡;列表项 hover 只有背景色变化;加载 = 全局 `animate-pulse` 灰块,无骨架屏形态、无 stagger;移动端底部导航切换无指示器移动动画(截图 `items-mobile-light.png` 底部)。 | +| micro_interaction | **2/10** | 按钮 hover 仅 `bg-primary/90`(button.tsx:8);无按下态(active:scale);开关 Switch 切换无弹性反馈;删除等危险操作仅靠红色 icon 区分,无二次确认外的任何触觉/视觉反馈设计;表单校验错误无入场动画;toast(Radix Toast)默认样式未定制。 | +| responsive | **4/10** | 双布局(桌面侧栏 / 移动底栏)骨架成立,safe-area 处理到位(`index.css:88-93`);但移动表格→卡片是「塞入」而非重构(7 列信息 + 5 按钮全保留,截图 `items-mobile-light.png`);中间断点(768-1024 平板)无定义,桌面侧栏 256px 在 1024 下挤压内容;详情页长表单移动端无分组折叠,滚动长度超 3 屏。 | +| originality | **2/10** | 视觉语言 = 开箱 shadcn 默认(zinc + blue + 0.5rem 圆角 + 默认卡片),与任何 SaaS 模板不可区分;eNotify 的核心语义「到期/倒计时/周期费用/触达」在视觉层完全缺席:倒计时只是绿色小圆点+「43d」文字(截图 `items-desktop-light.png`),没有进度、紧迫感梯度、周期节律等任何专属表达。 | + +--- + +## 2. 基准调研(每维度获奖参照) + +### typography +1. **Linear**(linear.app,Awwwards SOTD)— 用 Inter 单字族 + 极端克制的字号阶梯(13/14/16/21/28px 五档),标题靠字重 510→680 的微梯度而非字号跳跃分层;数字与代码一律 tabular。eNotify 学:少级数、每级有明确语义归属。 +2. **Stripe**(stripe.com,多次 Webby)— 中英/符号混排时西文用 sohne、CJK 落到系统栈,标题 letter-spacing -0.02em 收紧、正文 0;行高西文 1.5 / 大字 1.25。eNotify 学:标题负字距 + 中文略宽行高。 +3. **Readymag 自家站**(readymag.com,FWA)— display 级标题用超大号 + 极窄行高(0.95-1.05)制造张力,正文与标题字号比达 1:6。eNotify 学:仪表盘统计大数字应用 display 级处理。 + +### whitespace +4. **Apple 产品页**(apple.com,Webby 常任)— 区块间距是组件内间距的 3-4 倍(如组件内 24px、区块 96px),用留白倍数做节奏。eNotify 学:建立「内/外」间距比值规则。 +5. **Things 3 官网**(culturedcode.com/things,Apple Design Award)— 留白即分隔:几乎不用分隔线,靠 64px+ 的纵向留白区分组。eNotify 学:减少 border 依赖。 + +### visual_hierarchy +6. **Height**(height.app,Awwwards Honorable Mention)— 每页一个「主数据锚点」(大号数字/进度),其余元素字级差 ≥2 档;列表行内主信息 15px/500,辅信息 13px/400 muted,恒定两档差。eNotify 学:行内两级差规则。 +7. **Cron/Notion Calendar**(cron.com,Awwwards SOTD 提名)— 时间信息用「大数字 + 小单位」的非对称排版(如 "43" 大号 + "days" 小号),到期语义直接成为视觉主角。eNotify 学:倒计时数字的排版范式。 + +### color +8. **Wise**(wise.com,Webby Winner)— 单一高饱和品牌绿 + 全中性灰阶(8 级),品牌色只出现在行动点与关键数据上,克制产生识别度。eNotify 学:品牌色使用配额制。 +9. **Vercel**(vercel.com,Awwwards)— 暗色主题不是反色:重调饱和度与层级(暗色下用边框代替阴影分层),语义色暗色版提高明度降饱和。eNotify 学:暗色独立调色而非反色。 + +### motion +10. **Stripe Press**(press.stripe.com,Awwwards SOTD)— 页面级转场 300-500ms + cubic-bezier 强调曲线,内容入场 stagger 40-60ms;所有动效时长可枚举(没有随意值)。eNotify 学:三档时长枚举。 +11. **Family**(family.co,FWA SOTD)— 列表项 hover 同时位移 2-4px + 阴影抬升 + 箭头显现,多属性协同但全在 200ms 内完成。eNotify 学:微动效组合拳的时长上限。 +12. **Linear 方法论文档**(linear.app/method)— 公开规定 UI 动效 150-300ms、ease-out 为主、禁用 bounce 于工具型界面。eNotify 学:工具型产品的动效克制边界。 + +### micro_interaction +13. **Things 3**(Apple Design Award)— 完成待办的勾选:图标形变 + 整行 200ms 淡出 + 列表重排,一个动作三段反馈。eNotify 学:操作确认的分段反馈。 +14. **Superhuman**(superhuman.com,Webby)— 每个可达元素 100ms 内的即时 hover 反馈 + 快捷键提示 tooltip 延迟 400ms 出现;反馈分层(即时/延迟)。eNotify 学:反馈延迟分层。 + +### responsive +15. **Pitch**(pitch.com,Awwwards)— 移动端不是桌面压缩版:列表卡片重构成「主信息 + 次要抽屉」,操作收进溢出菜单,单行操作 ≤2 个。eNotify 学:移动端操作配额。 +16. **Linear 移动端**(linear.app 响应式)— 底部导航激活态有指示 pill 滑动动画(layoutId 共享元素),tab 切换内容交叉淡入。eNotify 学:底栏激活态表达。 + +### originality +17. **Cron/Notion Calendar**(同上)— 把「时间」做成产品的主视觉语言(时间块、进度、节奏栅格),品牌与功能语义合一。eNotify 学:从「到期/周期」长视觉语言。 +18. **Copilot Money**(copilot.money,Apple Design Award 提名)— 费用类产品用「燃尽进度条 + 剩余天数」作为首屏主视觉,数字全部 tabular + 大字号。eNotify 学:周期费用的可视化范式。 +19. **Wise**(同上)— 汇率倒计时锁价("rate guaranteed for 38 hours")用环形进度表达紧迫感。eNotify 学:紧迫感的图形化。 + +--- + +## 3. 视觉方向定案(originality 的主张) + +### 主张:**「时间账本 Ledger of Time」** + +eNotify 的视觉语言从它的核心语义直接长出来:**每一笔周期费用/到期事项都是时间轴上的一笔账**。具体可反驳的主张: + +1. **倒计时是第一公民**:到期天数是列表/详情/仪表盘的视觉主角——大号 tabular 数字(display 级),配「剩余进度环/条」(已过去 vs 剩余),而不是绿色小圆点 + "43d" 文本。紧迫感通过颜色梯度表达:>30 天中性、≤30 天蓝、≤7 天琥珀、逾期红——这条梯度成为全站唯一的语义色梯度。 +2. **周期节律可视化**:cycle/reset 模式用循环图形(环形进度/月相式圆点)表达,「本月已过去 ████░░ 60%」这类节律条成为仪表盘主视觉,呼应「账本」的记账行。 +3. **账目式排版**:列表行 = 账本分录——左:名称(债务人式排版),右:金额 + 到期天数右对齐 tabular 数字栏,像银行账单一样可扫读。表格感、纵向对齐、克制分隔线。 +4. **克制的工具气质**:无插画、无渐变 hero、无装饰图形;识别度全部来自排版 + 数字处理 + 时间图形,向 Linear/Things 的工具美学对齐。 + +### 为什么不是别的方向(三条反例) + +- **不是「通知/铃铛」方向**(铃铛 icon、消息气泡、通知中心红点亮渐变风):那是触达通道的语义,eNotify 的核心资产是「到期数据」而非「消息」;且通知中心风已被所有 IM/协作产品做滥,无区分度。 +- **不是「日历」方向**(日历网格主视觉、月视图):日历表达「时间点」但弱表达「剩余时长」与「周期循环」,而周期费用是 eNotify 区别于日程应用的核心;日历网格在移动端也必然退化成列表,等于白做。 +- **不是「温暖生活手账」方向**(圆角加大 + 柔和 pastel + 插画):与「费用到期提醒」需要的精确、可信、工具感相冲突;pastel 在暗色主题下维护成本高且对比度难达标;对 admin/2FA/安全设置等企业感页面气质不符。 + +--- + +## 4. 令牌规格(可直接写进 CSS 的值) + +> 全部 token 写入 `web/src/index.css` 的 `@theme inline`;颜色类在 `.dark` 块维护同名覆盖。命名遵循 Tailwind v4 约定(`--font-*`、`--text-*`、`--spacing-*`、`--radius-*`、`--shadow-*`、`--ease-*`、`--color-*`)。 + +### 4.1 字体族(--font-*) + +**主字体:自托管 Inter Variable(裁决定案,冻结)**——非 npm 依赖、非外部 CDN,woff2 资产入仓,保证离线与 PWA 可用。 + +- 资产(已随契约入仓):`web/src/assets/fonts/InterVariable.woff2`(344KB)与 `InterVariable-Italic.woff2`(379KB),许可 `web/src/assets/fonts/INTER-LICENSE.txt`(OFL,来源 Inter 4.1 官方 release)。 +- `@font-face`(唯一声明位置:`web/src/index.css` 顶层,`@theme` 之外): + +```css +@font-face { + font-family: "Inter"; + src: url("./assets/fonts/InterVariable.woff2") format("woff2"); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} +@font-face { + font-family: "Inter"; + src: url("./assets/fonts/InterVariable-Italic.woff2") format("woff2"); + font-weight: 100 900; + font-style: italic; + font-display: swap; +} +``` + +```css +--font-sans: "Inter", ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", + Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", + "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; +--font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, + "Liberation Mono", monospace; +``` + +- Inter 首顺位覆盖西文与数字;CJK 无 Inter 字形,自然落到 PingFang/雅黑——同字号下 PingFang 字面略大,正文级用 15px 而非 14px 补偿(见 4.2)。 +- Inter 为可变字重字体,§4.2 的 400/500/600/650 四档字重全部原生成立,不再依赖回落。 +- **等宽数字**:不另设字体,统一用 `font-feature-settings: "tnum"`(Tailwind `tabular-nums`),纳入数字专用工具类 `--font-numeric: var(--font-sans)` + 约定所有金额/日期/倒计时必须挂 `tabular-nums`(Inter 的 tnum 特性完整)。 + +### 4.2 字号阶梯(--text-*,含 line-height / 字重 / 字距) + +| token | px | line-height | 字重 | letter-spacing | 语义归属 | +|---|---|---|---|---|---| +| `--text-caption` | 12 | 1.5 (18px) | 400 | 0.01em | 辅助说明、表头、徽章 | +| `--text-body-sm` | 13 | 1.5 (19.5px) | 400 | 0 | 次要正文、列表辅信息 | +| `--text-body` | 15 | 1.6 (24px) | 400 | 0 | 默认正文(中文为主,行高放宽) | +| `--text-body-strong` | 15 | 1.6 | 500 | 0 | 列表主信息、表单值 | +| `--text-title` | 17 | 1.4 (23.8px) | 600 | -0.01em | 卡片标题、分区标题 | +| `--text-heading` | 21 | 1.33 (28px) | 650 | -0.015em | 页面 H1 | +| `--text-display` | 28 | 1.2 (33.6px) | 650 | -0.02em | 详情页主数字/标题 | +| `--text-display-lg` | 36 | 1.15 (41.4px) | 650 | -0.025em | 仪表盘主统计数字(倒计时天数) | + +- 字重仅允许 400/500/600/650 四档(650 由 Inter Variable 原生提供;极端情况下 Inter 加载失败回落系统栈时按 600 渲染,属可接受降级)。 +- 中西文差异:标题级负字距仅作用于西文多的场景;中文占比高时字距归零(约定:含中文的 heading 不加额外 tracking 类)。中文正文行高 1.6,西文正文 1.5 可接受,统一取 1.6。 + +### 4.3 间距阶梯(--spacing-*,4px 基准) + +| token | px | 用途 | +|---|---|---| +| `--spacing-1` | 4 | 图标-文字间隙、徽章内距 | +| `--spacing-2` | 8 | 组件内元素间(表单项 label-input) | +| `--spacing-3` | 12 | 组件内分组间 | +| `--spacing-4` | 16 | 卡片内边距(移动)、列表行内距 | +| `--spacing-6` | 24 | 卡片内边距(桌面)、表单字段组间 | +| `--spacing-8` | 32 | 卡片与卡片间、页面区块间(移动) | +| `--spacing-12` | 48 | 页面区块间(桌面) | +| `--spacing-16` | 64 | 页面级大区块分隔(仪表盘主视觉与列表) | + +规则:区块间距 : 组件内间距 ≈ 2:1 起步(学 Apple),禁止 `space-y-1`/`p-2` 这类 8px 以下值用于区块级。 + +### 4.4 圆角阶梯(--radius-*) + +| token | px | 用途 | +|---|---|---| +| `--radius-xs` | 4 | 徽章、tag、进度条 | +| `--radius-sm` | 6 | 输入框、小按钮 | +| `--radius-md` | 8 | 按钮、下拉项 | +| `--radius-lg` | 12 | 卡片、弹层、对话框 | +| `--radius-xl` | 16 | 页面级容器、底部抽屉 | +| `--radius-full` | 9999px | 头像、进度环、开关 | + +替换现有 `--radius: 0.5rem` 单值派生体系(`index.css:27-30`),改为显式六级。「账本」气质 = 中小圆角为主,卡片 12px 封顶,禁止全站 16px+ 的软糖风。 + +### 4.5 阴影 / elevation(--shadow-*,明暗各一套) + +亮色: + +| token | 值 | 层级 | +|---|---|---| +| `--shadow-1` | `0 1px 2px rgb(0 0 0 / 0.05)` | 静止卡片 | +| `--shadow-2` | `0 1px 3px rgb(0 0 0 / 0.07), 0 4px 12px rgb(0 0 0 / 0.06)` | 悬浮卡片/hover 抬升 | +| `--shadow-3` | `0 4px 8px rgb(0 0 0 / 0.08), 0 12px 32px rgb(0 0 0 / 0.10)` | 下拉/弹出层 | +| `--shadow-4` | `0 8px 16px rgb(0 0 0 / 0.10), 0 24px 48px rgb(0 0 0 / 0.12)` | 对话框/抽屉 | + +暗色(阴影失效,用边框 + 微光补偿): + +| token | 值 | +|---|---| +| `--shadow-1` | `0 0 0 1px rgb(255 255 255 / 0.06)` | +| `--shadow-2` | `0 0 0 1px rgb(255 255 255 / 0.08), 0 4px 12px rgb(0 0 0 / 0.4)` | +| `--shadow-3` | `0 0 0 1px rgb(255 255 255 / 0.10), 0 12px 32px rgb(0 0 0 / 0.5)` | +| `--shadow-4` | `0 0 0 1px rgb(255 255 255 / 0.12), 0 24px 48px rgb(0 0 0 / 0.6)` | + +废止 `shadow-lg` 滥用(20 处)与 `shadow-sm` 混用,统一四级。 + +### 4.6 色彩(--color-*,含对比度实测) + +**品牌主色:Indigo(靛蓝)**——从现行 blue 进化但保持连续性;靛蓝=「精确、账本、夜间可读」,避开通知红的语义冲突。 + +| 角色 | 亮色值 | 对比度(on 白) | 暗色值 | 对比度(on `#0a0a0c`) | +|---|---|---|---|---| +| primary | `#4f46e5` (indigo-600) | 6.29:1 ✅ | `#818cf8` (indigo-400) | 6.63:1 ✅ | +| primary-foreground | `#ffffff` | 6.29:1 ✅(on primary) | `#0a0a0c` | 6.63:1 ✅(on primary) | +| ring/focus | `#4f46e5` | ≥3:1 vs 相邻 ✅ | `#818cf8` | ✅ | + +**中性色阶(8 级,亮色 zinc 系微调,暗色独立调色非反色):** + +亮色:`--n-0:#ffffff(bg)` `--n-50:#fafafa` `--n-100:#f4f4f5(muted bg)` `--n-200:#e4e4e7(border)` `--n-300:#d4d4d8(input border)` `--n-500:#666670(muted fg,on 白 6.10:1 ✅、on muted 5.16:1 ✅)` `--n-700:#3f3f46(次级 fg)` `--n-900:#18181b(主 fg,on 白 17.72:1 ✅)` + +暗色:`--n-900:#0a0a0c(bg)` `--n-850:#111114(card bg)` `--n-800:#1a1a1f(muted bg)` `--n-700:#26262c(border)` `--n-600:#34343c(input border)` `--n-400:#a1a1aa(muted fg,on bg 7.76:1 ✅)` `--n-200:#d4d4d8(次级 fg)` `--n-50:#fafafa(主 fg,on bg 19.06:1 ✅)` + +`--n-*` 是中性色的**唯一来源**;组件入口仍走既有 role token(`background/card/popover/muted/accent/border/input/ring/foreground` 等,见 `index.css:5-26`),role token 的值改为引用 `n-*`,不另设色值。**`n-* → role` 显式映射表(冻结):** + +| role token | 亮色映射 | 暗色映射 | +|---|---|---| +| `--background` | `n-0 #ffffff` | `n-900 #0a0a0c` | +| `--foreground` | `n-900 #18181b` | `n-50 #fafafa` | +| `--card` / `--popover` | `n-0 #ffffff` | `n-850 #111114` | +| `--card-foreground` / `--popover-foreground` | `n-900 #18181b` | `n-50 #fafafa` | +| `--muted` / `--accent` | `n-100 #f4f4f5` | `n-800 #1a1a1f` | +| `--muted-foreground` / `--accent-foreground` | `n-500 #666670` / `n-900` | `n-400 #a1a1aa` / `n-50` | +| `--secondary` | `n-100 #f4f4f5` | `n-800 #1a1a1f` | +| `--secondary-foreground` | `n-900 #18181b` | `n-50 #fafafa` | +| `--border` | `n-200 #e4e4e7` | `n-700 #26262c` | +| `--input` | `n-300 #d4d4d8` | `n-600 #34343c` | +| `--ring` | primary `#4f46e5` | primary `#818cf8` | + +**语义色(成功/警告/信息/危险,亮色 on 白 / 暗色 on #0a0a0c,文本用法均实测):** + +| 语义 | 亮色文本值 | 对比度 | 暗色文本值 | 对比度 | +|---|---|---|---|---| +| success | `#15803d` (green-700) | 5.0:1 ✅ | `#4ade80` | 11.42:1 ✅ | +| warning | `#b45309` (amber-700) | 5.02:1 ✅ | `#fbbf24` | 11.92:1 ✅ | +| info | `#1d4ed8` (blue-700) | 6.7:1 ✅ | `#93c5fd` | 10.97:1 ✅ | +| danger | `#b91c1c` (red-700) | 6.47:1 ✅ | `#f87171` | 7.19:1 ✅ | + +(徽章底用同族 10% 透明度,如 `success/10`。) + +**命名兼容(冻结)**:危险色的实体 token 保留既有名 `--destructive` / `--destructive-foreground`(值写新 danger:亮色 `hsl(0 73.7% 41.8%)` = `#b91c1c`,暗色 `hsl(0 90.6% 70.8%)` = `#f87171`);`danger` 是文档与沟通中的语义名,落地映射为 **`danger → --destructive`**(`bg-danger`/`text-danger` 一律写成 `bg-destructive`/`text-destructive`)。success/warning/info 新增同名 token。 + +**功能色 = 倒计时紧迫梯度(本契约的语义核心,替换现状「一律绿点」):** + +| token | 阈值 | 亮色 | 暗色 | +|---|---|---|---| +| `--color-due-far` | >30 天 | neutral `#666670` | `#a1a1aa` | +| `--color-due-soon` | ≤30 天 | `#4f46e5` | `#818cf8` | +| `--color-due-close` | ≤7 天 | `#b45309` | `#fbbf24` | +| `--color-due-over` | 逾期 | `#b91c1c` | `#f87171` | + +### 4.7 动效(--ease-* + --duration-*) + +```css +--duration-fast: 120ms; /* hover、按下、开关 */ +--duration-standard: 200ms; /* 展开/收起、tooltip、tab 切换 */ +--duration-slow: 320ms; /* 页面转场、抽屉、骨架退场 */ + +--ease-out: cubic-bezier(0.22, 1, 0.36, 1); /* 进入/出现(强调) */ +--ease-in: cubic-bezier(0.64, 0, 0.78, 0); /* 退出/消失 */ +--ease-standard: cubic-bezier(0.2, 0, 0, 1); /* 通用状态变化 */ +``` + +规则:交互反馈一律 ≤200ms(Linear 边界);位移类只用 transform/opacity;禁用 bounce/elastic;列表入场 stagger 步长 40ms、上限 6 项;`prefers-reduced-motion` 时全部降级为 opacity 淡变(Stage 3 实现时纳入全局 media query)。 + +--- + +## 5. 落地映射:19 页面 + AppLayout 改动清单 + +> 「结构」= 不只是换 token,需要调整 DOM/组件结构。 + +| 页面 | 改动 | +|---|---| +| `AppLayout` | 结构:移动端底栏激活态加共享 pill 指示器(layoutId 滑动,200ms ease-out);桌面侧栏激活项用 `--color-primary/10` + 左侧 2px 指示条;移除硬编码 `bg-yellow-500/90`/`bg-blue-500/90` 横幅 → info/warning 语义 token;`text-xl font-bold` 的 appName → `--text-title`。 | +| `dashboard` | 结构:主视觉区改为「最近到期 Top 卡片」——大号 `--text-display-lg` tabular 倒计时数字 + 环形剩余进度(新组件 `DueRing`);统计卡 4 → 3(本月支出/30 天内到期/已逾期),数字用 display 级;骨架屏改为与内容同形态(stagger 40ms)。 | +| `items`(列表) | 结构:桌面行右侧新增「金额 + 天数」右对齐 tabular 分录栏;「43d」绿点 → 环形微进度 + 天数(due-* 梯度着色);移动端卡片重构:主行(名称+天数大数字)/ 次行(日期+分类)/ 操作收进溢出菜单(可见操作 ≤2:编辑+更多)。 | +| `items/new`、`items/:id`(详情 46.9K) | 结构:表单分区(基本信息 / 周期与到期 / 提醒与渠道 / 备注),分区标题 `--text-title` + `--spacing-8` 分隔;桌面双栏(左字段右摘要预览卡:实时到期倒计时环);移动端分区手风琴;日期/周期输入行改 grid 2 列。 | +| `channels` | 卡片标题层级修正(CardTitle → `--text-title`);渠道启用状态徽标接 success/due token;测试按钮结果反馈加 200ms 状态动画。 | +| `history` | 时间线化:按日分组,组标题 sticky + `--text-caption` 大写字距;发送状态图标 success/danger token;空状态插画位 → 纯排版空态(display 级图标 + 一行文案 + CTA)。 | +| `me` | 用户卡改「账本头」:头像 + 邮箱 + 当月到期笔数统计(tabular display 数字)。 | +| `settings`(47.4K,最大页) | 结构:tab 栏激活态加下划线滑动动画(200ms);表单分区同 items 规则;`animate-pulse` 灰块(595/821 行)→ 同形态骨架。 | +| `about` | 排版页:版本/链接信息用分录式定义列表(左 caption 右 body-strong)。 | +| `admin` ×5(admin/users/email/security/app) | 表格行高统一 `--spacing-4`;`AdminUsersPage` 骨架(365-369 行)→ 行形态骨架;危险操作按钮统一 danger token + ConfirmDialog 入场 320ms ease-out。 | +| `auth` ×5(login/register/forgot/2fa/verify-email) | 居中卡升级:卡宽 400px、`--shadow-2`、logo 区 `--text-display`;输入错误态:边框 danger + 文案 200ms 滑入;提交按钮 loading 态(spinner + 文案宽度保持)。 | +| `setup` | 同 auth 卡规范;步骤指示器用 due 环形语言呼应主视觉。 | + +--- + +## 附录 A:契约修订记录 + +### A-1(ONE-70,2026-10-23,Mike 授权修订) + +- **问题**:冻结值 `muted-foreground on muted`(`n-500 #71717a` on `n-100 #f4f4f5`)实测对比度 4.39:1,低于父单 color 维度的 AA 正文指标(≥4.5:1),差 0.11。 +- **修订**:亮色 `n-500` 由 `240 3.8% 46.1%`(`#71717a`)调整为 `240 4.9% 42%`(`#666670`)。同步引用该值的 token:`--muted-foreground`(亮色)与 `--due-far`(亮色)。 +- **达标后对比度**:`n-500 on n-100` = **5.16:1** ✅;`n-500 on n-0`(白底)= **6.10:1** ✅。暗色组合(`n-400 on n-800` = 6.76:1)原本达标,未动。 + +--- + +## 6. 契约边界(与冻结条款对齐) + +- **唯一契约**:本文件是唯一冻结契约。历史文档 `web/docs/design-contract.md`(存在于旧分支 `agent/mary/a19f619bb981` / `ed2f1ad360d5`,未进 main)**已退役**,不再作为任何实现依据;若其所在分支后续合并,必须删除该文件或以醒目批注指向本文档。 +- 令牌只写 `web/src/index.css` `@theme inline`;`.dark` 维护同名覆盖(含 4.5 暗色阴影套)。 +- 字体资产入仓于 `web/src/assets/fonts/`,`@font-face` 声明于 `index.css` 顶层;不引入新框架/组件库/动画库/外部字体 CDN。 +- 不动 `worker/`、路由、API、既有 i18n key 语义。 +- 命名兼容:`danger → --destructive`(见 §4.6);其余令牌按本文档 §4 命名原样保留,旧引用(6 个 `ui/*` 组件 + `AppLayout` 中的 shadow/rounded 等旧名)由 Stage 2 落地时统一替换。 +- 本单不写实现代码;实现由后续 Stage 子单按本文执行。 diff --git a/web/src/assets/fonts/INTER-LICENSE.txt b/web/src/assets/fonts/INTER-LICENSE.txt new file mode 100644 index 0000000..9b2ca37 --- /dev/null +++ b/web/src/assets/fonts/INTER-LICENSE.txt @@ -0,0 +1,92 @@ +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/web/src/assets/fonts/InterVariable-Italic.woff2 b/web/src/assets/fonts/InterVariable-Italic.woff2 new file mode 100644 index 0000000..b3530f3 Binary files /dev/null and b/web/src/assets/fonts/InterVariable-Italic.woff2 differ diff --git a/web/src/assets/fonts/InterVariable.woff2 b/web/src/assets/fonts/InterVariable.woff2 new file mode 100644 index 0000000..5a8d3e7 Binary files /dev/null and b/web/src/assets/fonts/InterVariable.woff2 differ diff --git a/web/src/components/AuthShell.tsx b/web/src/components/AuthShell.tsx new file mode 100644 index 0000000..50568cb --- /dev/null +++ b/web/src/components/AuthShell.tsx @@ -0,0 +1,48 @@ +import type { ReactNode } from "react"; +import { cn } from "@/lib/utils"; + +/** + * Centered auth card — shared by login/register/forgot/2fa/verify-email/setup + * (design contract §5: 400px width, shadow-2, display-level logo area). + */ +export function AuthShell({ + title, + subtitle, + children, + className, +}: { + title: ReactNode; + subtitle?: ReactNode; + children: ReactNode; + className?: string; +}) { + return ( +
+
+
+
+

{title}

+ {subtitle && ( +

+ {subtitle} +

+ )} +
+ {children} +
+
+
+ ); +} + +/** Inline form error that slides in (200ms, contract §5 auth). */ +export function FormError({ children }: { children: ReactNode }) { + return ( +

+ {children} +

+ ); +} diff --git a/web/src/components/ConfirmDialog.tsx b/web/src/components/ConfirmDialog.tsx index 11b7626..40427ff 100644 --- a/web/src/components/ConfirmDialog.tsx +++ b/web/src/components/ConfirmDialog.tsx @@ -1,4 +1,5 @@ import { AlertTriangle } from "lucide-react"; +import { useFocusTrap } from "@/hooks/useFocusTrap"; interface ConfirmDialogProps { open: boolean; @@ -21,6 +22,8 @@ export function ConfirmDialog({ onConfirm, onCancel, }: ConfirmDialogProps) { + const trapRef = useFocusTrap(open, onCancel); + if (!open) return null; return ( @@ -31,7 +34,10 @@ export function ConfirmDialog({ className="absolute inset-0 bg-black/40" onClick={onCancel} /> -
+
- {title &&

{title}

} -

{message}

+ {title &&

{title}

} +

{message}

@@ -56,7 +62,7 @@ export function ConfirmDialog({ type="button" onClick={onConfirm} className={cn( - "px-4 py-2 rounded-lg text-sm font-medium transition-colors", + "px-4 py-2 rounded-md text-body-sm font-medium transition-colors", variant === "danger" ? "bg-destructive text-destructive-foreground hover:bg-destructive/90" : "bg-primary text-primary-foreground hover:bg-primary/90", diff --git a/web/src/components/DueRing.tsx b/web/src/components/DueRing.tsx new file mode 100644 index 0000000..3749225 --- /dev/null +++ b/web/src/components/DueRing.tsx @@ -0,0 +1,129 @@ +import { useTranslation } from "react-i18next"; +import { cn } from "@/lib/utils"; + +/** + * Countdown urgency tiers — the single semantic color gradient of the + * design system (design contract §3.1 / §4.6). + */ +export type DueTier = "far" | "soon" | "close" | "over"; + +export function getDueTier(days: number): DueTier { + if (days < 0) return "over"; + if (days <= 7) return "close"; + if (days <= 30) return "soon"; + return "far"; +} + +const TIER_TEXT: Record = { + far: "text-due-far", + soon: "text-due-soon", + close: "text-due-close", + over: "text-due-over", +}; + +const TIER_BADGE: Record = { + far: "bg-due-far/10 text-due-far", + soon: "bg-due-soon/10 text-due-soon", + close: "bg-due-close/10 text-due-close", + over: "bg-due-over/10 text-due-over", +}; + +export function dueTierTextClass(days: number): string { + return TIER_TEXT[getDueTier(days)]; +} + +export function dueTierBadgeClass(days: number): string { + return TIER_BADGE[getDueTier(days)]; +} + +/** Circular remaining-progress ring (design contract §3.1 — countdown is first-class). */ +export function DueRing({ + days, + progress, + size = 28, + strokeWidth = 3, + className, +}: { + days: number; + /** 0..1 — fraction of the period still remaining */ + progress: number; + size?: number; + strokeWidth?: number; + className?: string; +}) { + const { t } = useTranslation(); + const tier = getDueTier(days); + const r = (size - strokeWidth) / 2; + const c = 2 * Math.PI * r; + const clamped = Math.max(0, Math.min(1, progress)); + const ariaLabel = + days < 0 + ? t("common.overdueBy", { count: -days }) + : t("common.daysLeftShort", { count: days }); + return ( + + + + + ); +} + +/** Ledger-style countdown: large tabular numeral + small unit (§3.1, Cron-style asymmetric type). */ +export function DueCount({ + days, + unit, + size = "md", + className, +}: { + days: number; + unit: string; + size?: "sm" | "md" | "lg"; + className?: string; +}) { + const tier = getDueTier(days); + const numCls = + size === "lg" + ? "text-display-lg" + : size === "md" + ? "text-display" + : "text-title"; + return ( + + + {days < 0 ? `-${Math.abs(days)}` : days} + + {unit} + + ); +} diff --git a/web/src/components/PasswordPromptDialog.tsx b/web/src/components/PasswordPromptDialog.tsx index 9d2aa0a..64ab621 100644 --- a/web/src/components/PasswordPromptDialog.tsx +++ b/web/src/components/PasswordPromptDialog.tsx @@ -1,5 +1,6 @@ import { useState } from "react"; import { useTranslation } from "react-i18next"; +import { useFocusTrap } from "@/hooks/useFocusTrap"; interface PasswordPromptDialogProps { open: boolean; @@ -17,13 +18,15 @@ export function PasswordPromptDialog({ const { t } = useTranslation(); const [password, setPassword] = useState(""); - if (!open) return null; + const trapRef = useFocusTrap(open, onCancel); const close = () => { setPassword(""); onCancel(); }; + if (!open) return null; + return (
{open && ( -
+

{user?.email}

@@ -199,9 +199,15 @@ export function AppLayout() { return (
{/* Desktop sidebar */} -
{impersonating && ( -
+
{t("admin.impersonating", { defaultValue: "Impersonating another user", @@ -254,7 +260,7 @@ export function AppLayout() { )} {needRefresh && ( -
+
{t("pwa.updateAvailable")}
+ )} +
+ ); +} diff --git a/web/src/components/ui/button.tsx b/web/src/components/ui/button.tsx index 62b5f54..9f6b16b 100644 --- a/web/src/components/ui/button.tsx +++ b/web/src/components/ui/button.tsx @@ -4,25 +4,26 @@ import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "@/lib/utils"; const buttonVariants = cva( - "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-body-sm font-medium ring-offset-background transition-[color,background-color,border-color,box-shadow,transform] duration-(--duration-fast) ease-(--ease-standard) focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50", { variants: { variant: { - default: "bg-primary text-primary-foreground hover:bg-primary/90", + default: + "bg-primary text-primary-foreground shadow-1 hover:bg-primary/90", destructive: - "bg-destructive text-destructive-foreground hover:bg-destructive/90", + "bg-destructive text-destructive-foreground shadow-1 hover:bg-destructive/90", outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground", secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", ghost: "hover:bg-accent hover:text-accent-foreground", - link: "text-primary underline-offset-4 hover:underline", + link: "text-primary underline-offset-4 hover:underline active:scale-100", }, size: { default: "h-10 px-4 py-2", - sm: "h-9 rounded-md px-3", - lg: "h-11 rounded-md px-8", - icon: "h-10 w-10", + sm: "h-9 px-3", + lg: "h-11 px-8", + icon: "h-11 w-11", }, }, defaultVariants: { diff --git a/web/src/components/ui/card.tsx b/web/src/components/ui/card.tsx index d305169..e973a93 100644 --- a/web/src/components/ui/card.tsx +++ b/web/src/components/ui/card.tsx @@ -8,7 +8,7 @@ const Card = React.forwardRef<
(({ className, ...props }, ref) => (
)); @@ -32,14 +32,7 @@ const CardTitle = React.forwardRef< HTMLParagraphElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( -

+

)); CardTitle.displayName = "CardTitle"; @@ -49,7 +42,7 @@ const CardDescription = React.forwardRef< >(({ className, ...props }, ref) => (

)); @@ -59,7 +52,11 @@ const CardContent = React.forwardRef< HTMLDivElement, React.HTMLAttributes >(({ className, ...props }, ref) => ( -

+
)); CardContent.displayName = "CardContent"; @@ -69,7 +66,7 @@ const CardFooter = React.forwardRef< >(({ className, ...props }, ref) => (
)); diff --git a/web/src/components/ui/input.tsx b/web/src/components/ui/input.tsx index 82c077a..c5eaee7 100644 --- a/web/src/components/ui/input.tsx +++ b/web/src/components/ui/input.tsx @@ -9,7 +9,7 @@ const Input = React.forwardRef< (({ className, ...props }, ref) => ( diff --git a/web/src/components/ui/tabs.tsx b/web/src/components/ui/tabs.tsx index a9ec550..1181b1f 100644 --- a/web/src/components/ui/tabs.tsx +++ b/web/src/components/ui/tabs.tsx @@ -26,7 +26,7 @@ const TabsTrigger = React.forwardRef< ( + active: boolean, + onEscape?: () => void, +) { + const ref = useRef(null); + const restoreRef = useRef(null); + const escapeRef = useRef(onEscape); + escapeRef.current = onEscape; + + useEffect(() => { + if (!active) return; + const node = ref.current; + if (!node) return; + + restoreRef.current = document.activeElement as HTMLElement | null; + + const focusables = () => + Array.from( + node.querySelectorAll( + 'a[href], button:not([disabled]), textarea, input, select, [tabindex]:not([tabindex="-1"])', + ), + ).filter( + (el) => el.offsetParent !== null || el === document.activeElement, + ); + + // initial focus: first focusable, else the container itself + const first = focusables()[0]; + if (first) first.focus(); + else { + node.setAttribute("tabindex", "-1"); + node.focus(); + } + + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") { + e.stopPropagation(); + escapeRef.current?.(); + return; + } + if (e.key !== "Tab") return; + const items = focusables(); + if (items.length === 0) { + e.preventDefault(); + return; + } + const firstItem = items[0]; + const lastItem = items[items.length - 1]; + const current = document.activeElement as HTMLElement | null; + if (e.shiftKey) { + if (!current || current === firstItem || !node.contains(current)) { + e.preventDefault(); + lastItem.focus(); + } + } else if (!current || current === lastItem || !node.contains(current)) { + e.preventDefault(); + firstItem.focus(); + } + }; + + document.addEventListener("keydown", onKeyDown, true); + return () => { + document.removeEventListener("keydown", onKeyDown, true); + restoreRef.current?.focus?.(); + }; + }, [active]); + + return ref; +} diff --git a/web/src/index.css b/web/src/index.css index be218b4..610ddb1 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -2,7 +2,38 @@ @custom-variant dark (&:is(.dark *)); +/* Self-hosted Inter Variable — design contract §4.1 */ +@font-face { + font-family: "Inter"; + src: url("./assets/fonts/InterVariable.woff2") format("woff2"); + font-weight: 100 900; + font-style: normal; + font-display: swap; +} +@font-face { + font-family: "Inter"; + src: url("./assets/fonts/InterVariable-Italic.woff2") format("woff2"); + font-weight: 100 900; + font-style: italic; + font-display: swap; +} + @theme inline { + /* Neutral scale — sole source (design contract §4.6) */ + --color-n-0: hsl(var(--n-0)); + --color-n-50: hsl(var(--n-50)); + --color-n-100: hsl(var(--n-100)); + --color-n-200: hsl(var(--n-200)); + --color-n-300: hsl(var(--n-300)); + --color-n-400: hsl(var(--n-400)); + --color-n-500: hsl(var(--n-500)); + --color-n-600: hsl(var(--n-600)); + --color-n-700: hsl(var(--n-700)); + --color-n-800: hsl(var(--n-800)); + --color-n-850: hsl(var(--n-850)); + --color-n-900: hsl(var(--n-900)); + + /* Role tokens (n-* → role mapping, design contract §4.6) */ --color-background: hsl(var(--background)); --color-foreground: hsl(var(--foreground)); --color-card: hsl(var(--card)); @@ -19,36 +50,134 @@ --color-accent-foreground: hsl(var(--accent-foreground)); --color-destructive: hsl(var(--destructive)); --color-destructive-foreground: hsl(var(--destructive-foreground)); + --color-success: hsl(var(--success)); + --color-success-foreground: hsl(var(--success-foreground)); + --color-warning: hsl(var(--warning)); + --color-warning-foreground: hsl(var(--warning-foreground)); + --color-info: hsl(var(--info)); + --color-info-foreground: hsl(var(--info-foreground)); --color-border: hsl(var(--border)); --color-input: hsl(var(--input)); --color-ring: hsl(var(--ring)); - --radius-sm: calc(var(--radius) - 4px); - --radius-md: calc(var(--radius) - 2px); - --radius-lg: var(--radius); - --radius-xl: calc(var(--radius) + 4px); + + /* Countdown urgency gradient (design contract §4.6) */ + --color-due-far: hsl(var(--due-far)); + --color-due-soon: hsl(var(--due-soon)); + --color-due-close: hsl(var(--due-close)); + --color-due-over: hsl(var(--due-over)); + + /* Typography — design contract §4.1/§4.2 */ + --font-sans: + "Inter", ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, + "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", + "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; + --font-mono: + ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", + monospace; + + --text-caption: 0.75rem; + --text-caption--line-height: 1.5; + --text-caption--letter-spacing: 0.01em; + --text-body-sm: 0.8125rem; + --text-body-sm--line-height: 1.5; + --text-body: 0.9375rem; + --text-body--line-height: 1.6; + --text-body-strong: 0.9375rem; + --text-body-strong--line-height: 1.6; + --text-body-strong--font-weight: 500; + --text-title: 1.0625rem; + --text-title--line-height: 1.4; + --text-title--font-weight: 600; + --text-title--letter-spacing: -0.01em; + --text-heading: 1.3125rem; + --text-heading--line-height: 1.33; + --text-heading--font-weight: 650; + --text-heading--letter-spacing: -0.015em; + --text-display: 1.75rem; + --text-display--line-height: 1.2; + --text-display--font-weight: 650; + --text-display--letter-spacing: -0.02em; + --text-display-lg: 2.25rem; + --text-display-lg--line-height: 1.15; + --text-display-lg--font-weight: 650; + --text-display-lg--letter-spacing: -0.025em; + + --font-weight-regular: 400; + --font-weight-medium: 500; + --font-weight-semibold: 600; + --font-weight-display: 650; + + /* Radius ladder — design contract §4.4 */ + --radius-xs: 4px; + --radius-sm: 6px; + --radius-md: 8px; + --radius-lg: 12px; + --radius-xl: 16px; + + /* Shadow / elevation ladder — design contract §4.5 */ + --shadow-1: 0 1px 2px rgb(0 0 0 / 0.05); + --shadow-2: 0 1px 3px rgb(0 0 0 / 0.07), 0 4px 12px rgb(0 0 0 / 0.06); + --shadow-3: 0 4px 8px rgb(0 0 0 / 0.08), 0 12px 32px rgb(0 0 0 / 0.1); + --shadow-4: 0 8px 16px rgb(0 0 0 / 0.1), 0 24px 48px rgb(0 0 0 / 0.12); + + /* Motion — design contract §4.7 */ + --duration-fast: 120ms; + --duration-standard: 200ms; + --duration-slow: 320ms; + --ease-out: cubic-bezier(0.22, 1, 0.36, 1); + --ease-in: cubic-bezier(0.64, 0, 0.78, 0); + --ease-standard: cubic-bezier(0.2, 0, 0, 1); } :root { + /* Neutral scale (light) */ + --n-0: 0 0% 100%; + --n-50: 0 0% 98%; + --n-100: 240 4.8% 95.9%; + --n-200: 240 5.9% 90%; + --n-300: 240 4.9% 83.9%; + --n-400: 240 5% 64.9%; + --n-500: 240 4.9% 42%; + --n-600: 240 7.1% 22%; + --n-700: 240 5.3% 26.1%; + --n-800: 240 8.8% 11.2%; + --n-850: 240 8.1% 7.3%; + --n-900: 240 5.9% 10%; + + /* n-* → role (light), design contract §4.6 mapping table. + NOTE: raw channel values (not var() refs) — Tailwind v4 hoists var() + dependencies into :root, which would freeze these at light values. */ --background: 0 0% 100%; - --foreground: 222.2 84% 4.9%; + --foreground: 240 5.9% 10%; --card: 0 0% 100%; - --card-foreground: 222.2 84% 4.9%; + --card-foreground: 240 5.9% 10%; --popover: 0 0% 100%; - --popover-foreground: 222.2 84% 4.9%; - --primary: 221.2 83.2% 53.3%; - --primary-foreground: 210 40% 98%; - --secondary: 210 40% 96.1%; - --secondary-foreground: 222.2 47.4% 11.2%; - --muted: 210 40% 96.1%; - --muted-foreground: 215.4 16.3% 46.9%; - --accent: 210 40% 96.1%; - --accent-foreground: 222.2 47.4% 11.2%; - --destructive: 0 84.2% 60.2%; - --destructive-foreground: 210 40% 98%; - --border: 214.3 31.8% 91.4%; - --input: 214.3 31.8% 91.4%; - --ring: 221.2 83.2% 53.3%; - --radius: 0.5rem; + --popover-foreground: 240 5.9% 10%; + --primary: 243.4 75.4% 58.6%; + --primary-foreground: 0 0% 100%; + --secondary: 240 4.8% 95.9%; + --secondary-foreground: 240 5.9% 10%; + --muted: 240 4.8% 95.9%; + --muted-foreground: 240 4.9% 42%; + --accent: 240 4.8% 95.9%; + --accent-foreground: 240 5.9% 10%; + --destructive: 0 73.7% 41.8%; + --destructive-foreground: 0 0% 100%; + --success: 142.4 71.8% 29.2%; + --success-foreground: 0 0% 100%; + --warning: 26 90.5% 37.1%; + --warning-foreground: 0 0% 100%; + --info: 224.3 76.3% 48%; + --info-foreground: 0 0% 100%; + --border: 240 5.9% 90%; + --input: 240 4.9% 83.9%; + --ring: 243.4 75.4% 58.6%; + + /* Countdown urgency gradient (light) */ + --due-far: 240 4.9% 42%; + --due-soon: 243.4 75.4% 58.6%; + --due-close: 26 90.5% 37.1%; + --due-over: 0 73.7% 41.8%; } html { @@ -57,25 +186,64 @@ html { } .dark { - --background: 0 0% 0%; - --foreground: 0 0% 92%; - --card: 0 0% 11%; - --card-foreground: 0 0% 92%; - --popover: 0 0% 11%; - --popover-foreground: 0 0% 92%; - --primary: 211 100% 50%; - --primary-foreground: 0 0% 100%; - --secondary: 0 0% 17%; - --secondary-foreground: 0 0% 92%; - --muted: 0 0% 17%; - --muted-foreground: 0 0% 56%; - --accent: 0 0% 17%; - --accent-foreground: 0 0% 92%; - --destructive: 0 100% 45%; - --destructive-foreground: 0 0% 100%; - --border: 0 0% 20%; - --input: 0 0% 20%; - --ring: 211 100% 50%; + /* Neutral scale (dark) — same-name coverage over the light set. + Dark semantic slots declared per contract: n-900=bg, n-850=card, n-800=muted, + n-700=border, n-600=input, n-400=muted-fg, n-200=secondary-fg, n-50=fg. + n-0/n-100/n-300/n-500 are not assigned a semantic slot in dark; they are + overridden to their dark-mode visual equivalents so no stale light value + leaks through (n-500: same visual as n-400). */ + --n-0: 0 0% 100%; + --n-50: 0 0% 98%; + --n-100: 240 8.8% 11.2%; + --n-200: 240 5.9% 83.9%; + --n-300: 240 7.1% 22%; + --n-400: 240 5% 64.9%; + --n-500: 240 5% 64.9%; + --n-600: 240 7.1% 22%; + --n-700: 240 7.3% 16.1%; + --n-800: 240 8.8% 11.2%; + --n-850: 240 8.1% 7.3%; + --n-900: 240 9.1% 4.3%; + + /* n-* → role (dark), design contract §4.6 mapping table (raw channels, + same no-var() reason as the light block above) */ + --background: 240 9.1% 4.3%; + --foreground: 0 0% 98%; + --card: 240 8.1% 7.3%; + --card-foreground: 0 0% 98%; + --popover: 240 8.1% 7.3%; + --popover-foreground: 0 0% 98%; + --primary: 234.5 89.5% 73.9%; + --primary-foreground: 240 9.1% 4.3%; + --secondary: 240 8.8% 11.2%; + --secondary-foreground: 0 0% 98%; + --muted: 240 8.8% 11.2%; + --muted-foreground: 240 5% 64.9%; + --accent: 240 8.8% 11.2%; + --accent-foreground: 0 0% 98%; + --destructive: 0 90.6% 70.8%; + --destructive-foreground: 240 9.1% 4.3%; + --success: 141.9 69.2% 58%; + --success-foreground: 240 9.1% 4.3%; + --warning: 43.3 96.4% 56.3%; + --warning-foreground: 240 9.1% 4.3%; + --info: 211.7 96.4% 78.4%; + --info-foreground: 240 9.1% 4.3%; + --border: 240 7.3% 16.1%; + --input: 240 7.1% 22%; + --ring: 234.5 89.5% 73.9%; + + /* Countdown urgency gradient (dark) */ + --due-far: 240 5% 64.9%; + --due-soon: 234.5 89.5% 73.9%; + --due-close: 43.3 96.4% 56.3%; + --due-over: 0 90.6% 70.8%; + + /* Dark elevation: borders + glow instead of drop shadows (§4.5) */ + --shadow-1: 0 0 0 1px rgb(255 255 255 / 0.06); + --shadow-2: 0 0 0 1px rgb(255 255 255 / 0.08), 0 4px 12px rgb(0 0 0 / 0.4); + --shadow-3: 0 0 0 1px rgb(255 255 255 / 0.1), 0 12px 32px rgb(0 0 0 / 0.5); + --shadow-4: 0 0 0 1px rgb(255 255 255 / 0.12), 0 24px 48px rgb(0 0 0 / 0.6); } * { @@ -85,10 +253,39 @@ html { body { background-color: hsl(var(--background)); color: hsl(var(--foreground)); + font-family: var(--font-sans); + font-size: var(--text-body); + line-height: 1.6; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); } +/* Tabular figures for amounts, dates and countdowns */ +.tnum { + font-variant-numeric: tabular-nums; +} + +/* Form error slide-in (design contract §5 auth) */ +@keyframes form-error-in { + from { + opacity: 0; + transform: translateY(-4px); + } + to { + opacity: 1; + transform: none; + } +} + +/* Respect reduced motion — design contract §4.7. + Unlayered rule beats Tailwind's layered utilities; avoids !important (biome noImportantStyles). */ +@media (prefers-reduced-motion: reduce) { + :root :is(*, *::before, *::after) { + animation-duration: 0.01ms; + transition-duration: 0.01ms; + } +} + select { color-scheme: light; } diff --git a/web/src/lib/utils.ts b/web/src/lib/utils.ts index ea2f9a1..5f5a1dd 100644 --- a/web/src/lib/utils.ts +++ b/web/src/lib/utils.ts @@ -5,6 +5,19 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } +/** Local YYYY-MM-DD today — shared by countdown/status calculations. */ +export function localToday(): string { + const d = new Date(); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`; +} + +/** Days from today until a YYYY-MM-DD date (negative = overdue). */ +export function daysUntil(date: string): number { + return Math.ceil( + (new Date(date).getTime() - new Date(localToday()).getTime()) / 86400000, + ); +} + function bufferToBase64url(buffer: ArrayBuffer): string { const bytes = new Uint8Array(buffer); let binary = ""; diff --git a/web/src/locales/en.json b/web/src/locales/en.json index df1e9f0..f6d5a1e 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -35,7 +35,11 @@ "period": "Period", "confirmDelete": "Delete \"{{name}}\"?", "confirmDeletePayment": "Delete this payment?", - "notificationSent": "Notification sent!" + "notificationSent": "Notification sent!", + "retry": "Retry", + "more": "More", + "daysLeftShort": "{{count}} days left", + "overdueBy": "Overdue by {{count}} days" }, "auth": { "login": "Login", @@ -71,7 +75,8 @@ "resendCode": "Resend code", "resendCodeCountdown": "Resend ({{seconds}}s)", "resetCodeCooldown": "Too many requests, please try again later", - "backToLogin": "Back to login" + "backToLogin": "Back to login", + "loading": "Please wait…" }, "nav": { "dashboard": "Dashboard", @@ -93,7 +98,7 @@ "yearlyExpense": "Yearly Expense", "monthlyAverage": "Monthly Avg", "activeCount": "Active Notifications", - "expiringSoon": "Expiring Soon", + "expiringSoon": "Due in 7 days", "upcomingRenewals": "Upcoming Renewals", "recentPayments": "Recent Payments", "categoryRanking": "By Category", @@ -105,7 +110,15 @@ "regularSection": "Regular Reminders", "activeRegularCount": "Active Reminders", "upcomingReminders": "Upcoming Reminders", - "regularCategoryRanking": "By Category (count)" + "regularCategoryRanking": "By Category (count)", + "overdue": "Overdue", + "expiring30": "Due in 30 days", + "daysUnit": "d", + "nextDue": "Next due", + "monthSpent": "This month", + "noUpcoming": "Nothing due soon", + "expiring7": "Due in 7 days", + "activeTotal": "Active items" }, "items": { "title": "Notifications", @@ -157,7 +170,7 @@ "expired": "Expired", "expiringSoon": "Expiring Soon" }, - "daysRemaining": "{{days}} days remaining", + "daysRemaining": "Days left", "expired": "Expired {{days}} days ago", "notFound": "Notification not found", "paymentType": { @@ -185,7 +198,13 @@ "filterAll": "All", "searchPlaceholder": "Search notifications...", "sortExpiry": "Expiry", - "statusAll": "All Status" + "statusAll": "All Status", + "daysShort": "{{count}}d", + "overdueShort": "{{count}}d overdue", + "emptyTitle": "No entries yet", + "emptyDesc": "Add your first subscription or reminder to start your ledger of time.", + "amountDue": "Amount", + "moreActions": "More actions" }, "settings": { "title": "Settings", @@ -275,7 +294,10 @@ "noData": "No notification records yet", "detail": "Notification Detail", "content": "Message Content", - "noContent": "No message content for this record" + "noContent": "No message content for this record", + "emptyTitle": "No history yet", + "emptyDesc": "Sent notifications will be recorded here.", + "loadError": "Failed to load history" }, "admin": { "title": "Admin Panel", @@ -395,6 +417,22 @@ "missingSecret": "Please enter the setup secret.", "wrongSecret": "Incorrect setup secret.", "rateLimited": "Too many requests, please try again later.", - "genericError": "Initialization failed, please try again later." + "genericError": "Initialization failed, please try again later.", + "stepInit": "Initialize", + "stepDone": "Done" + }, + "me": { + "dueThisMonth": "Due in 7 days", + "entries": "entries", + "due7": "Due in 7 days" + }, + "detail": { + "sectionBasic": "Basic info", + "sectionCycle": "Cycle & expiry", + "sectionReminder": "Reminder & channels", + "sectionNotes": "Notes", + "summary": "Due preview", + "daysLeft": "remaining", + "daysUnit": "d" } } diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index e7a14f2..e912595 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -35,7 +35,11 @@ "period": "周期", "confirmDelete": "确定删除 \"{{name}}\"?", "confirmDeletePayment": "确定删除该支付记录?", - "notificationSent": "通知已发送!" + "notificationSent": "通知已发送!", + "retry": "重试", + "more": "更多", + "daysLeftShort": "剩余 {{count}} 天", + "overdueBy": "已逾期 {{count}} 天" }, "auth": { "login": "登录", @@ -71,7 +75,8 @@ "resendCode": "重新发送验证码", "resendCodeCountdown": "重新发送 ({{seconds}}s)", "resetCodeCooldown": "请求过于频繁,请稍后再试", - "backToLogin": "返回登录" + "backToLogin": "返回登录", + "loading": "请稍候…" }, "nav": { "dashboard": "仪表盘", @@ -93,7 +98,7 @@ "yearlyExpense": "年度支出", "monthlyAverage": "月均", "activeCount": "活跃通知", - "expiringSoon": "即将到期", + "expiringSoon": "7 天内到期", "upcomingRenewals": "即将续费", "recentPayments": "近期支付", "categoryRanking": "分类排行", @@ -105,7 +110,15 @@ "regularSection": "普通提醒", "activeRegularCount": "活跃普通提醒", "upcomingReminders": "即将到期提醒", - "regularCategoryRanking": "分类排行(条数)" + "regularCategoryRanking": "分类排行(条数)", + "overdue": "已逾期", + "expiring30": "30 天内到期", + "daysUnit": "天", + "nextDue": "最近到期", + "monthSpent": "本月支出", + "noUpcoming": "暂无即将到期事项", + "expiring7": "7 天内到期", + "activeTotal": "活跃条目" }, "items": { "title": "通知管理", @@ -157,7 +170,7 @@ "expired": "已过期", "expiringSoon": "即将到期" }, - "daysRemaining": "剩余 {{days}} 天", + "daysRemaining": "剩余天数", "expired": "已过期 {{days}} 天", "notFound": "未找到该通知", "paymentType": { @@ -185,7 +198,13 @@ "filterAll": "全部", "searchPlaceholder": "搜索通知...", "sortExpiry": "到期日", - "statusAll": "全部状态" + "statusAll": "全部状态", + "daysShort": "{{count}} 天", + "overdueShort": "逾期 {{count}} 天", + "emptyTitle": "还没有任何账目", + "emptyDesc": "添加第一笔订阅或提醒,开始记录你的时间账本。", + "amountDue": "金额", + "moreActions": "更多操作" }, "settings": { "title": "设置", @@ -275,7 +294,10 @@ "noData": "暂无通知记录", "detail": "通知详情", "content": "消息内容", - "noContent": "该记录无消息内容" + "noContent": "该记录无消息内容", + "emptyTitle": "还没有发送记录", + "emptyDesc": "通知发出后会在这里留下账目。", + "loadError": "发送记录加载失败" }, "admin": { "title": "管理后台", @@ -395,6 +417,22 @@ "missingSecret": "请输入密钥。", "wrongSecret": "密钥错误,请检查后重试。", "rateLimited": "请求过于频繁,请稍后再试。", - "genericError": "初始化失败,请稍后再试。" + "genericError": "初始化失败,请稍后再试。", + "stepInit": "初始化", + "stepDone": "完成" + }, + "me": { + "dueThisMonth": "7 天内到期", + "entries": "笔", + "due7": "7 天内到期" + }, + "detail": { + "sectionBasic": "基本信息", + "sectionCycle": "周期与到期", + "sectionReminder": "提醒与渠道", + "sectionNotes": "备注", + "summary": "到期预览", + "daysLeft": "剩余", + "daysUnit": "天" } } diff --git a/web/src/pages/about/AboutPage.tsx b/web/src/pages/about/AboutPage.tsx index 038500f..9548e0b 100644 --- a/web/src/pages/about/AboutPage.tsx +++ b/web/src/pages/about/AboutPage.tsx @@ -13,32 +13,32 @@ export function AboutPage() { ]; return ( -
-

{t("about.title")}

+
+

{t("about.title")}

-
-
- +
+
+
{t("about.version")} - - +
+
{__APP_VERSION__} - -
+ +
-

+

{t("about.description")}

-
-

{t("about.builtWith")}

+
+

{t("about.builtWith")}

    {stack.map((item) => (
  • {item} @@ -47,26 +47,28 @@ export function AboutPage() {
-
-
- +
+
+
{t("about.sourceCode")} - - - GitHub - -
-
- + +
+ + GitHub + +
+ +
+
{t("about.license")} - - MIT -
+ +
MIT
+
); diff --git a/web/src/pages/admin/AdminAppPage.tsx b/web/src/pages/admin/AdminAppPage.tsx index c3b3e73..7af6206 100644 --- a/web/src/pages/admin/AdminAppPage.tsx +++ b/web/src/pages/admin/AdminAppPage.tsx @@ -5,12 +5,12 @@ import { api } from "@/lib/api"; import type { SystemSettings } from "@/types"; const INPUT = - "w-full rounded-lg border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-shadow"; + "w-full rounded-lg border bg-background px-3 py-2 text-body-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-shadow"; function Field({ label, children }: { label: string; children: ReactNode }) { return (
- + {children}
); @@ -52,8 +52,11 @@ export function AdminAppPage() { if (loading) { return ( -
-
+
+
+
+
+
); } @@ -61,7 +64,7 @@ export function AdminAppPage() { return (
{error && ( -
+
{error}
@@ -89,7 +92,9 @@ export function AdminAppPage() { > {saving ? t("common.loading") : t("common.save")} - {saveMsg && {saveMsg}} + {saveMsg && ( + {saveMsg} + )}
diff --git a/web/src/pages/admin/AdminEmailPage.tsx b/web/src/pages/admin/AdminEmailPage.tsx index 866fdbc..f0d6990 100644 --- a/web/src/pages/admin/AdminEmailPage.tsx +++ b/web/src/pages/admin/AdminEmailPage.tsx @@ -23,12 +23,12 @@ interface ResendConfig { } const INPUT = - "w-full rounded-lg border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-shadow"; + "w-full rounded-lg border bg-background px-3 py-2 text-body-sm focus:outline-none focus:ring-2 focus:ring-primary/50 transition-shadow"; function Field({ label, children }: { label: string; children: ReactNode }) { return (
- + {children}
); @@ -162,7 +162,7 @@ export function AdminEmailPage() { if (loading) { return ( -
+
@@ -172,7 +172,7 @@ export function AdminEmailPage() { return (
{error && ( -
+
{error}
@@ -296,7 +296,9 @@ export function AdminEmailPage() { > {saving ? t("common.loading") : t("common.save")} - {saveMsg && {saveMsg}} + {saveMsg && ( + {saveMsg} + )}
{emailProvider !== "none" && ( @@ -320,7 +322,9 @@ export function AdminEmailPage() { {testEmailLoading ? t("common.loading") : t("admin.testEmail")} {testEmailMsg && ( - {testEmailMsg} + + {testEmailMsg} + )} {testEmailError && ( diff --git a/web/src/pages/admin/AdminPage.tsx b/web/src/pages/admin/AdminPage.tsx index 8371036..2add308 100644 --- a/web/src/pages/admin/AdminPage.tsx +++ b/web/src/pages/admin/AdminPage.tsx @@ -35,9 +35,7 @@ export function AdminPage() { if (isIndex && isMobile) { return (
-

- {t("admin.title")} -

+

{t("admin.title")}

{tabs.map(({ to, label, icon: Icon }) => ( - {saveMsg && {saveMsg}} + {saveMsg && ( + {saveMsg} + )}
@@ -201,7 +205,7 @@ export function AdminSecurityPage() {

{upgradeResult && ( -

{upgradeResult}

+

{upgradeResult}

)} {upgradeError && (

{upgradeError}

diff --git a/web/src/pages/admin/AdminUsersPage.tsx b/web/src/pages/admin/AdminUsersPage.tsx index 7743eee..a62153f 100644 --- a/web/src/pages/admin/AdminUsersPage.tsx +++ b/web/src/pages/admin/AdminUsersPage.tsx @@ -16,6 +16,7 @@ import { import { ConfirmDialog } from "@/components/ConfirmDialog"; import { api } from "@/lib/api"; import { cn } from "@/lib/utils"; +import { useFocusTrap } from "@/hooks/useFocusTrap"; import { useAuth } from "@/hooks/useAuth"; interface AdminUser { @@ -28,13 +29,12 @@ interface AdminUser { } const ROLE_STYLE: Record = { - admin: - "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400", - user: "bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400", + admin: "bg-info/10 text-info", + user: "bg-muted text-muted-foreground", }; const INPUT = - "w-full px-3 py-2 rounded-md border border-input bg-background text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-ring"; + "w-full px-3 py-2 rounded-md border border-input bg-background text-foreground text-body-sm focus:outline-none focus:ring-2 focus:ring-ring"; const SELECT = cn(INPUT, "cursor-pointer"); export function AdminUsersPage() { @@ -57,6 +57,9 @@ export function AdminUsersPage() { const [editEmail, setEditEmail] = useState(""); const [editPassword, setEditPassword] = useState(""); const [editing, setEditing] = useState(false); + const editTrapRef = useFocusTrap(!!editUser, () => + setEditUser(null), + ); const [pendingAction, setPendingAction] = useState<{ message: string; danger?: boolean; @@ -208,13 +211,15 @@ export function AdminUsersPage() {
-

+

{t("admin.userCount")}

{loading ? ( -
+
) : ( -

{users.length}

+

+ {users.length} +

)}
@@ -232,7 +237,7 @@ export function AdminUsersPage() {
{error && ( -
+
{error}
@@ -245,7 +250,9 @@ export function AdminUsersPage() {
- +
-
- +
-
+ ); } diff --git a/web/src/pages/auth/LoginPage.tsx b/web/src/pages/auth/LoginPage.tsx index b6d099f..a4ab214 100644 --- a/web/src/pages/auth/LoginPage.tsx +++ b/web/src/pages/auth/LoginPage.tsx @@ -5,6 +5,7 @@ import { Globe, Sun, Moon, Monitor } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { useTheme } from "@/components/ThemeProvider"; import { api } from "@/lib/api"; +import { AuthShell, FormError } from "@/components/AuthShell"; export function LoginPage() { const { t, i18n } = useTranslation(); @@ -68,9 +69,9 @@ export function LoginPage() { const ThemeIcon = theme === "light" ? Sun : theme === "dark" ? Moon : Monitor; return ( -
+ {/* Top-right controls */} -
+
-
-
-
-

- {t("app.name")} -

-

- {t("app.tagline")} -

-
- +
+
-
-
- {error && ( -

- {error} -

- )} + {error && {error}} {registrationEnabled && ( -

+

{t("auth.noAccount")}{" "}

-
+ ); } diff --git a/web/src/pages/auth/RegisterPage.tsx b/web/src/pages/auth/RegisterPage.tsx index df81b48..20ca5f8 100644 --- a/web/src/pages/auth/RegisterPage.tsx +++ b/web/src/pages/auth/RegisterPage.tsx @@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next"; import { Globe, Sun, Moon, Monitor } from "lucide-react"; import { useAuth } from "@/hooks/useAuth"; import { useTheme } from "@/components/ThemeProvider"; +import { AuthShell, FormError } from "@/components/AuthShell"; export function RegisterPage() { const { t, i18n } = useTranslation(); @@ -56,9 +57,9 @@ export function RegisterPage() { const ThemeIcon = theme === "light" ? Sun : theme === "dark" ? Moon : Monitor; return ( -
+ {/* Top-right controls */} -
+
-
-
-
-

- {t("app.name")} -

-

- {t("app.tagline")} -

-
- +
+
{message ? (
-
+
{message}
{t("auth.login")} @@ -103,7 +95,7 @@ export function RegisterPage() { ) : (
-
-
-
- {error && ( -

- {error} -

- )} + {error && {error}}
)} {!message && ( -

+

{t("auth.hasAccount")}{" "}

-
+ ); } diff --git a/web/src/pages/auth/TwoFactorPage.tsx b/web/src/pages/auth/TwoFactorPage.tsx index 50f66be..8903be2 100644 --- a/web/src/pages/auth/TwoFactorPage.tsx +++ b/web/src/pages/auth/TwoFactorPage.tsx @@ -9,6 +9,7 @@ import { serializeAuthenticationCredential, prepareAuthenticationOptions, } from "@/lib/utils"; +import { AuthShell, FormError } from "@/components/AuthShell"; type Method = "totp" | "email_otp" | "passkey"; @@ -125,16 +126,9 @@ export function TwoFactorPage() { }; return ( -
-
-
-

- {t("auth.twoFactor")} -

-

- {t("auth.enterCode")} -

- + +
+
{/* Method selector */} {availableMethods.length > 1 && (
@@ -161,9 +155,9 @@ export function TwoFactorPage() { )} {error && ( -

- {error} -

+
+ {error} +
)} {activeMethod === "passkey" ? ( @@ -174,7 +168,7 @@ export function TwoFactorPage() { className="w-full py-2 px-4 bg-primary hover:bg-primary/90 disabled:opacity-50 text-primary-foreground text-sm font-medium rounded-md transition-colors flex items-center justify-center gap-2" > - {loading ? t("common.loading") : t("auth.passkey")} + {loading ? t("auth.loading") : t("auth.passkey")} ) : (
@@ -185,11 +179,11 @@ export function TwoFactorPage() { disabled={loading} className="w-full py-2 px-4 bg-secondary hover:bg-secondary/80 disabled:opacity-50 text-secondary-foreground text-sm font-medium rounded-md transition-colors" > - {loading ? t("common.loading") : t("auth.sendCode")} + {loading ? t("auth.loading") : t("auth.sendCode")} )} {activeMethod === "email_otp" && codeSent && ( -

+

{t("auth.verifyEmailSent")}

)} @@ -218,7 +212,7 @@ export function TwoFactorPage() { disabled={loading || code.length < 6} className="w-full py-2 px-4 bg-primary hover:bg-primary/90 disabled:opacity-50 text-primary-foreground text-sm font-medium rounded-md transition-colors" > - {loading ? t("common.loading") : t("common.confirm")} + {loading ? t("auth.loading") : t("common.confirm")} )} @@ -228,13 +222,13 @@ export function TwoFactorPage() {
← {t("common.back")}
-
+
); } diff --git a/web/src/pages/auth/VerifyEmailPage.tsx b/web/src/pages/auth/VerifyEmailPage.tsx index 7cc0ddd..d47cfca 100644 --- a/web/src/pages/auth/VerifyEmailPage.tsx +++ b/web/src/pages/auth/VerifyEmailPage.tsx @@ -3,6 +3,7 @@ import { Link, useSearchParams } from "react-router"; import { useTranslation } from "react-i18next"; import { CheckCircle, XCircle, Loader2 } from "lucide-react"; import { api } from "@/lib/api"; +import { AuthShell } from "@/components/AuthShell"; export function VerifyEmailPage() { const { t } = useTranslation(); @@ -38,27 +39,23 @@ export function VerifyEmailPage() { }, [token, t]); return ( -
-
-
-

- {t("auth.verifyEmail")} -

- + +
+
{status === "loading" && (
-

{t("common.loading")}

+

{t("auth.loading")}

)} {status === "success" && (
- -

{message}

+ +

{message}

{t("auth.login")} @@ -68,10 +65,10 @@ export function VerifyEmailPage() { {status === "error" && (
-

{message}

+

{message}

{t("auth.login")} @@ -79,6 +76,6 @@ export function VerifyEmailPage() { )}
-
+ ); } diff --git a/web/src/pages/channels/ChannelPage.tsx b/web/src/pages/channels/ChannelPage.tsx index e6d8d68..9424b4f 100644 --- a/web/src/pages/channels/ChannelPage.tsx +++ b/web/src/pages/channels/ChannelPage.tsx @@ -357,7 +357,7 @@ function ChannelCard({ }; return ( -
+
{/* Toggle switch */} @@ -366,7 +366,7 @@ function ChannelCard({ onClick={toggleEnabled} className={cn( "relative shrink-0 w-10 h-6 cursor-pointer rounded-full transition-colors", - isEnabled ? "bg-primary" : "bg-gray-300 dark:bg-gray-600", + isEnabled ? "bg-primary" : "bg-input", )} role="switch" aria-checked={isEnabled} @@ -378,8 +378,16 @@ function ChannelCard({ )} /> - - {channel.label} + {channel.label} + + {isEnabled ? t("common.enabled") : t("common.disabled")}
+ + + ))} + + ))} + + +
+ + {/* Mobile card list */} +
+ {groupedByDay.map(([day, rows]) => ( +
+

+ {day} +

+ {rows.map((g) => ( + - - - ))} - - -
- - {/* Mobile card list */} -
- {grouped.map((g) => ( - +
+
+ {g.channels.some((c) => c.error) && ( +

+ {g.channels + .filter((c) => c.error) + .map((c) => `${c.channel}: ${c.error}`) + .join("; ")}

)} -
- {g.allSuccess ? ( - - - {t("history.success")} - - ) : ( - - - {t("history.failed")} - - )} -
-
-
- {g.channels.map((c) => ( - - {c.channel} - - ))} -
-
- - {new Date(g.created_at).toLocaleString()} - - -
-
- {g.channels.some((c) => c.error) && ( -

- {g.channels - .filter((c) => c.error) - .map((c) => `${c.channel}: ${c.error}`) - .join("; ")} -

- )} - + + ))} +
))}
@@ -301,9 +356,15 @@ export function HistoryPage() { className="absolute inset-0 bg-black/40" onClick={() => setSelected(null)} /> -
+
-

{t("history.detail")}

+

{t("history.detail")}

-

{item.name}

+

{item.name}

- {error && ( -
- - {error} -
- )} - - {/* Edit form */} -
-

{t("common.edit")}

- - {/* Kind (read-only) */} -
- - {t("items.kind")}: - - - {item.item_kind === "subscription" - ? t("items.kindSubscription") - : t("items.kindRegular")} - -
- -
- - setField("name", e.target.value)} - required - /> - + {error && } - - - - - - setField("category", v)} - options={tags} - /> - - - +
+
+ {/* Edit form */} +
+

{t("common.edit")}

+ + {/* Kind (read-only) */}
- - setField("start_date", e.target.value || null) - } - /> - {item.calendar_mode !== "solar" && item.start_date && ( - - {formatLunarDate(item.start_date)} - - )} + + {t("items.kind")}: + + + {item.item_kind === "subscription" + ? t("items.kindSubscription") + : t("items.kindRegular")} +
- - - -
- - setField("period_value", Number(e.target.value)) - } - /> - setField("name", e.target.value)} + required + /> + + + - {item.calendar_mode === "solar" && ( - - )} - {item.calendar_mode === "solar" && ( - - )} - - - -
-
+ + + + + setField("category", v)} + options={tags} + /> + -
- - {item.calendar_mode === "both" ? ( -
-
- - {t("items.calendarSolar")} - - - setField("expiry_date", e.target.value) - } - required - /> - - {formatLunarDate(item.expiry_date)} - -
-
- - {t("items.calendarLunar")} - - - setField("lunar_expiry_date", e.target.value || null) - } - /> - {item.lunar_expiry_date && ( - - {formatLunarDate(item.lunar_expiry_date)} - - )} -
-
- ) : ( +
setField("expiry_date", e.target.value)} - required + value={item.start_date ?? ""} + onChange={(e) => + setField("start_date", e.target.value || null) + } /> - {item.calendar_mode !== "solar" && item.expiry_date && ( + {item.calendar_mode !== "solar" && item.start_date && ( - {formatLunarDate(item.expiry_date)} + {formatLunarDate(item.start_date)} )}
- )} -
-
+ - -
- - setField("reminder_value", Number(e.target.value)) - } - /> - + setField("period_value", Number(e.target.value)) + } + /> + +
+
+ +
- - - -
- -
+ + {item.calendar_mode === "both" ? ( +
+
+ + {t("items.calendarSolar")} + + + setField("expiry_date", e.target.value) + } + required + /> + + {formatLunarDate(item.expiry_date)} + +
+
+ + {t("items.calendarLunar")} + + + setField( + "lunar_expiry_date", + e.target.value || null, + ) + } + /> + {item.lunar_expiry_date && ( + + {formatLunarDate(item.lunar_expiry_date)} + + )} +
+
+ ) : ( +
+ + setField("expiry_date", e.target.value) + } + required + /> + {item.calendar_mode !== "solar" && item.expiry_date && ( + + {formatLunarDate(item.expiry_date)} + + )} +
+ )} +
+
- {item.item_kind === "subscription" && ( -
- - - setField( - "amount", - e.target.value ? Number(e.target.value) : null, - ) - } - /> - + +
+ + setField("reminder_value", Number(e.target.value)) + } + /> + +
+
+
- - - -
- )} + {item.item_kind === "subscription" && ( +
+

+ {t("detail.sectionCycle")} +

+ + + setField( + "amount", + e.target.value ? Number(e.target.value) : null, + ) + } + /> + + + + + +
+ )} -
- setField("is_active", v ? 1 : 0)} - label={t("items.enableItem")} - /> - setField("auto_renew", v ? 1 : 0)} - label={t("items.autoRenew")} - /> -
+
+ setField("is_active", v ? 1 : 0)} + label={t("items.enableItem")} + /> + setField("auto_renew", v ? 1 : 0)} + label={t("items.autoRenew")} + /> +
- {/* Calendar mode selector + action buttons */} -
- -
- {(["solar", "lunar", "both"] as const).map((mode) => ( + {/* Calendar mode selector + action buttons */} +
+ +
+ {(["solar", "lunar", "both"] as const).map((mode) => ( + + ))} +
+
+
- ))} -
- -
- - - {notifyMsg && ( - + + {t("items.recalcExpiry")} + + {notifyMsg && ( + + {notifyMsg} + )} +
+
+ +
+

+ {t("detail.sectionReminder")} +

+ +