收口运行态状态提示组件
新增 PlatformRuntimeStatusToast 统一运行态短错误、成功和反馈 toast 迁移跳一跳、拼图、敲木鱼、方洞和宝贝爱画运行态状态 chip 补充公共组件与运行态回归测试,并更新 PlatformUiKit 文档和 Hermes 决策记录
This commit is contained in:
104
src/components/common/PlatformRuntimeStatusToast.tsx
Normal file
104
src/components/common/PlatformRuntimeStatusToast.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import type { HTMLAttributes, ReactNode } from 'react';
|
||||
|
||||
type PlatformRuntimeStatusTone =
|
||||
| 'error'
|
||||
| 'success'
|
||||
| 'info'
|
||||
| 'warning'
|
||||
| 'neutral';
|
||||
type PlatformRuntimeStatusSurface = 'light' | 'dark' | 'solid';
|
||||
type PlatformRuntimeStatusSize = 'xs' | 'sm' | 'md';
|
||||
type PlatformRuntimeStatusShape = 'pill' | 'rounded';
|
||||
|
||||
type PlatformRuntimeStatusToastProps = Omit<
|
||||
HTMLAttributes<HTMLDivElement>,
|
||||
'children'
|
||||
> & {
|
||||
tone: PlatformRuntimeStatusTone;
|
||||
surface?: PlatformRuntimeStatusSurface;
|
||||
size?: PlatformRuntimeStatusSize;
|
||||
shape?: PlatformRuntimeStatusShape;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
const PLATFORM_RUNTIME_STATUS_SURFACE_CLASS: Record<
|
||||
PlatformRuntimeStatusSurface,
|
||||
Record<PlatformRuntimeStatusTone, string>
|
||||
> = {
|
||||
light: {
|
||||
error:
|
||||
'border-white/70 bg-white/86 text-[var(--platform-button-danger-text)]',
|
||||
success:
|
||||
'border-white/70 bg-white/86 text-[var(--platform-success-text)]',
|
||||
info: 'border-white/70 bg-white/86 text-[var(--platform-cool-text)]',
|
||||
warning: 'border-white/70 bg-white/86 text-[var(--platform-warm-text)]',
|
||||
neutral: 'border-white/70 bg-white/86 text-[var(--platform-text-base)]',
|
||||
},
|
||||
dark: {
|
||||
error: 'border-rose-200/35 bg-rose-400/18 text-rose-50',
|
||||
success: 'border-emerald-200/35 bg-emerald-400/18 text-emerald-50',
|
||||
info: 'border-sky-200/30 bg-sky-400/16 text-sky-50',
|
||||
warning: 'border-amber-200/35 bg-amber-400/18 text-amber-50',
|
||||
neutral: 'border-white/15 bg-white/12 text-white/82',
|
||||
},
|
||||
solid: {
|
||||
error: 'border-transparent bg-rose-600 text-white',
|
||||
success: 'border-transparent bg-emerald-600 text-white',
|
||||
info: 'border-transparent bg-sky-600 text-white',
|
||||
warning: 'border-transparent bg-amber-500 text-amber-950',
|
||||
neutral: 'border-transparent bg-slate-800 text-white',
|
||||
},
|
||||
};
|
||||
|
||||
const PLATFORM_RUNTIME_STATUS_SIZE_CLASS: Record<
|
||||
PlatformRuntimeStatusSize,
|
||||
string
|
||||
> = {
|
||||
xs: 'px-3 py-1 text-xs leading-5',
|
||||
sm: 'px-3 py-2 text-sm leading-5',
|
||||
md: 'px-4 py-3 text-sm leading-6',
|
||||
};
|
||||
|
||||
const PLATFORM_RUNTIME_STATUS_SHAPE_CLASS: Record<
|
||||
PlatformRuntimeStatusShape,
|
||||
string
|
||||
> = {
|
||||
pill: 'rounded-full',
|
||||
rounded: 'rounded-[1.2rem]',
|
||||
};
|
||||
|
||||
/**
|
||||
* 运行态 HUD 状态提示。
|
||||
* 收口游戏内短错误、成功和反馈 chip,位置与玩法强品牌视觉仍由调用方控制。
|
||||
*/
|
||||
export function PlatformRuntimeStatusToast({
|
||||
tone,
|
||||
surface = 'light',
|
||||
size = 'sm',
|
||||
shape = 'pill',
|
||||
children,
|
||||
className,
|
||||
role,
|
||||
...divProps
|
||||
}: PlatformRuntimeStatusToastProps) {
|
||||
const ariaLive = divProps['aria-live'];
|
||||
|
||||
return (
|
||||
<div
|
||||
{...divProps}
|
||||
role={role ?? (tone === 'error' ? 'alert' : 'status')}
|
||||
aria-live={ariaLive ?? (tone === 'error' ? 'assertive' : 'polite')}
|
||||
className={[
|
||||
'platform-runtime-status-toast inline-flex max-w-full items-center justify-center gap-1.5 border text-center font-black shadow-sm backdrop-blur',
|
||||
PLATFORM_RUNTIME_STATUS_SIZE_CLASS[size],
|
||||
PLATFORM_RUNTIME_STATUS_SHAPE_CLASS[shape],
|
||||
PLATFORM_RUNTIME_STATUS_SURFACE_CLASS[surface][tone],
|
||||
className,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user