nex_animation/frontend/src/components/ui/tone.tsx

49 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 反馈色调:吐司 / 确认框 / 提示条共用的**唯一一张**语义表(2026-11 第十三轮)。
*
* 症状:反馈类表面原先各说各话——antd `<message>` 只有「绿勾小胶囊 / 红叉小胶囊」,
* `window.confirm` 连颜色都没有(浏览器原生灰框,字体、按钮、层级全是系统的),
* `Notice` 是 antd Alert 的直封装(四档 type 自带一套图标)。
* 同一个「删除失败」在一屏里可能出现三种长相。
* 做法:把「一个反馈语气该是什么颜色、什么图形」抽成一张表,三个表面都读它:
* 色调变量只取 antd 语义 token(`--ant-color-*`,站内唯一色源),
* 图形只取 `components/icons` 登记的语义名(R11)。
* 底纹与描边不在这里:那套口径由 `Panel.tsx` 的 `BLOCK_TONE` 管(R16.3)。
* 为什么不复用 Status.tsx 的 TONE_VARS:那张表服务的是**行内标签**(一颗 6px 圆点),
* 语气档位多了 accent / mono 却没有 loading;反馈表面要的是「一句结论 + 一枚图形」,
* 尺寸与图形 vocabulary 都不同,硬合成一张表会让两边都不敢改。
*/
import type { ReactNode } from 'react'
import { IconCheck, IconInfo, IconLoading, IconReject, IconWarn } from '../icons'
/** 反馈语气:成功 / 失败 / 需要注意 / 纯信息 / 进行中 */
export type FeedbackTone = 'ok' | 'bad' | 'warn' | 'info' | 'loading'
/** 色调 → antd 语义色变量(写进 CSS 变量 `--nex-mark-tint`,由 app.css 的色块族上色) */
export const TONE_TINT: Record<FeedbackTone, string> = {
ok: 'var(--ant-color-success)',
bad: 'var(--ant-color-error)',
warn: 'var(--ant-color-warning)',
info: 'var(--ant-color-info)',
loading: 'var(--ant-color-primary)'
}
/** 色调 → 色块里的那枚图形 */
export const TONE_ICON: Record<FeedbackTone, ReactNode> = {
ok: <IconCheck />,
bad: <IconReject />,
warn: <IconWarn />,
info: <IconInfo />,
loading: <IconLoading spin />
}
/** 语气名(aria-label / title 共用,不再逐处手写中文) */
export const TONE_LABEL: Record<FeedbackTone, string> = {
ok: '成功', bad: '失败', warn: '注意', info: '提示', loading: '进行中'
}
/** 提示条的 antd Alert 词汇 → 站内语气(30 处 `<Notice type=…>` 的写法保持不变) */
export const NOTICE_TONE: Record<'info' | 'success' | 'warning' | 'error', FeedbackTone> = {
info: 'info', success: 'ok', warning: 'warn', error: 'bad'
}