Skip to main content

Type Definition

Overview

The IconContext interface defines the shape of the configuration object that can be provided to the IconContext.Provider. It allows you to set default values for icon properties that will be inherited by all icons within the provider’s component subtree.

Properties

string
Default color for all icons in the context.Accepted Values:
  • Hex colors: "#3b82f6"
  • RGB/RGBA: "rgb(59, 130, 246)", "rgba(59, 130, 246, 0.5)"
  • Named colors: "blue", "red", "currentColor"
  • HSL: "hsl(217, 91%, 60%)"
Default: undefined (icons use “currentColor”)Behavior: Individual icon color props override this value.Example:
string
Default size for all icons in the context.Accepted Values:
  • Any valid CSS size unit: "24px", "1.5em", "2rem", "100%"
Default: undefined (icons use “1em”)Note: Unlike IconBaseProps.size, this only accepts strings, not numbers.Behavior: Individual icon size props override this value.Example:
string
CSS class name(s) to apply to all icons in the context.Default: undefinedBehavior: Merged with individual icon className props. Both context and icon classes are applied.Merge Logic:
Example:
React.CSSProperties
Inline styles to apply to all icons in the context.Type: Standard React CSS properties objectDefault: undefinedBehavior: Merged with individual icon style props. Icon styles override context styles for the same property.Merge Precedence:
  1. Context styles (lowest priority)
  2. Icon color prop (applied to style.color)
  3. Icon style prop (highest priority)
Example:
React.SVGAttributes<SVGElement>
Additional SVG attributes to apply to all icons in the context.Accepted Attributes:
  • viewBox, preserveAspectRatio
  • strokeLinecap, strokeLinejoin, strokeWidth
  • fill, fillRule, fillOpacity
  • stroke, strokeOpacity, strokeDasharray
  • Any other valid SVG attributes
Default: undefinedBehavior: Merged with icon-specific attributes. Merge order:
  1. Context attr (lowest priority)
  2. Icon attr prop (if using IconBase)
  3. Other icon props (highest priority)
Example:

Default Values

When no IconContext.Provider is present, or when a property is not specified in the context value, icons use these defaults:

Usage Examples

Basic Configuration

Theme Integration

Accessibility Configuration

Stroke Customization

Responsive Sizing

Nested Contexts

Type Usage in TypeScript

Typing Context Configuration

Helper Function

Component Props

Merge Behavior

Understanding how context values merge with icon props:

Source Reference

The IconContext interface is defined in:
  • iconContext.tsx:3-9 - Interface definition
  • iconContext.tsx:11-17 - DefaultContext constant
  • iconContext.tsx:19-20 - Context creation