Card卡片
组合标题、图标、内容与底部操作,支持整卡点击和选中状态。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add card安装
在项目根目录运行,安装源码。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add card使用
React
"use client";
import { MoreHorizontal } from "lucide-react";import { KalosCard } from "@/components/ui/kalos-card";import { KalosButton } from "@/components/ui/kalos-button";
function ActivityIcon() { return <span aria-hidden="true" className="grid size-10 place-items-center rounded-lg bg-muted"> <style>{`@keyframes card-activity-pixel { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }`}</style> <span className="grid size-4 grid-cols-[repeat(3,3px)] auto-rows-[3px] place-content-center gap-[1.5px]"> {Array.from({ length: 9 }, (_, index) => <i key={index} className="rounded-[0.75px] bg-[var(--k-card-activity)]" style={{ opacity: index === 1 || index === 7 ? 0 : 1, animation: index === 1 || index === 7 ? undefined : "card-activity-pixel 1.2s ease-in-out infinite both", animationDelay: (Math.floor(index / 3) + index % 3) * 120 + "ms", }} />)} </span> </span>;}
export default function Example() { return <div className="w-full max-w-[400px]"> <KalosCard as="section" aria-label="文档资料" title="文档资料" description="最近 30 天" icon={<ActivityIcon />} action={<KalosButton variant="ghost" size="icon" aria-label="查看文档信息" onClick={() => window.alert("142 份文档,已使用 4.2 GB 存储空间")}><MoreHorizontal /></KalosButton>} footer={<> <span>2 分钟前同步</span> <span className="ms-auto"><KalosButton onClick={() => window.alert("已打开文档资料")}>打开</KalosButton></span> </>} > <dl className="grid grid-cols-3 gap-3"> <div><dt className="text-xs text-muted-foreground">文档</dt><dd className="text-base tabular-nums">142</dd></div> <div><dt className="text-xs text-muted-foreground">已同步</dt><dd className="text-base tabular-nums">96%</dd></div> <div><dt className="text-xs text-muted-foreground">存储</dt><dd className="text-base tabular-nums">4.2 GB</dd></div> </dl> </KalosCard> </div>;}API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
title | ReactNode | — | 卡片标题;interactive 时在标题中放置链接或按钮,点击区域会覆盖整张卡片 |
description | ReactNode | — | 标题下方的可选说明;省略时不占位 |
icon | ReactNode | — | 标题前的图标或图标容器 |
action | ReactNode | — | 与标题首行居中对齐的独立操作 |
children | ReactNode | — | 卡片内容;省略时不保留内容区间距 |
footer | ReactNode | — | 底部状态与操作;使用 margin-inline-start: auto 将操作推至右侧,窄屏自动换行 |
interactive | boolean | false | 启用悬停阴影与标题点击区域;其他控件仍可独立操作,禁用标题按钮保留原生禁用行为 |
selected | boolean | false | 以灰色填充和加深边缘表示选中;同时在标题按钮或链接上提供 aria-pressed 或 aria-current |
as | "div" | "section" | "article" | "li" | div | 根元素;在列表中使用 li |
titleAs | "h2" | "h3" | "h4" | "p" | h3 | 根据页面层级选择标题元素;选项卡片可使用 p |
...props | ComponentProps<"div"> | — | 原生属性、事件、ARIA 属性及 className 传递给根元素 |
键盘操作
- Tab / Shift + Tab
- 依次聚焦标题中的链接或按钮,以及其他独立操作;交互标题的焦点轮廓覆盖整卡
- Enter
- 激活聚焦的标题链接或按钮
- Space
- 激活聚焦的标题按钮