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

@terriblemia/eight-ball

v0.2.0

Published

A Web Component for showing a random selection from a group of options

Downloads

13

Readme

eight-ball

A Web Component for showing a random selection from a group of options (and allowing you to shake it up).

Features

Demo

Open in StackBlitz

Examples

General usage example:

<script type="module" src="eight-ball.js"></script>

<eight-ball>
  <span>It is certain</span>
  <span hidden>It is decidedly so</span>
  <span hidden>Without a doubt</span>
  <span hidden>Yes definitely</span>
  <span hidden>You may rely on it</span>
</eight-ball>

Installation

You have a few options (choose one):

  1. Install via npm: npm install @terriblemia/eight-ball
  2. Download the source manually from GitHub into your project.
  3. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)

Usage

Make sure you include the <script> in your project (choose one, and update the version number as needed):

<!-- Host yourself -->
<script type="module" src="eight-ball.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://www.unpkg.com/@terriblemia/[email protected]/eight-ball.js"
></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://esm.sh/@terriblemia/[email protected]"
></script>

Or use the built in WebC component with Eleventy, by adding "npm:@terriblemia/eight-ball/*.webc" to the Eleventy WebC Plugin components registry:

// Only one module.exports per configuration file, please!
module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(eleventyWebcPlugin, {
    components: [
      // Add as a global WebC component
      "npm:@11ty/eight-ball/*.webc",
    ],
  });
}

Attributes & parts

  • By default, a ::part(button) is exposed for styling.
  • Optionally provide a data-action attribute to override the inner text of ::part(button)
  • Optionally set data-current on one of the options to enforce an initial state
  • Optionally add the (boolean) view-transition attribute to transition between values in supporting browsers.

Slots

  • Any element in the default slot will be treated as an option
  • If any element is marked for slot="options", the children of that element will be the options to choose from (this overrides the default slot)
  • Anything in slot="action" will replace the ::part(button), and the fist button in the slot will be used as a trigger for getting a new random selection

Properties & methods

  • EightBall.options (read-only, array): the collection of elements to select from
  • EightBall.action (read-only, HTMLButtonElement): the action button that controls the eight-ball
  • EightBall.actionText (read/write, string): the action button's inner text
  • EightBall.current (read/write, HTMLElement): the currently selected option, if any
  • EightBall.onDeck (read-only, array): the options that have not yet been displayed (or all non-current options, once all have been seen)
  • EightBall.shake(): hide the current selection, and show a new one from the list of options currently on-deck!

ToDo

Things we might need…

  • [ ] Allow moving the action before the options?
  • [ ] More repeat options (maybe data-repeat):
    • cycle: the current behavior
    • always: everything is always 'on-deck'
    • never: only go through the options once???

Support

At OddBird, we enjoy collaborating and contributing as part of an open web community. But those contributions take time and effort. If you're interested in supporting our open-source work, consider becoming a GitHub sponsor, or contributing to our Open Collective.

❤️ Thanks!

Credit

With thanks to the following people: