Type Definition
Overview
TheIconContext 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
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%)"
undefined (icons use “currentColor”)Behavior: Individual icon color props override this value.Example:Default size for all icons in the context.Accepted Values:
- Any valid CSS size unit:
"24px","1.5em","2rem","100%"
undefined (icons use “1em”)Note: Unlike IconBaseProps.size, this only accepts strings, not numbers.Behavior: Individual icon size props override this value.Example:CSS class name(s) to apply to all icons in the context.Default: Example:
undefinedBehavior: Merged with individual icon className props. Both context and icon classes are applied.Merge Logic: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:- Context styles (lowest priority)
- Icon
colorprop (applied to style.color) - Icon
styleprop (highest priority)
Additional SVG attributes to apply to all icons in the context.Accepted Attributes:
viewBox,preserveAspectRatiostrokeLinecap,strokeLinejoin,strokeWidthfill,fillRule,fillOpacitystroke,strokeOpacity,strokeDasharray- Any other valid SVG attributes
undefinedBehavior: Merged with icon-specific attributes. Merge order:- Context
attr(lowest priority) - Icon
attrprop (if using IconBase) - Other icon props (highest priority)
Default Values
When noIconContext.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:| Property | Merge Strategy | Example |
|---|---|---|
color | Icon prop overrides context | Context: blue, Icon: red → red |
size | Icon prop overrides context | Context: 2em, Icon: 3em → 3em |
className | Concatenated (context + icon) | Context: “base”, Icon: “special” → “base special” |
style | Merged (icon overrides on conflict) | Context: {opacity: 0.8}, Icon: {opacity: 1} → {opacity: 1} |
attr | Merged (icon overrides on conflict) | Context: {strokeWidth: "2"}, Icon: {strokeWidth: "3"} → {strokeWidth: "3"} |
Source Reference
TheIconContext interface is defined in:
iconContext.tsx:3-9- Interface definitioniconContext.tsx:11-17- DefaultContext constanticonContext.tsx:19-20- Context creation