npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@github/octicons-react

v7.4.0

Published

A scalable set of icons handcrafted with <3 by GitHub.

Downloads

64

Readme

GitHub Octicons React Component

npm version Build Status

Octicons for React

Install

$ npm install @github/octicons-react --save

Usage

<Octicon>

The <Octicon> component is really just the "shell" of an Octicon that renders the <svg> element and all of its attributes. To render a specific icon, you must pass it either via the icon prop, or as the only child:

/**
 * The prop form is shorter, but doesn't allow you to pass icon props.
 */
<Octicon icon={Icon} />

/**
 * The child form allows you to pass props.
 */
<Octicon><Icon x={10}/></Octicon>

Note that none of our builtin icons take props, so unless you're creating custom icons you'll probably want to use the icon prop form.

Icons

The @github/octicons-react module exports the Octicon component as default and the individual icon symbols as separate named exports. This allows you to import only the icons that you need without blowing up your bundle:

import React from 'react'
import Octicon, {Beaker, Zap} from '@github/octicons-react'

export default function Icon({boom}) {
  return <Octicon icon={boom ? Zap : Beaker}/>
}

If you were to compile this example with a tool that supports tree-shaking (such as Webpack, Rollup, or Parcel) the resulting bundle would only include the "zap" and "beaker" icons.

All icons

If you don't mind your bundle being huge or you need to be able to render arbitrarily named icons at runtime, you can import either of the following named exports:

getIconByName()

The getIconByName export is a function that takes a lowercase octicon name (such as arrow-right) and returns the corresponding icon class. Using this helper, it's possible to create an Octicon class that takes a name prop and resolves it to the right component:

import React from 'react'
import Octicon, {getIconByName} from '@github/octicons-react'

export default function OcticonByName({name, ...props}) {
  return <Octicon {...props} icon={getIcon(name)} />
}

iconsByName

The iconsByName export is an object that maps keys (such as arrow-right or zap) to component functions, which you can use to generate listings of all the octicons:

import React from 'react'
import Octicon, {iconsByName} from '@github/octicons-react'

export default function OcticonsList() {
  return (
    <ul>
      {Object.keys(iconsByName).map(key => (
        <li key={key}>
          <tt>{key}</tt>
          <Octicon icon={iconsByName[key]}/>
        </li>
      ))}
    </ul>
  )
}

Vertical alignment

By default the octicons have vertical-align: text-bottom; applied as inline styles. You can change the alignment via the verticalAlign prop, which can be either middle, text-bottom, text-top, or top.

import Octicon, {Repo} from '@github/octicons-react'

export default () => (
  <h1>
    <Octicon icon={Repo} size='large' verticalAlign='middle' /> github/github
  </h1>
)

ariaLabel

You have the option of adding accessibility information to the icon with the aria-label attribute via the ariaLabel prop (note the capitalization of L!).

// Example usage
import Octicon, {Plus} from '@github/octicons-react'

export default () => (
  <button>
    <Octicon icon={Plus} ariaLabel="Add new item" /> New
  </button>
)

Sizes

The size prop takes small, medium, and large values that can be used to render octicons at standard sizes:

| Prop | Rendered Size | | :- | :- | | size='small' | 16px height by computed width | | size='medium' | 32px height by computed width | | size='large' | 64px height by computed width |

// Example usage
import Octicon, {LogoGithub} from '@github/octicons-react'

export default () => (
  <h1>
    <a href='https://github.com'>
      <Octicon icon={LogoGithub} size='large' ariaLabel='GitHub'/>
    </a>
  </h1>
)

Custom icons

Each of our icon components is really just a function that renders its SVG <path>. To accommodate icons varying aspect ratios, the Octicon component determines the viewBox of the <svg> element by first looking for a size array on the icon component class. For instance, if you wanted to create a custom icon that consisted of three circles side by side, you could do this:

import React from 'react'
import Octicon from '@github/octicons-react'

function CirclesIcon() {
  return (
    <React.Fragment>
      <circle r={5} cx={5} cy={5}/>
      <circle r={5} cx={15} cy={5}/>
      <circle r={5} cx={25} cy={5}/>
    </React.Fragment>
  )
}

CirclesIcon.size = [30, 10]

export default CirclesOcticon(props) {
  return <Octicon {...props} icon={CirclesIcon} />
}

License

(c) GitHub, Inc.

When using the GitHub logos, be sure to follow the GitHub logo guidelines.

MIT