npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rc-kpc-skeleton-card

v1.0.6

Published

react skeleton for ksyun design card component

Downloads

13

Readme

rc-kpc-skeleton-card

为 KPC Card 增加骨架屏配置选项

skeleton showcase

安装

npm

npm install rc-kpc-skeleton-card

Yarn

yarn add rc-kpc-skeleton-card

使用

import SkeletonCard from 'rc-kpc-skeleton-card';

<SkeletonCard loading={loading}>
  <span>Hello World</span>
</SkeletonCard>;

可以直接使用SkeletonCard替换已有的Card组件,已有参数不变

特点

基于 KPC-Card 的组件库拥有以下特点,来让研发更快速高效的为页面增加骨架屏效果。

1. 将判断逻辑从业务代码中解耦

常见的带有加载动画的代码如下:

<Card title="数据列表">
  <Row gutter="16">
    {!loading ? (
      <ul>
        {dataList.map((item) => (
          <li>item</li>
        ))}
      </ul>
    ) : (
      <Loading />
    )}
  </Row>
</Card>

这样,会让我们的代码结构比较混乱,您可能会尝试,将 list 再单独提取为一个组件,但是仍然会有多余的结构。而使用SkeletonCard则可以让代码更加聚焦业务本身。

<SkeletonCard title="数据列表" loading={loading} loadingElement={<Loading />}>
  <Row gutter="16">
    <ul>
      {dataList.map((item) => (
        <li>item</li>
      ))}
    </ul>
  </Row>
</SkeletonCard>

甚至,借助SkeletonCard的预设,可以省去开发<Loading />组件的过程。

<SkeletonCard title="数据列表" loading={loading}>
  <Row gutter="16">
    <ul>
      {dataList.map((item) => (
        <li>item</li>
      ))}
    </ul>
  </Row>
</SkeletonCard>

2. 方便的预设 Skeleton 样式

针对不同的 Card,我们可能不只满足于简单的矩形排列,因此SkeletonCard提供了以下几种预设:

  • charts 图
  • profile 用户信息
  • code 代码块
  • table 表格
  • list 列表
<SkeletonCard
  title="资讯信息"
  loading={loading}
  loadingPreset="list"
></SkeletonCard>

同时,可以使用以上预设,来组合生成其他Skeleton效果,以下为一个带有多个按钮的组合 Skeleton 代码。

import {
  ProfileSkeleton,
  SquareSkeleton,
  defaultSkeletonStyleConfig,
} from 'rc-kpc-skeleton-card';

const Loading: React.FC<LoadingProps> = () => {
  return (
    <div>
      <ProfileSkeleton {...defaultSkeletonStyleConfig} />
      <Row gutter={16}>
        {Array(4)
          .fill(0)
          .map((_, index) => (
            <Col key={index} md={6} xs={12}>
              <SquareSkeleton />
            </Col>
          ))}
      </Row>
    </div>
  );
};

API

KPC-Card 可用 API 配置请参阅 Card 介绍文档

新增 API 内容

| 参数 | 说明 | 类型 | 默认值 | 是否必填 | | :------------- | :-------------------------------------------- | :-------------------------------------------------------------------- | :-------------- | :------- | | loading | 是否展示骨架屏 | boolean | false | 否 | | loadingSize | 默认骨架屏的尺寸,对预设无效 | 'large' | 'default' | 'small' | 'mini' | 200 | 否 | | loadingColumn | 骨架屏行列数,用来控制展示多少列、行元素 | { row: number;col: number;} | {row: 3,col: 2} | 否 | | loadingElement | 自定义加载效果,用以覆盖 loading 时展示的内容 | ReactNode | {row: 3,col: 2} | 否 | | loadingPreset | 使用预设配置骨架屏 | 'charts' | 'profile' | 'code' | 'table' | 'list' | 'bullet-list' | 无 | 否 |