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-quiz-match

v1.0.1

Published

A quiz component to match or connect items from one set with the items from another

Downloads

2

Readme

React Quiz Match

npm version minzipped package size

Take a card from the left, connect it with the one from the right!

A quiz component to match or connect items from one set with the items from another.

Installation

npm install react-quiz-match
pnpm add react-quiz-match

Type definitions are built in 😎.

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

Usage

It exports two things, a component Match and a hook useMatchLines. The Match component also contains a related component, Match.Item, to render out the items on either sides.

Props of Match:

interface MatchProps {
  /** Allows you to use the component in an uncontrolled way. */
  defaultValue?: Record<string, string>;
  /** Specify the options using `Match.Item` components anywhere within the tree. */
  children: ReactNode;
  /** Allows you to use the component in a controlled way. */
  value?: Record<string, string>;
  /** Disables the buttons. */
  disabled?: boolean;
  /** Called with an object of key-value pairs when the user changes the choice. */
  onChange?: (value: Record<string, string>) => void;
}

Props of Match.Item:

/** The presence of `value` marks the item as a value, the presence of a key marks it as a key. */
type MatchItemProps = (
  | { value: string; name?: never }
  | { name: string; value?: never }
) &
  Omit<ComponentProps<"button">, "name" | "value" | "onClick">;

Example

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

<Match
  className="flex justify-between"
  onChange={console.log}
  disabled={disabled}
>
  <div className="flex flex-col gap-2">
    <Match.Item name="pizza-shop">Pizza shop</Match.Item>
    <Match.Item name="library">Library</Match.Item>
  </div>

  <MatchLines
    answers={
      answersShown ? { "pizza-shop": "user", library: "user" } : undefined
    }
  />

  <div className="flex flex-col gap-2">
    <Match.Item value="post">Post</Match.Item>
    <Match.Item value="user">User</Match.Item>
  </div>
</Match>

Styling

The <Match> component renders nothing (in other words, it is a headless component). The Match.Item component renders a button

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.