React components for GitHub's Octicons icon library providing scalable SVG icons with tree-shaking support and TypeScript definitions.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
@primer/octicons-react icons support comprehensive styling options through props and standard React/CSS approaches. All icons inherit styling capabilities from standard SVG elements while providing convenient abstractions for common use cases.
type Size = 'small' | 'medium' | 'large'
interface SizeProps {
/** Size as predefined string or custom pixel value */
size?: number | Size
}Size Mappings:
small: 16px height by computed widthmedium: 32px height by computed widthlarge: 64px height by computed widthimport { BeakerIcon } from '@primer/octicons-react'
function CustomSizes() {
return (
<div>
<BeakerIcon size={12} /> {/* 12px height */}
<BeakerIcon size={24} /> {/* 24px height */}
<BeakerIcon size={48} /> {/* 48px height */}
<BeakerIcon size={96} /> {/* 96px height */}
</div>
)
}Icons automatically maintain their aspect ratio when height is specified. Width is computed based on the original icon proportions using the formula: width = height * (naturalWidth / naturalHeight) where natural dimensions come from the closest available SVG variant.
interface ColorProps {
/** Fill color (defaults to 'currentColor') */
fill?: string
}Default Behavior:
Icons use currentColor by default, inheriting the text color from their parent element.
import { AlertIcon, CheckIcon } from '@primer/octicons-react'
function ColorExamples() {
return (
<div style={{ color: 'blue' }}>
{/* Uses parent's blue color */}
<AlertIcon />
{/* Explicit red color */}
<CheckIcon fill="#ff0000" />
{/* CSS color names */}
<AlertIcon fill="green" />
{/* CSS variables */}
<CheckIcon fill="var(--primary-color)" />
</div>
)
}interface AlignmentProps {
/** @deprecated use v-align utilities instead - Vertical alignment relative to text baseline */
verticalAlign?: 'middle' | 'text-bottom' | 'text-top' | 'top' | 'unset'
}Alignment Values:
text-bottom (default): Aligns with text baselinemiddle: Centers with text middletext-top: Aligns with text toptop: Aligns with element topunset: Removes alignment stylingimport { RepoIcon } from '@primer/octicons-react'
function AlignmentExamples() {
return (
<div>
<h1>
<RepoIcon verticalAlign="middle" /> Repository Name
</h1>
<p>
<RepoIcon verticalAlign="text-bottom" /> Default alignment
</p>
<span>
<RepoIcon verticalAlign="text-top" /> Top aligned
</span>
</div>
)
}interface CSSProps {
/** CSS class names */
className?: string
/** Inline styles */
style?: React.CSSProperties
}import { GearIcon } from '@primer/octicons-react'
function StyledIcons() {
return (
<div>
{/* CSS classes */}
<GearIcon className="icon-primary rotating" />
{/* Inline styles */}
<GearIcon
style={{
color: '#0969da',
cursor: 'pointer',
transition: 'transform 0.2s'
}}
/>
</div>
)
}Icons work seamlessly with styled-components, emotion, and other CSS-in-JS libraries:
import styled from 'styled-components'
import { SearchIcon } from '@primer/octicons-react'
const StyledIcon = styled(SearchIcon)`
color: ${props => props.theme.primaryColor};
cursor: pointer;
transition: all 0.2s ease;
&:hover {
transform: scale(1.1);
color: ${props => props.theme.hoverColor};
}
`
function SearchButton() {
return <StyledIcon size="medium" />
}import { MenuIcon } from '@primer/octicons-react'
function ResponsiveIcon() {
return (
<MenuIcon
className="responsive-icon"
style={{
width: 'clamp(16px, 4vw, 32px)',
height: 'auto'
}}
/>
)
}import { SyncIcon } from '@primer/octicons-react'
function SpinningIcon() {
return (
<SyncIcon
className="spinning"
size="medium"
style={{
animation: 'spin 1s linear infinite'
}}
/>
)
}
// CSS
/*
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
*/Icons inherit CSS custom properties and work with design system tokens:
import { StarIcon } from '@primer/octicons-react'
function ThemedIcon() {
return (
<StarIcon
fill="var(--color-icon-primary)"
size="var(--size-icon-medium)"
style={{
marginRight: 'var(--spacing-xs)'
}}
/>
)
}currentColor for icons that should match text colorInstall with Tessl CLI
npx tessl i tessl/npm-primer--octicons-react