@bradleyhodges/sfsymbols-react

中文文档
8.1.3发布于 2026/09/08TypeScriptESM + CJS近 30 天下载 3190

Components and utilities for using icons from the @bradleyhodges/sfsymbols package in React applications.

原始使用文档
文档目录10 节
  1. Companion package for using Apple's SF Symbols icons from @…
  2. Available Icons
  3. 🚀 Getting Started
  4. Install the Packages
  5. Usage
  6. Optimising for performance
  7. Styled and unstyled entries
  8. Props and precedence
  9. Metadata helpers and types
  10. Optional VS Code previews

@bradleyhodges/sfsymbols-react

Companion package for using Apple's SF Symbols icons from @bradleyhodges/sfsymbols in React/Next.js.

NPM Downloads by package author npmjs package GitHub repo
Version: 8.1.3 Platforms: Next.js – React.js – React Nav License: MIT

SF Symbols is a library of over 7,000 symbols that are designed to integrate seamlessly with San Francisco, the system font for Apple platforms.

Available Icons • 🚀 Getting Started • Install • Usage • Optimising for Performance • Style Entries • Props • VS Code Extension • Issues • Pull Requests

[!CAUTION] SF Symbols is licensed by Apple for use only on Apple platforms. Use of this package, or any of the other @bradleyhodges/sfsymbols-* packages, outside of Apple platforms is NOT permitted.

Available Icons

@bradleyhodges/sfsymbols contains 8,111 icons, which includes 609 supplementary brand icons. All 7,502 of the Regular weight icons from the San Francisco font are included. Other weights and variable icon directives are not included in this package, but the icon weights can be made heavier by applying a stroke to the vector paths.

For simplicity, I've created a basic icon browser for this package, which you can access here: bradleyhodges-sfsymbols.vercel.app Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.

🚀 Getting Started

This package contains the React components and metadata helpers that allow you to use these icons in your React/Next.js project. The actual icons and icon data for SF Symbols 8 come from the sfsymbols package, which you'll need to install as well.

Install the Packages

You will need to install the following packages to use the icons in your project:

pnpm add @bradleyhodges/sfsymbols @bradleyhodges/sfsymbols-react

The component wrapper renders web DOM <svg> elements. React Native applications need a native SVG renderer instead. This library supports React 18 and 19.

Usage

It's dead simple to get going. Once you've installed the above packages, you can simply import and use them:

import SFIcon from "@bradleyhodges/sfsymbols-react";
import { sfArrowUpCircleFill, sfCheckmark, sfCrossVialFill } from "@bradleyhodges/sfsymbols";

function MyComponent() {
    return (
        <div>
            <SFIcon icon={sfArrowUpCircleFill} />
            <SFIcon icon={sfCheckmark} weight={2} />
            <SFIcon icon={sfCrossVialFill} size={24} className="text-red-500" />
        </div>
    );
}

Use the icon browser to find icons you want to use.

Optimising for performance

The default and SFIcon exports are the same memoized, ref-forwarding component. For an opt-in direct icon import, use the exact sf* leaf path. This lets a bundler avoid parsing the catalogue's large root barrel:

import { SFIcon } from "@bradleyhodges/sfsymbols-react";
import { sfArrowUpCircleFill } from "@bradleyhodges/sfsymbols/sfArrowUpCircleFill";

<SFIcon icon={sfArrowUpCircleFill} size={24} color="rebeccapurple" />;

Do not build an application registry that imports every icon merely to support runtime lookup. Import the icons used by the application, or load bounded groups on demand.

Styled and unstyled entries

The root entry merges these compatibility classes with className by using the cn engine with a default base class set: inline-block align-middle overflow-visible text-current box-content h-[1em] -leading-[0.125em]. The default h-[1em] class is omitted when size or a native height is supplied, and caller sizing utilities win class conflicts.

The unstyled entry renders the same SVG, paths, accessibility markup, ref, and events without importing cn or adding classes:

import SFIcon from "@bradleyhodges/sfsymbols-react/unstyled";

<SFIcon icon={sfArrowUpCircleFill} className="icon" />;

Use the root entry for the established layout behavior. Use /unstyled when the application owns all SVG layout and wants the smaller boundary.

Props and precedence

SFIcon accepts ordinary React.SVGProps<SVGSVGElement> plus the following props:

PropTypeBehavior
iconIconDefinitionRequired icon geometry and metadata.
sizenumber | string | nullSets both dimensions unless a native dimension overrides it. Explicit 0 is preserved.
width, heightnative SVG valuesOverride size independently.
colorCSS colorOverrides each path's source fill.
weightnumber | nullAdds root fill, stroke, stroke width and round joins. It is a stroke effect, not selection of Apple's native SF Symbols weights.
fillOpacitystring | number | nullOverrides source path opacity. With weight, the legacy default is 1.
preservePathOpacitybooleanKeeps source opacity when weight is set and fillOpacity is absent.
className, stylenative SVG valuesApply to the SVG. The styled entry merges classes; ordinary CSS cascade and inline-style rules still apply.
titlestringRenders <title> and generates its linked ID.
descriptionstringRenders <desc> and generates its linked ID. A description alone does not name an image; also supply title, aria-label, or an external accessible name.
titleId, descriptionIdstringReplace the generated ID for the corresponding element. They have no effect when that element is absent.
svgChildrenReactNodeInserts SVG content such as defs before the icon paths. Legacy children remain ignored.
pathPropspath props or (path, index) => path propsApplies safe per-path presentation and event props after generated fill and opacity.

