@agney/react-loading

中文文档
0.1.2发布于 2020/10/05MITTypeScriptESM + CJS近 30 天下载 6977

反应加载

使用 React 的简单且可访问的加载指标 .

中文使用文档
文档目录9 节
  1. 反应加载
  2. 安装
  3. 特征
  4. 使用量
  5. 装入器
  6. A. 背景情况
  7. 装入器上的额外道具
  8. 带上你自己的装载机
  9. 发展

反应加载

使用 React 的简单且可访问的加载指标 .


code style: prettier

与反应组件捆绑在一起 Sam Herbert的动画 SVG 加载器 在可动摇的树上.

Example of loading indicator SVGs

安装

npm i @agney/react-loading
# OR
yarn add @agney/react-loading

演示

特征

  • 小号

    整个图书馆都是关于 20kB 已微调。 。 。 . 但你不会需要整个包.

    库是用来摇摆树木的 当你使用一两个被捆绑的加载器时, 你就会有不到1克B的被捆绑.

  • 无障碍

    提供您装入组件和容器的无障碍属性.

    aria-busy 设置为 true 载货量和进度指标 role=progressbar。 。 。 .

  • 指定全局加载器

    您可能不希望加载器组件在任何地方混合,所以您可以指定一个 LoaderContext 如果有必要,以后可以推翻.

  • 带上你自己的装载机

    如果你决定带上自己的加载指示器,库也会支持这一点,保持所有逻辑不变.

  • 类型脚本支持. 零额外CSS.

使用量

import { useLoading, Audio } from '@agney/react-loading';

function Content() {
  const { containerProps, indicatorEl } = useLoading({
    loading: true,
    indicator: <Audio width="50" />,
  });

  return (
    {/* Accessibility props injected to container */}
    <section {...containerProps}>
      {indicatorEl} {/* renders only while loading */}
    </section>
  );
}

装入器

这个库与 React 组件捆绑在一起 Sam Herbert的动画 SVG 加载器 在可动摇的树上.

每个装载机都是SVG,所通过道具应被应用到顶部SVG元件上. 所有 SVG 将被设定为继承 currentColor 从它的父母的填充/中空.

可用的装载器有:

import {
  Audio,
  BallTriangle,
  Bars,
  Circles,
  Grid,
  Hearts,
  Oval,
  Puff,
  Rings,
  SpinningCircles,
  TailSpin,
  ThreeDots,
} from '@agney/react-loading';

使用Webpack/Rollup等捆绑器时,只包含您使用的那些.

A. 背景情况

您可以指定单个加载指示器, 并使用 LoaderProvider。 。 。 .

import { LoaderProvider, useLoading, BallTriangle } from '@agney/react-loading';

function App() {
  const { containerProps, indicatorEl } = useLoading({
    loading: true,
  });
  return <section {...containerProps}>{indicatorEl}</section>;
}

ReactDOM.render(
  <LoaderProvider indicator={<BallTriangle width="50" />}>
    <App />
  </LoaderProvider>
);

你可以用这么多 LoaderProvider 您喜欢的提供者元素和React会选择最接近您正在渲染的钩子的元素.

更多关于反应背景

装入器上的额外道具

如果您想在装入器上提供特定的道具, 使用钩子时:

useLoading({
  loading: true,
  loaderProps: {
    // Any props here would be spread on to the indicator element.
    style: {{ margin: '0 auto' }}
  }
});

我们还为 valueText,用于描述:

useLoading({
  loading: true,
  loaderProps: {
    valueText: 'Fetching video from the Great Internet',
  },
});

// now this will generate:
/* <svg role="progressbar" aria-valuetext="Fetching video from the Great Internet"></svg>*/

aria-valuetext 将被屏幕阅读者读取.

您也可以提供 aria-valuenow (但预先捆绑的指标最适合不确定的进展指标)

用于参考的 MDN progressbar

带上你自己的装载机

只要将导入切换到您自己的加载指示器( 只要确保它接受道具)

import { LoaderProvider, useLoading } from '@agney/react-loading';

const Loader = ({ ...rest }) => <p {...rest}>Loading...</p>;

function App() {
  const { containerProps, indicatorEl } = useLoading({
    loading: true,
  });
  return <section {...containerProps}>{indicatorEl}</section>;
}

ReactDOM.render(
  <LoaderProvider indicator={<Loader />}>
    <App />
  </LoaderProvider>
);

捐款

所有公关都欢迎.

发展

我们用 tsdx 用来生产锅炉板.

安装 :

# Library
npm i

# Example
cd example && npm i

发展:

# Running library dev
npm start

# Running example
cd example && npm start

测试 :

测试 react-testing-library 财务报告和审定财务报表 jest

npm test

在tsdx寄存器上可以详细获取命令.

版本与发布记录

@agney/react-loading 共发布 2 个版本,首次发布于 2020/10/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.2latest2020/10/056 年前
0.1.12020/10/046 年前

关于 @agney/react-loading 的常见问题

@agney/react-loading 是什么?

反应加载 使用 React 的简单且可访问的加载指标 .

如何安装 @agney/react-loading?

在项目目录运行 npm install @agney/react-loading,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agney/react-loading 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agney/react-loading 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@agney/react-loading 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agney/react-loading 可以商用吗?

@agney/react-loading 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agney/react-loading 的下载量有多少?

根据 npm 官方下载统计,@agney/react-loading 在 2026/10/05 – 2026/11/03 这 30 天内被下载 6,977 次,日均约 233 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agney/react-loading 还在维护吗?

最新版本 0.1.2 发布于 2020/10/05(6 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。