Ordo UI
PatternsLayout & Shells

SectionCard

@mox-hub/patterns 模式 · Layout & Shells · canonical

section-card@mox-hub/patternsLayout & Shellscanonicalsrc/components/section-card.tsx
变体演示section-card
仓库设置

管理默认分支、可见性与同步策略

默认分支main
自动同步已开启

Props API

Prop类型默认值说明
title*ReactNode——
description*ReactNode——
actions*ReactNode——
icon*LucideIcon——
iconColor*string"text-accent-blue"—
titleClassName*string——
children*ReactNode——
className*string——
contentClassName*string——

源码

packages/patterns/src/components/section-card.tsx
import type { ReactNode } from "react";
import type { LucideIcon } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@mox-hub/ui/components/card";
import { cn } from "@mox-hub/ui";

export interface SectionCardProps {
  title?: ReactNode;
  description?: ReactNode;
  actions?: ReactNode;
  /** 卡片标题旁彩色图标(设计标准:带标题卡片配 15/16px accent 图标) */
  icon?: LucideIcon;
  iconColor?: string;
  /** 覆盖 CardTitle 字号(默认 text-lg;设置页统一层级时传 text-base) */
  titleClassName?: string;
  children: ReactNode;
  className?: string;
  contentClassName?: string;
}

/**
 * SectionCard —— 带标题/描述/操作/图标的卡片分区骨架。
 *
 * `title || description || actions` 才渲染 header;内容区不嵌套卡片。
 */
export function SectionCard({
  title,
  description,
  actions,
  icon: Icon,
  iconColor = "text-accent-blue",
  titleClassName,
  children,
  className,
  contentClassName,
}: SectionCardProps) {
  return (
    <Card className={cn("border-border bg-card", className)}>
      {title || description || actions ? (
        <CardHeader className="flex-row items-start justify-between space-y-0 pb-1">
          <div className="flex min-w-0 flex-col gap-1">
            {title ? (
              <CardTitle className={cn("flex items-center gap-2 text-foreground text-base", titleClassName)}>
                {Icon ? <Icon className={cn("size-4 shrink-0", iconColor)} strokeWidth={1.75} /> : null}
                <span className="truncate">{title}</span>
              </CardTitle>
            ) : null}
            {description ? <p className="text-xs text-muted-foreground">{description}</p> : null}
          </div>
          {actions}
        </CardHeader>
      ) : null}
      <CardContent className={cn("pt-0", contentClassName)}>{children}</CardContent>
    </Card>
  );
}

可访问性与 RTL

  • 键盘:交互件保留:focus-visible焦点环;浮层支持 Escape 关闭与焦点归还,菜单 / 页签按 Base UI 约定支持方向键。 筛选菜单、拖拽排序、执行树与模型 listbox 等关键键盘流由 Playwright 断言覆盖,见规范示例 · 交互与可访问性。
  • RTL:间距、对齐与方向性图标使用逻辑属性 (ms-* /text-start /rtl:-scale-x-100);通过 ThemeProvider 或I18nProvider 的direction="rtl"驱动,`lint:rtl` 会拦截新增物理类。
  • 文案:优先用组件labels /translate /translator props,其次用I18nProvider目录;内置 zh-CN 默认值,en-US 为参考翻译。见Theming · i18n 与 RTL。
  • 对比度:高对比度 token、2px 控件边框与 3px 焦点环由主题层统一提供,见Foundations · Contrast。

用法说明

带标题/描述/操作/图标的卡片分区骨架;title/description/actions 任一存在才渲染 header,内容区不嵌套卡片。