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

stoke-toolbelt

v0.8.1

Published

React components used for making websites at Stoke Studio

Downloads

5

Readme

Stoke Toolbelt

This is a collection of React components we use at Stoke Studio for creating websites.

Install

yarn add stoke-toolbelt

Dependencies:

yarn add lodash prop-types react react-ga react-router-dom

Components

NotFound

See Rendering Routes with Statuses. For use with react-router.

Props: Same props as Route

<Switch>
  <Route path="/page1" component={Page1} />
  <Route path="/page2" component={Page2} />
  <Route path="/page3" component={Page3} />

  <NotFound component={NotFoundPage} />
</Switch>

PermanentRedirect

For use with react-router. Forwards search query to new path.

Props: Same props as Route

<Switch>
  <Route path="/page1" component={Page1} />
  <Route path="/page2" component={Page2} />
  <Route path="/page3" component={Page3} />

  <PermanentRedirect exact from="/about-us" to="/about" />
</Switch>

RetinaImage

Props:

  • srcs: array of source paths in increasing densities [1x, 2x, 3x]
  • naturalWidth: the width image should actually be (width of 1x image)
  • alt: accessible alt text
<RetinaImage
  srcs={[
    '/images/my-image.jpg',
    '/images/[email protected]',
    '/images/[email protected]'
  ]}
  naturalWidth={500}
  alt="My Image"
/>

ScrollToTop

For use with react-router. Scroll to top of page on route changes.

<ScrollToTop>
  <App />
</ScrollToTop>

TrackPageViews

Tracks page views with Google Analytics (via react-ga) and Bing UET (if loaded)

Props:

  • trackingId: Google Analytics Tracking ID (ex. UA-12345678-1)
    • Supports multiple Tracking IDs: [{ trackingId: 'UA-1' }, { trackingId: 'UA-2', gaOptions: { name: 'second' }}]
      • At least one tracker must be named
      • Pageviews are tracked via all trackers (regardless of name)
  • onInit: Function ran after react-ga is initialized. ReactGA is passed as only parameter. Only runs in browser—never on server.
const App = () => (
  <TrackPageViews trackingId="UA-12345678-1">
    <Layout>
      <Switch>
        <Route exact path="/" component={Home} />
      </Switch>
    </Layout>
  </TrackPageViews>
);

WindowSize

Props:

  • render: passed object of { width } where width is current width of window
    • Note: width value calculation is throttled
<WindowSize
  render={({ width }) => (
    <div style={{ width: width * 0.5 }}>
      This is always fixed at half of window width.
    </div>
  )}
/>

Rendering Routes with Statuses

Express example:

const context = {};
const markup = renderToString(
  <StaticRouter context={context} location={req.url}>
    <App />
  </StaticRouter>
);

if (context.url) {
  res.redirect(context.status || 302, context.url);
} else {
  res.status(context.status || 200).send(`<html>...</html>`);
}