组件目录

Skeleton骨架屏

在内容加载时保留文字、图标与列表的布局,支持同步扫光和延迟淡入。

npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add skeleton
MCP

最近记录

DataLoading

安装

在项目根目录运行,安装源码。

npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add skeleton

使用

React
import { KalosLoading, KalosSkeleton } from "@/components/ui/kalos-skeleton";
type Contact = { id: string; name: string; email: string };
export default function ContactList({ contacts }: { contacts?: Contact[] }) {  if (!contacts) return (    <KalosLoading label="正在加载联系人" className="flex w-full max-w-sm flex-col gap-4">      {[160, 128, 144].map((width, index) => (        <div key={index} className="flex items-center gap-3">          <KalosSkeleton width={32} height={32} radius="50%" />          <div className="min-w-0 flex-1">            <KalosSkeleton line={20} width={width} height={10} />            <KalosSkeleton line={16} width={112} height={8} />          </div>        </div>      ))}    </KalosLoading>  );
  return <ul className="flex w-full max-w-sm flex-col gap-4">    {contacts.map(contact => <li key={contact.id} className="flex items-center gap-3">      <span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-muted" aria-hidden="true">{contact.name.slice(0, 1)}</span>      <div className="min-w-0 flex-1">        <p className="truncate leading-5">{contact.name}</p>        <p className="truncate text-xs leading-4 text-muted-foreground">{contact.email}</p>      </div>    </li>)}  </ul>;}

API

属性类型默认值说明
KalosSkeleton.widthnumber | string100%占位形状宽度;数字按 px,字符串支持 CSS 长度,最大不超过父容器
KalosSkeleton.heightnumber | string12占位形状自身的高度,数字按 px
KalosSkeleton.radiusnumber | string6px圆角;传 50% 可展示圆形头像占位
KalosSkeleton.lineboolean | number | stringfalse将形状居中放入行高盒,保留真实文字的行高;true 使用 1lh,也可传入 20 等高度
KalosSkeleton.className / style / refComponentPropsWithRef<"span">—原生 span 属性;开启 line 时作用于外层行高盒,形状对屏幕阅读器隐藏
KalosLoading.labelstring正在加载加载区域的可访问名称;使用 role=status 和 aria-busy,仅播报一次区域状态
KalosLoading.children / className / style / refComponentPropsWithRef<"div">—使用真实内容的布局包裹占位形状;150ms 后淡入,数据就绪时替换整个加载区域
动画变量CSS custom properties1600ms / 150ms / 300ms通过 --kalos-skeleton-duration、--kalos-skeleton-delay 和 --kalos-skeleton-fade-duration 调整扫光、等待与淡入时长