PatternFly 4 Icons as React Components providing tree-shakable icon imports with TypeScript support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
PatternFly React Icons provides over 1,100 icon components for React applications, offering a comprehensive collection from FontAwesome, PatternFly design system, and custom Red Hat ecosystem icons. All icons are provided as tree-shakable React components with full TypeScript support and built-in accessibility features.
npm install @patternfly/react-iconsimport { UserIcon, ArrowRightIcon } from "@patternfly/react-icons";
import { createIcon } from "@patternfly/react-icons/dist/esm/createIcon";
import type { SVGIconProps, IconDefinition } from "@patternfly/react-icons/dist/esm/createIcon";For individual icon imports (recommended for tree-shaking):
import UserIcon from "@patternfly/react-icons/dist/esm/icons/user-icon";
import ArrowRightIcon from "@patternfly/react-icons/dist/esm/icons/arrow-right-icon";For CommonJS:
const { UserIcon, ArrowRightIcon } = require("@patternfly/react-icons");import { UserIcon, ArrowRightIcon, CheckIcon } from "@patternfly/react-icons";
function MyComponent() {
return (
<div>
{/* Simple icon usage */}
<UserIcon />
{/* Icon with accessibility title */}
<ArrowRightIcon title="Navigate to next page" />
{/* Icon with custom styling */}
<CheckIcon className="text-green-500" style={{ fontSize: '24px' }} />
</div>
);
}PatternFly React Icons is built around several key components:
createIcon function generates React class components from icon definitions{Name}Icon)SVGIconProps and IconDefinition interfacesPre-built React components for all icons from FontAwesome, PatternFly, and custom sources. Each icon follows consistent naming patterns and includes accessibility features.
// Example icon components
const UserIcon: React.ComponentClass<SVGIconProps>;
const ArrowRightIcon: React.ComponentClass<SVGIconProps>;
const CheckIcon: React.ComponentClass<SVGIconProps>;
interface SVGIconProps extends Omit<React.HTMLProps<SVGElement>, 'ref'> {
title?: string;
className?: string;
}Factory function for creating custom icon components from icon definitions, enabling creation of custom icons that match the library's patterns.
function createIcon(iconDefinition: IconDefinition): React.ComponentClass<SVGIconProps>;
interface IconDefinition {
name?: string;
width: number;
height: number;
svgPath: string | SVGPathObject[];
xOffset?: number;
yOffset?: number;
svgClassName?: string;
}
interface SVGPathObject {
path: string;
className?: string;
}Comprehensive categorized collections of icons from different sources, each with specific naming conventions and use cases.
// FontAwesome Icons (1000+ icons)
const TimesIcon: React.ComponentClass<SVGIconProps>; // Solid icons
const OutlinedUserIcon: React.ComponentClass<SVGIconProps>; // Regular icons
const FacebookIcon: React.ComponentClass<SVGIconProps>; // Brand icons
// PatternFly Icons (100+ icons)
const SaveAltIcon: React.ComponentClass<SVGIconProps>;
const EditAltIcon: React.ComponentClass<SVGIconProps>;
// Custom Icons (10 icons)
const OpenshiftIcon: React.ComponentClass<SVGIconProps>;
const AzureIcon: React.ComponentClass<SVGIconProps>;interface SVGIconProps extends Omit<React.HTMLProps<SVGElement>, 'ref'> {
/** Accessibility title for the icon */
title?: string;
/** Additional CSS classes */
className?: string;
}
interface IconDefinition {
/** Display name for the icon component */
name?: string;
/** Icon width in pixels */
width: number;
/** Icon height in pixels */
height: number;
/** SVG path data or array of path objects */
svgPath: string | SVGPathObject[];
/** X-axis offset (default: 0) */
xOffset?: number;
/** Y-axis offset (default: 0) */
yOffset?: number;
/** CSS class for the SVG element */
svgClassName?: string;
}
interface SVGPathObject {
/** SVG path data */
path: string;
/** CSS class for this specific path */
className?: string;
}
interface IconConfig {
name: string;
height: number;
width: number;
svgPath: string | SVGPathObject[];
yOffset: number;
xOffset: number;
svgClassName: string | null;
}