Dimension precedence is native width or height, then size, then the icon's positive width, then its positive height, then 1em. The definition fallback is deliberately square for compatibility. A zero definition dimension is not used as the fallback, while an explicit size={0}, width={0}, or height={0} remains zero.

Path fill precedence is pathProps.fill, color, source fill, then currentColor. Path opacity precedence is pathProps.fillOpacity, explicit fillOpacity, the legacy weight default unless preservePathOpacity is true, then source opacity. pathProps.style follows ordinary React style precedence. Geometry and child ownership stay with the renderer: d, key, ref, children, and dangerouslySetInnerHTML are excluded by the public type and filtered at runtime.

Native SVG props, including refs and event handlers, are forwarded. Explicit role, aria-hidden, aria-label, aria-labelledby, and aria-describedby override generated accessibility attributes. When title and aria-label are both present, the title's generated aria-labelledby takes naming precedence; explicitly override aria-labelledby, including with aria-labelledby={undefined}, when aria-label should supply the name. Without an accessible name the SVG is hidden; a title, aria-label, or external aria-labelledby makes it visible to accessibility APIs. Generated IDs are unique, stable across title removal and restoration, and can be replaced with deterministic IDs when server output needs them.

const iconRef = React.createRef<SVGSVGElement>();

<SFIcon
    ref={iconRef}
    icon={sfArrowUpCircleFill}
    title="Upload"
    description="Moves the selected item upward"
    svgChildren={
        <defs>
            <linearGradient id="upload-gradient">...</linearGradient>
        </defs>
    }
    pathProps={(path, index) => ({
        fill: index === 0 ? "url(#upload-gradient)" : path.fill,
    })}
/>

Plain serializable props and SVG children can render through React Server Components. Functions such as pathProps callbacks and event handlers must be introduced on the client side under the application's normal Server/Client boundary; the package does not add a use client directive.

Metadata helpers and types

The root and /metadata entries export getIconKeywords and getIconVariants. Both validate legacy catalogue shapes without mutating them, ignore inherited properties and accessors, preserve source order, and return frozen copies.

import {
    getIconKeywords,
    getIconVariants,
} from "@bradleyhodges/sfsymbols-react/metadata";

const keywords = getIconKeywords(sfArrowUpCircleFill);
const variants = getIconVariants<"custom">(sfArrowUpCircleFill);

Keyword arrays retain valid text, generic, and finite priority fields. Legacy string dictionaries become { text } entries without invented metadata. Variant maps retain own string values and use a null prototype, so arbitrary absent custom names such as toString safely resolve to undefined. Convert with { ...variants } when an API specifically requires an ordinary object prototype.

React Server Component props are one such boundary because React's serializable object form requires an ordinary object prototype:

<ClientComponent variants={{ ...getIconVariants(icon) }} />

Public types are available from the root, /unstyled, and the type-only /types entry: IconDefinition, SFIconProps, SFIconPathProps, SFIconPath, SFIconKeyword, and SFIconVariant. The additive SFIconProps type keeps the companion package's legacy contract intact.

Optional VS Code previews

The separate extension in extensions/vscode provides local hover previews and SF Symbols: Preview and Import Icon. It parses installed icon leaves as bounded static data and inserts exact per-icon imports; it is not an application dependency and does not ship an icon registry.

To build a local VSIX without installing or publishing it:

cd extensions/vscode
pnpm install --frozen-lockfile
pnpm test
pnpm typecheck
pnpm package

Then choose Extensions: Install from VSIX… in VS Code and select artifacts/sfsymbols-preview-0.1.0.vsix. See the extension README for supported syntax, security boundaries, limits, corpus checks, and the isolated extension-host workflow.

版本与发布记录

@bradleyhodges/sfsymbols-react 共发布 6 个版本,首次发布于 2025/09/23;过去 12 个月发布了 5 个版本。

版本发布日期距今
8.1.3latest2026/09/082 个月前
8.1.12026/09/072 个月前
8.0.42026/09/062 个月前
8.0.32026/09/062 个月前
8.0.22026/09/062 个月前
7.0.42025/09/231.1 年前

关于 @bradleyhodges/sfsymbols-react 的常见问题

@bradleyhodges/sfsymbols-react 是什么?

Components and utilities for using icons from the @bradleyhodges/sfsymbols package in React applications.

如何安装 @bradleyhodges/sfsymbols-react?

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

@bradleyhodges/sfsymbols-react 支持 TypeScript 吗?

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

@bradleyhodges/sfsymbols-react 支持 ESM 还是 CommonJS?

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

@bradleyhodges/sfsymbols-react 可以商用吗?

@bradleyhodges/sfsymbols-react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@bradleyhodges/sfsymbols-react 的下载量有多少?

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

@bradleyhodges/sfsymbols-react 还在维护吗?

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