@boxicons/react

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

React components for Boxicons

原始使用文档
文档目录18 节
  1. Installation
  2. Usage
  3. Basic Usage
  4. Icon Packs
  5. Sizing
  6. Colors
  7. Opacity
  8. Flip
  9. Rotate
  10. Remove Padding
  11. Combining Props
  12. Standard SVG Props
  13. Ref Forwarding
  14. Tree Shaking
  15. Available Icons
  16. Naming Convention
  17. TypeScript
  18. BoxIconProps

@boxicons/react

React icon library built from Boxicons SVG files with full tree-shaking support.

Installation

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

Usage

Basic Usage

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

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

Icon Packs

Each icon can have multiple variants. Use the pack prop to switch between them:

  • basic - Outline/regular style icons (default for most icons)
  • filled - Solid/filled style icons
  • brands - Brand/logo icons (default for brand icons like Twitter, Facebook, etc.)
import { Alarm } from '@boxicons/react';

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

Sizing

Size Presets

Use the size prop for convenient preset sizes:

<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 */}

Custom Sizing

For custom sizes, use width and height props (overrides size):

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

Colors

Use the fill prop to change the icon color (defaults to currentColor):

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

Opacity

Control transparency with the opacity prop:

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

Flip

Mirror icons horizontally or vertically:

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

Rotate

Rotate icons by any degree:

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

Remove Padding

Remove the default 2px padding around icons for a tighter fit:

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

Combining Props

All props can be combined:

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

Standard SVG Props

All standard SVG props are supported and passed through to the underlying <svg> element:

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

Ref Forwarding

Refs are forwarded to the SVG element:

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

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

Tree Shaking

This library is fully tree-shakeable. Only the icons you import will be included in your final bundle.

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

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

Available Icons

The library includes all Boxicons:

  • 1884 basic (outline) icons
  • 1884 filled icons
  • 295 brand icons

Naming Convention

Icon names are converted from kebab-case SVG filenames to PascalCase:

SVG FileComponent Name
bx-alarm.svg<Alarm />
bx-alarm-clock.svg<AlarmClock />
bx-twitter.svg<Twitter />
bx-8-ball.svg<Icon8Ball />

Note: Icons starting with numbers are prefixed with "Icon" (e.g., Icon8Ball, Icon500px).

Note: Some icons have the "Icon" suffix to avoid conflicts with reserved words (e.g., ReactIcon for the React logo).

TypeScript

Full TypeScript support with exported types:

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

BoxIconProps

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/react

版本与发布记录

@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 是什么?

React components for 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 和提交记录判断。