PatternsData Display
IconStack
@mox-hub/patterns 模式 · Data Display · canonical
icon-stack@mox-hub/patternsData Displaycanonicalsrc/components/icon-stack.tsx变体演示icon-stack
Props API
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
| className* | string | — | — |
| children* | ReactNode | — | — |
| style* | CSSProperties | — | — |
源码
import { cn } from '@mox-hub/ui';
/**
* 等距层叠图标插画容器(reui base-nova 配方移植,2026-09-14)。
* 装饰性组件:用于空态/引导/完成时刻的深度感图标——children 居中渲染在层叠卡堆上,
* 尺寸经 className 控制(默认 h-20 w-18),语义色经 text-* 传入。
* 纯装饰场景记得 aria-hidden="true",可读文案放在周边内容里。
* 与 reui 原配方差异:椭圆投影模糊 token 化(blur-xs=4px)、内容定位改内联 style(避开任意值类)。
*/
type IconStackProps = React.ComponentProps<'div'>;
function IconStack({ className, children, style, ...props }: IconStackProps) {
return (
<div
data-slot="icon-stack"
className={cn(
'text-foreground **:data-[slot=icon-stack-layer]:fill-background relative h-20 w-18',
className
)}
style={
{
'--icon-stack-content-x': '71%',
'--icon-stack-content-y': '58%',
...style,
} as React.CSSProperties
}
{...props}
>
<svg
aria-hidden="true"
viewBox="0 0 72 81"
fill="none"
className="h-full w-full overflow-visible"
>
<ellipse
cx="36"
cy="76"
rx="30"
ry="7"
fill="currentColor"
fillOpacity="0.055"
className="blur-xs"
/>
<IconStackLayer opacity="0.4" />
<IconStackLayer opacity="0.6" x={13.65} y={6.04} />
<IconStackLayer opacity="0.8" x={27.32} y={12.08} active />
</svg>
{children ? (
<div
data-slot="icon-stack-content"
className="text-muted-foreground pointer-events-none absolute flex -translate-x-1/2 -translate-y-1/2 scale-x-90 -skew-y-26 items-center justify-center"
style={{
top: 'var(--icon-stack-content-y)',
left: 'var(--icon-stack-content-x)',
}}
>
{children}
</div>
) : null}
</div>
);
}
function IconStackLayer({
active = false,
opacity,
x = 0,
y = 0,
}: {
active?: boolean;
opacity: string;
x?: number;
y?: number;
}) {
return (
<g opacity={opacity} transform={`translate(${x} ${y})`}>
<path
data-slot="icon-stack-layer"
d="M42.2538 2.046C41.4408 1.6325 40.3965 1.6677 39.2612 2.2424L7.9616 18.1934C5.3895 19.5039 3.301 23.1064 3.301 26.2322V64.3226C3.301 66.0677 3.9458 67.2943 4.962 67.8199L1.8363 66.229C0.8201 65.7104 0.1753 64.4771 0.1753 62.732V24.6412C0.1753 21.5085 2.2638 17.913 4.8359 16.6024L36.1355 0.6515C37.2778 0.0698 38.322 0.0416 39.128 0.4551L42.2538 2.046Z"
stroke="currentColor"
strokeOpacity={active ? '0.3' : '0.2'}
strokeWidth="0.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
data-slot="icon-stack-layer"
d="M42.2545 2.0456C43.2707 2.5643 43.9155 3.7979 43.9155 5.543V43.6337C43.9155 46.7665 41.827 50.3616 39.2549 51.6722L7.9554 67.6235C6.813 68.2052 5.7687 68.2331 4.9628 67.8196C3.9465 67.301 3.3018 66.0673 3.3018 64.3222V26.2318C3.3018 23.0991 5.3903 19.5036 7.9624 18.193L39.2619 2.2421C40.4043 1.6604 41.4486 1.6321 42.2545 2.0456Z"
stroke="currentColor"
strokeOpacity={active ? '0.3' : '0.2'}
strokeWidth="0.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</g>
);
}
export { IconStack, type IconStackProps };
可访问性与 RTL
- 键盘:交互件保留
:focus-visible焦点环;浮层支持 Escape 关闭与焦点归还,菜单 / 页签按 Base UI 约定支持方向键。 筛选菜单、拖拽排序、执行树与模型 listbox 等关键键盘流由 Playwright 断言覆盖,见规范示例 · 交互与可访问性。 - RTL:间距、对齐与方向性图标使用逻辑属性 (
ms-*/text-start/rtl:-scale-x-100);通过ThemeProvider或I18nProvider的direction="rtl"驱动,`lint:rtl` 会拦截新增物理类。 - 文案:优先用组件
labels/translate/translatorprops,其次用I18nProvider目录;内置 zh-CN 默认值,en-US 为参考翻译。见Theming · i18n 与 RTL。 - 对比度:高对比度 token、2px 控件边框与 3px 焦点环由主题层统一提供,见Foundations · Contrast。
用法说明
等距层叠图标插画容器:装饰性组件,children 居中渲染在层叠卡堆上;尺寸/语义色经 className 注入。