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

react-github-data

v1.0.0

Published

A collection of React components to easily display basic information about a GitHub user, repository, etc.

Downloads

1

Readme

Features

This library is not a widget; you can use the components to display a single piece of data and integrate it into your webpage as desired

  • Easy to use
  • Data is fetched once for multiple components
  • Fetched data is cached
  • Easy to style and customize with CSS

Example

import { GitHubRepo } from "react-github-data";

Display stars

<GitHubRepo user="Droppers" repo="AnimatedBottomBar" data="stars" />

Display custom content

<GitHubRepo
  user="Droppers"
  repo="AnimatedBottomBar"
  content={(data) => (
    <>
      The <b>{data.name}</b> repo has <b>{data.stars}</b> stars and
      <b>{data.forks}</b>forks!
    </>
  )}
/>

Available components

GitHubRepo

To display information about a repository use the GitHubRepo component.

import { GitHubRepo } from 'react-github-data';
...
<GitHubRepo
  user="Droppers"
  repo="AnimatedBottomBar"
  data="stars" />

Props

GitHubUser

import { GitHubUser } from 'react-github-data';
...
<GitHubUser
  user="Droppers"
  data="followers" />

Props

Customization

Custom content

As shown in the example in the beginning, it is also possible to use one component to display all information desired. For this the content prop can be used, this props expects a function with the fetched data as argument.

Load and error callbacks

If you want to do something in case an error occurs while fetching the data or the data is successfully loaded, you can use one of the following callback props:

  • onDataLoad
  • onDataError (Note: does not include the error message due to the design of the library)

Loading and error content

By default, the content of the component will be empty when loading or when an error occurs. To change the default content for these situations, you can use the props demonstrated in the example below.

import { GitHubUser } from 'react-github-data';
...
<GitHubRepo
  loading={<div>Loading information. (JSX)</div>}
  error="Could not load information. (text)" />

Styling

There are also several standard styleable classes that you can use, and you can use your own using the className prop. The inner HTML element of this component is a div element.

Example

Below is an example of JSX and CSS on how to recreate the widget shown above.

JSX There are two methods you can use, you can use multiple components, as demonstrated in the first example, or use the content prop to use one component to display more information, as demonstrated in the second example.

import React from "react";
import { GitHubRepo } from "react-github-data";

export default function App() {
  const user = "Droppers";
  const repo = "AnimatedBottomBar";

  return (
    <>
      <h1>Example one</h1>
      <div className="github-card">
        <div className="name">AnimatedBottomBar</div>
        <div className="description">
          <GitHubRepo user={user} repo={repo} data="description" />
        </div>
        <div className="info">
          <GitHubRepo user={user} repo={repo} data="language" />
          <img alt="Stars" src="https://svgshare.com/i/YQV.svg" />
          <GitHubRepo user={user} repo={repo} data="stars" />
          <img alt="Forks" src="https://svgshare.com/i/YNP.svg" />
          <GitHubRepo user={user} repo={repo} data="forks" />
        </div>
      </div>

      <h1>Example two</h1>
      <GitHubRepo
        className="github-card"
        user={user}
        repo={repo}
        content={(data) => (
          <>
            <div className="name">{data.name}</div>
            <div className="description">{data.description}</div>
            <div className="info">
              {data.language}
              <img alt="Stars" src="https://svgshare.com/i/YQV.svg" />
              {data.stars}
              <img alt="Forks" src="https://svgshare.com/i/YNP.svg" />
              {data.forks}
            </div>
          </>
        )}
      />
    </>
  );
}

CSS

.github-card {
  width: 400px;
  padding: 15px;
  background-color: white;
  border: 1px solid #bbb;
  border-radius: 10px;
  font: 14px Arial;
}

.github-card .name {
  color: #0b69ff;
  font-weight: bold;
}

.github-card .description {
  margin: 10px 0;
}

.github-card .info div {
  margin-right: 10px;
}
.github-card .info img {
  margin-right: 5px;
  vertical-align: text-bottom;
}

License

MIT License

Copyright (c) 2021 Joery Droppers (https://github.com/Droppers)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.