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

@decidables/decidables-elements

v0.4.6

Published

decidables-elements: Basic UI Web Components for the decidables project

Downloads

47

Readme

@decidables/decidables-elementsWeb Components for Basic UI in decidables

npm version license

This package provides basic user interface web components for use in all of the explorables. This facilitates a consistent look and feel. They try to use the native inputs when possible, but build on them for new elements like a switch, and composite elements like a slider with a linked spinner.

Usage

Install

yarn add @decidables/decidables-elements

Use

import '@decidables/decidables-elements';

A bare import is used to register the elements in the custom registry, so they are then available for use in HTML.

Contents

Components

DecidablesButton / <decidables-button>

Button for taking actions

Slots
  • unnamed
    • Inline content as label
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
Example
<decidables-button disabled>
  Click me
</decidables-button>

DecidablesSlider / <decidables-slider>

Slider w/spinner for selecting a numeric value from a range

Slots
  • unnamed
    • Inline content as label
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
  • max: number = undefined
    • Maximum value the slider can take
  • min: number = undefined
    • Minimum value the slider can take
  • step: number = undefined
    • Amount that value increments with smallest movement of the slider
  • value: number = undefined
    • Initial value of the slider
Example
<decidables-slider disabled max="0" min="100" step="2" value="50">
  Move me
</decidables-slider>

DecidablesSpinner / <decidables-spinner>

Text field w/spinner arrows for selecting a continuous numeric value

Slots
  • unnamed
    • Inline content as label
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
  • max: number = undefined
    • Maximum value the slider can take
  • min: number = undefined
    • Minimum value the slider can take
  • step: number = undefined
    • Amount that value increments with smallest movement of the slider
  • value: number = undefined
    • Initial value of the slider
Example
<decidables-spinner disabled max="0" min="100" step="2" value="50">
  Change me
</decidables-spinner>

DecidablesSwitch / <decidables-switch>

Switch for turning an option on or off

Slots
  • unnamed
    • Inline content as label for on state
  • off-label
    • Inline content as label for off state
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
  • checked: number = false
    • Whether the switch is on (true) or off (false)
Example
<decidables-switch disabled checked>
  <span>On</span>
  <span slot="off-label">Off</span>
</decidables-switch>

DecidablesToggleOption / <decidables-toggle-option>

One option in a toggle set

Slots
  • unnamed
    • Inline content as label for option
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
  • checked: number = false
    • Whether the option is selected (true) or not ('false`)
  • name: string = undefined
    • An identifier to be shared by all options in a mutually exclusive group
  • value: string = undefined
    • An identifier specific to this option to uniquely identify it in the group
Example
<decidables-toggle-option disabled name="flavors" value="chocolate" checked>
  Chocolate
</decidables-toggle-option>

DecidablesToggle / <decidables-toggle>

Toggle for selecting one option from a set

Slots
  • unnamed
    • Inline content as label for set
  • label
    • Inline content as legend for options
Attributes
  • disabled: boolean = false
    • In disabled state user can't interact
Example
<decidables-toggle disabled>
  <span>Pick one</span>
  <span slot="label">Flavors</span>
  <decidables-toggle-option disabled name="flavors" value="chocolate">
    Chocolate
  </decidables-toggle-option>
  <decidables-toggle-option disabled name="flavors" value="strawberry">
    Strawberry
  </decidables-toggle-option>
  <decidables-toggle-option disabled name="flavors" value="vanilla" checked>
    Vanilla
  </decidables-toggle-option>
</decidables-toggle>

Base class

DecidablesElement

Base class for all decidables web components

To define a new element:

export default class DecidablesSomething extends DecidablesElement {
  ...
}

This library is built on Lit, so the resulting DecidableElement is also a LitElement

Utilities

DecidablesConverterArray

Utility for attributes that can take an array of values

If you are defining a DecidablesElement with an attribute that can take an array of numbers, then you can use this to automatically convert between a space-separated list as the attribute and an Array of numbers as the property:

static get properties() {
  return {
    stuff: {
      attribute: 'values',
      converter: DecidablesConverterArray,
      reflect: true,
    },
  };
};
<decidables-something values="1.23 3.56 -2.97"></decidables-something>

And this.values will be the Array: [1.23 3.56 -2.97]

DecidablesConverterSet

Utility for attributes that can take a set of values

If you are defining a DecidablesElement with an attribute that can take a set of string values, then you can use this to automatically convert between a space-separated list as the attribute and a Set of strings as the property:

static get properties() {
  return {
    stuff: {
      attribute: 'stuff',
      converter: DecidablesConverterSet,
      reflect: true,
    },
  };
};
<decidables-something stuff="this that other"></decidables-something>

And this.stuff will be a Set with members: 'this', 'that', and 'other'

Development

Features/Bugs/Notes

  • Custom spinner that looks better than User Agent spinners?
  • Edge/IE11 - slider shadow is clipped
  • Edge/IE11 - no arrows for numeric controls
  • Firefox - spinner arrows look ugly and asymmetrical
  • IE11 - No CSS variables outside custom elements (and not patched by ShadyCSS!)

Package Scripts

  • yarn lint
    • Lints markdown, scripts and styles
  • yarn test
    • Runs all tests and reports coverage in test/coverage/
  • yarn test:watch
    • Runs all tests in watch mode and reports coverage in test/coverage/
  • yarn test:file <filename>
    • Runs tests for a single file and reports coverage in test/coverage/
  • yarn build
    • Builds bundles from src/ to lib/

File Organization

  • decidables-elements/
    • lib/ (Bundles created from src/ by build) [autogenerated]
    • src/ (Source files)
    • test/ (Testing files)
      • coverage/ (Code coverage results) [autogenerated]
    • CHANGELOG.md (Based on conventional commits) [autogenerated]
    • gulpfile.js (Tasks for gulp)
    • package.json (Package config for yarn and npm)
    • README.md (This file)
    • rollup-stats.html (Report on js bundle composition and size) [autogenerated]

License

The content of this project is licensed under Creative Commons Attribution-ShareAlike 4.0 International License (CC-BY-SA-4.0) and the source code of this project is licensed under GNU General Public License v3.0 or any later version (GPL-3.0-or-later).