@boxicons/react

中文文档
1.0.3发布于 2026/02/16MITTypeScriptESM + CJS零依赖近 30 天下载 4.1万

Boxicons 的反应组件

中文使用文档
文档目录18 节
  1. 安装
  2. 使用量
  3. 基本用途
  4. 图标包
  5. 大小
  6. 颜色
  7. 不透明度
  8. 翻转
  9. 旋转
  10. 删除铺设
  11. 组合道具
  12. 标准 SVG 道具
  13. 转发
  14. 树摇
  15. 可用图标
  16. 命名公约
  17. 类型脚本
  18. BoxIcon 选项

@ boxicons/ 反应

由 Boxicons SVG 文件所建的具有全树摇晃支持的回放图标库.

安装

npm install @boxicons/react
# or
yarn add @boxicons/react
# or
pnpm add @boxicons/react

使用量

基本用途

import { Alarm, Twitter, Home } from '@boxicons/react';

function App() {
  return (
    <div>
      <Alarm />
      <Twitter />
      <Home />
    </div>
  );
}

图标包

每个图标可以有多个变体. 使用 pack 在它们之间切换的道具 :

  • 基础 - 大纲/正则样式图标(大多数图标默认)
  • 已填满 - 固态/填充式图标
  • 品牌 - 品牌/logo图标(对Twitter,Facebook等品牌图标的默认)
import { Alarm } from '@boxicons/react';

function App() {
  return (
    <div>
      {/* Basic/outline style (default) */}
      <Alarm />
      
      {/* Filled style */}
      <Alarm pack="filled" />
    </div>
  );
}

大小

大小预设

使用 size 方便预设大小的道具 :

<Alarm size="xs" />   {/* 16px */}
<Alarm size="sm" />   {/* 20px */}
<Alarm size="base" /> {/* 24px (default) */}
<Alarm size="md" />   {/* 36px */}
<Alarm size="lg" />   {/* 48px */}
<Alarm size="xl" />   {/* 64px */}
<Alarm size="2xl" />  {/* 96px */}
<Alarm size="3xl" />  {/* 128px */}
<Alarm size="4xl" />  {/* 256px */}
<Alarm size="5xl" />  {/* 512px */}

自定义大小

对于自定义大小, 使用 width 财务报告和审定财务报表 height 道具( 覆盖) size:

<Alarm width={32} height={32} />
<Alarm width="48" height="48" />
<Alarm width="2rem" height="2rem" />

颜色

使用 fill 更改图标颜色的道具(默认为 currentColor:

<Alarm fill="#ff0000" />
<Alarm fill="rgb(0, 128, 255)" />
<Alarm fill="currentColor" /> {/* Inherits text color */}

不透明度

控制透明度 opacity 道具 :

<Alarm opacity={0.5} />
<Alarm opacity="0.75" />

翻转

横向或纵向镜像图标 :

<Alarm flip="horizontal" /> {/* Mirrors left-to-right */}
<Alarm flip="vertical" />   {/* Mirrors top-to-bottom */}

旋转

任意旋转图标 :

<Alarm rotate={45} />      {/* Rotates 45 degrees */}
<Alarm rotate="90" />      {/* Rotates 90 degrees */}
<Alarm rotate="180deg" />  {/* Also accepts "deg" suffix */}

删除铺设

删除默认的 2px 粘贴在图标周围以进行更紧的匹配 :

<Alarm removePadding />    {/* Crops padding, viewBox becomes "2 2 20 20" */}

组合道具

所有道具都可以合并:

<Alarm 
  pack="filled"
  fill="#ffffff"
  opacity={0.8}
  size="lg"
  flip="horizontal"
  rotate={45}
  className="my-icon"
  style={{ margin: '8px' }}
/>

标准 SVG 道具

所有标准的SVG道具都得到支持并传递到下面 <svg> 元素 :

<Alarm 
  className="icon"
  id="my-alarm-icon"
  aria-label="Alarm"
  role="img"
  onClick={() => console.log('clicked')}
/>

转发

参考文献转发到SVG元素:

import { useRef } from 'react';
import { Alarm } from '@boxicons/react';

function App() {
  const iconRef = useRef<SVGSVGElement>(null);
  
  return <Alarm ref={iconRef} />;
}

树摇

这个图书馆是完全可以树动的。 只有您导入的图标将包含在您的最后捆绑中 .

// ✅ Only Alarm is bundled
import { Alarm } from '@boxicons/react';

// ✅ Direct import also works
import { Alarm } from '@boxicons/react/icons/Alarm';

可用图标

图书馆包括所有Boxicons:

  • 1884 (英语) 基本(外线)图标
  • 1884 (英语) 已填入图标
  • 295个 品牌图标

命名公约

图标名称从 kebab- case SVG 文件名转换为 PascalCase :

SVG 文件组件名称
bx-alarm.svg<Alarm />
bx-alarm-clock.svg<AlarmClock />
bx-twitter.svg<Twitter />
bx-8-ball.svg<Icon8Ball />

说明: 以数字开头的图标被前缀为"Icon"(例如, Icon8Ball, (中文(简体) ), Icon500px) (中文(简体) ).

说明: 一些图标有"Icon"后缀来避免与保留词相冲突(例如, ReactIcon 用于反应标志).

类型脚本

导出类型的全类型脚本支持 :

import type { BoxIconProps, IconPack, IconSize, FlipDirection } from '@boxicons/react';

BoxIcon 选项

interface BoxIconProps extends SVGProps<SVGSVGElement> {
  pack?: 'basic' | 'filled' | 'brands';
  fill?: string;
  opacity?: number | string;
  width?: number | string;
  height?: number | string;
  size?: 'xs' | 'sm' | 'base' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
  flip?: 'horizontal' | 'vertical';
  rotate?: number | string;
  removePadding?: boolean;
}

@ boxicons/ 反应

版本与发布记录

@boxicons/react 共发布 4 个版本,首次发布于 2026/01/27;过去 12 个月发布了 4 个版本。

版本发布日期距今
1.0.3latest2026/02/168 个月前
1.0.22026/01/299 个月前
1.0.12026/01/279 个月前
1.0.02026/01/279 个月前

关于 @boxicons/react 的常见问题

@boxicons/react 是什么?

Boxicons 的反应组件

如何安装 @boxicons/react?

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

@boxicons/react 支持 TypeScript 吗?

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

@boxicons/react 支持 ESM 还是 CommonJS?

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

@boxicons/react 可以商用吗?

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

@boxicons/react 的下载量有多少?

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

@boxicons/react 还在维护吗?

最新版本 1.0.3 发布于 2026/02/16(8 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/01/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。