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/ground-control

v0.3.0

Published

A Web Component for user control of HTML attributes and CSS properties

Downloads

2

Readme

ground-control

A Web Component for user control of HTML attributes and CSS properties on other elements of the page.

  • Use input-control to get values from input and select elements
  • Use toggle-control to get values from solo or grouped toggle buttons
  • Use switch-control for single on/off switch buttons (and extend by providing functions to the onPress() and onUnPress() methods)
  • Store and retrieve values in either sessionStorage or localStorage
  • Update output elements to display the current values
  • Provide reset buttons, to clear any changes
  • Extend the ground-control base class to set up other sources for broadcasting

Demo

Examples

With a range input:

<script type="module" src="index.js"></script>

<input-control
  data-for=".color-swatch"
  data-prop="--hue"
  data-session="hue"
>
  <label for="hue">Hue</label>
  <input id="hue" type="range" min="0" max="360" value="200">
  <output for="hue"></output>
</input-control>

Or a group of toggle buttons:

<toggle-control
  id="color-scheme"
  data-prop="color-scheme"
  data-local="color-scheme"
  data-off="light dark"
>
  <strong>Color Scheme</strong>
  <button data-value="light dark" aria-pressed="true">auto</button>
  <button>light</button>
  <button>dark</button>
</toggle-control>

Or a switch:

<switch-control data-prop="color-scheme" data-on="dark">
  <button id="dark-mode" is-switch>dark mode</button>
</switch-control>

Installation

You have a few options (choose one):

  1. Install via npm: npm install @terriblemia/ground-control
  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="index.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://www.unpkg.com/@terriblemia/[email protected]/index.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 components with Eleventy, by adding "npm:@terriblemia/ground-control/*.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:@terriblemia/ground-control/*.webc",
    ],
  })
}

This provides input-control and toggle-control components.

All the attributes

  • ground-control base class
  • input-control supports basic input and select types (but not files, checkboxes, or radios)
  • toggle-control supports solo and grouped toggles
  • Built-in WebC components
  • Control element attributes:
    • id="<control-id>" [optional]: A standard HTML id for referencing the control
    • data-for="<selector>" [defaults to :root]: the elements to update
    • data-prop="<css-property-name>" [optional]: the CSS property to set
    • data-attr="<attribute-name>" [optional]: the HTML attribute to set
    • data-local="<localStorage-key>" [optional]: store and retrieve the value from localStorage
    • data-session="<sessionStorage-key>" [optional]: store and retrieve the value from sessionStorage
    • data-event="<event-name>" [optional]: only used by input-control at this point, which can listen for either change (the default) or input
    • data-off="<value>" [optional]: the value to use when no other value is selected (primarily for toggles, but also useful with select)
    • for switch-control only…
      • data-on="<value>" [optional]: the value to use when toggled on (falls back to the button value defined below)
      • data-id [optional]: establishes which nested button to use as a toggle, if multiple are present
  • button element attributes inside toggle-control:
    • data-value [defaults to the button.innerText]: provide a value for the toggle that is different from the text of the button
    • aria-pressed [optional]: set the initial pressed state of each toggle (only one in a toggle-control can be pressed at a time)
  • Support for output displays and reset buttons:
    • Using the id of the input/select or the toggle-control
    • <output for="<control-id>">: will set the output as a display for the control
    • <button data-reset="<control-id-list>">: will use the button to clear the referenced controls

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: