@i316/heroicons-react
v0.1.1
Published
i316: Heroicons icons as tree-shakeable React components.
Maintainers
Readme
@i316/heroicons-react
i316: Heroicons icons as React components. 324 icons in 2 styles: outline (default), solid.
Other i316 Heroicons packages: @i316/heroicons-react-native (React Native), @i316/heroicons-vue (Vue 3), @i316/heroicons-angular (Angular) and @i316/heroicons-web (plain HTML web component and raw SVGs).
npm install @i316/heroicons-reactUsage
// One style: every icon is exported as both `Bell` and `BellIcon`.
import { ChevronDown, BellIcon } from '@i316/heroicons-react/outline';
// Any style from the root: <Name><Style>Icon, or <Name>Icon to switch style at runtime.
import { BellSolidIcon, HomeIcon } from '@i316/heroicons-react';
<ChevronDown size={20} color="#e11d48" />
<BellSolidIcon className="text-slate-500" title="Notifications" />
<HomeIcon variant={isActive ? 'solid' : 'outline'} />Works in React Server Components: icons can be rendered directly from server components (Next.js App Router).
Defaults for a whole subtree
import { HeroIconProvider } from '@i316/heroicons-react';
<HeroIconProvider size={20} color="currentColor" strokeWidth={2} className="shrink-0">
<App />
</HeroIconProvider>Props on an icon override the provider. Nested providers override their parent's values.
Icons chosen at runtime (CMS, user settings)
import { DynamicIcon, iconNames } from '@i316/heroicons-react/dynamic';
<DynamicIcon name={item.icon} variant="solid" fallback={<Spinner />} />Each icon is loaded as its own chunk the first time it renders. This is opt-in: only apps that import /dynamic pay for its map of every icon name.
Tree-shaking
Every icon is its own module and the package is sideEffects-free. Production builds in Vite, webpack, Rollup, esbuild and Next.js ship only the icons you import, whichever path you import from. <Name>Icon from the root includes every style of that one icon; import a specific style when you don't need switching.
Toolchains that don't tree-shake load a whole barrel for one named import: webpack in development, Jest, and anything else that runs modules unbundled. Two fixes:
Babel (Jest, webpack/babel-loader): add the bundled plugin. It rewrites import { Bell } from '…/outline' into import Bell from '…/outline/bell' at compile time.
// babel.config.js
module.exports = {
plugins: ['@i316/heroicons-react/babel'],
};Next.js (SWC, no Babel): use Next's own barrel optimization.
// next.config.js
module.exports = {
experimental: { optimizePackageImports: ['@i316/heroicons-react'] },
};Props
| Prop | Default | |
|---|---|---|
| size | 24 | width and height |
| color | currentColor | icon color |
| strokeWidth | 1.5 | outline only; ignored by the other styles |
| title | none | accessible name (see below) |
| variant | outline | <Name>Icon and DynamicIcon only: which style to render |
All other props pass through to the root <svg> (className, style, onClick, …), and ref is forwarded.
Accessibility: icons are decorative by default (aria-hidden="true"). Pass title to make one meaningful: it renders a <title> with role="img". Passing your own aria-label or role also removes aria-hidden.
Styling: every icon has the classes hero-icon hero-icon-<name> (e.g. hero-icon-chevron-down), plus any className you pass.
Editor previews: hovering an icon imported from a style path (@i316/heroicons-react/outline) in VS Code (or any TypeScript editor) shows a picture of it. Root imports have no previews, which keeps them light for the editor.
Module format, TypeScript and Jest
ESM only, with TypeScript declarations included. moduleResolution "bundler", "node16" and legacy "node" all resolve every import path. Node 20.19+ and 22.12+ can require() it. Peer dependency: react >= 16.8.
Jest's default CommonJS mode needs it transformed by your Babel setup (babel-jest), the usual configuration for ESM-only packages. Adding the plugin above keeps each test file from loading every icon:
// jest.config.js
transformIgnorePatterns: ['/node_modules/(?!@i316/heroicons-react/)'],License
Icons: Heroicons by Tailwind Labs (https://github.com/tailwindlabs/heroicons), licensed under MIT. i316 modified them: 24px outline and solid sets only, recolored to currentColor and reformatted; converted into React, React Native, Vue, Angular and web-component formats.
i316 code (components, runtime, tooling): MIT, © 2026 rahil316. See LICENSE for both licenses in full.
