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

@illright/react-feed

v1.0.0

Published

An unstyled React component that implements the WAI-ARIA feed pattern

Downloads

2

Readme

@illright/react-feed

npm version minzipped package size

Your list of cards could do with a bit of keyboard navigation, eh?

The headless implementation of the ARIA feed pattern for React.

Installation

pnpm add @illright/react-feed

Type definitions are built in 😎.

Minimum requirements for React? The one that has hooks (16.8+), that's it.

What do you mean "I don't use pnpm"? It's so much faster! Alright, here's your npm command:

npm install --save @illright/react-feed

Usage

It exports two components:

  • Feed, the list of cards
    Props:
    • aria-labelledby?: string, the ID of the element that labels the feed. This element should be outside the feed, like a sibling.
    • aria-busy?: boolean, whether the feed is being updated with more articles.
  • Article, each individual card
    Props:
    • Required: aria-labelledby: string, the ID of the element that labels the article. This element should be inside the article.
    • aria-describedby?: string, the ID of the element that describes the article. It should be inside the article.

Here's an example (see the demo folder for a complete one):

import { useId } from "react";  // This is from React 18, but you don't have to use it
import { Feed, Article } from "react-feed";

// ↓ This is a hook to fetch data, e.g. from React Query
import { useArticles } from "./data";

export function App() {
  const idBase = useId();
  const { data: articles, fetchNextPage, isFetching } = useArticles();

  return (
    <Feed aria-busy={isFetching}>
      {articles.map((article) => (
        <Article
          key={article.title}
          aria-labelledby={`${idBase}-${article.id}`}
          aria-describedby={`${idBase}-${article.id}-desc`}
        >
          <h2 id={`${idBase}-${article.id}`}>{article.title}</h2>
          <p id={`${idBase}-${article.id}-desc`}>
            {article.description}
          </p>
        </Article>
      ))}
      // ↓ Note that the "load more" button should be an article too.
      <Article aria-labelledby={`${idBase}-more`}>
        <button
          id={`${idBase}-more`}
          onClick={() => fetchNextPage()}
        >
          Load more posts
        </button>
      </Article>
    </Feed>
  );
}

Styling

The <Feed> component renders a <div role="feed"> with no styling, you can pass any other props to it, for example, a class to style it. Similarly, the <Article> renders a <article> with no styling.

Therefore, styling with Tailwind CSS, plain CSS, or any other CSS-in-JS library is easy. Styling with styled-components will be supported in future versions.

License

The source code of this project is distributed under the terms of the ISC license. It's like MIT, but better. Click here to learn what that means.