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

@rapid-build-ui/base

v0.0.12

Published

Rapid Build UI Web Components Base Mixin

Downloads

26

Readme

Rapid Build UI · Web Components · Base Mixin

Base mixin for all <rb-components>.

This is not a web component.
It is an internal module for all our web components.
Our consumable web components are prefixed with "rb-" example rb-button.

Installation

$ yarn add @rapid-build-ui/base

What's Included

How To Use

/* Example
 **********/
import { RbBase, props, html } from '../../base/scripts/base.js';
import View                    from '../../base/scripts/public/view/directives.js';
import template                from '../views/rb-popover.html';

export class RbPopover extends RbBase() {
	// Lifecycle
	viewReady() { // :void
		super.viewReady && super.viewReady(); // line required
		this.rb.elms.trigger = this.shadowRoot.querySelector('.trigger');
		this.rb.events.add(this.rb.elms.trigger, 'click touchstart', this.toggle);
	}
	// Event Handler
	toggle(e) { // :void
		this.showPopover = !this.showPopover;
	}
	// Template
	render({ props, state }) { // :string
		return html template;
	}
}

API

this.rb.elms

this.rb.events

  • Properties
    • events :object (readonly, hashmap of active events)
  • Methods
    • add(elm(s), 'space separated events', callback[, opts]) :void
      • events are automatically removed in disconnectedCallback()
        • meaning, you don't have to call remove() or removeAll()
      • opts :{}
        • default options
        • opts.bind (custom):
          • undefined (binds to component, default)
          • false | null (binds to target elm)
          • elm (binds to supplied elm)
    • emit(elm, 'event' [, { detail: any } ]) :boolean
    • remove(elm(s), 'space separated events', callback) :void
    • removeAll([opts]) :void
      • opts :{}
        • opts.force (internal option) :boolean
          • forces events to be set to empty {}

this.rb.events.host

  • Properties
    • events :object (readonly, hashmap of active host events)
  • Methods
    • add([event types]) :void
      • usually ran in component constructor
      • event types example: ['click', 'focus']
      • examples:
        • this.rb.events.host.add(['click']);
        • this.rb.events.add(this, 'click', this.rb.events.host.run);
    • remove([event types]) :void
      • event types example: ['click', 'focus']
    • removeAll() :void
    • run(event) :any (event :object | string)
      • runs event that was added via add()
      • supports promises (see isPending())
      • example: this.rb.events.host.run(event)
    • isPending(event) :boolean (event :object | string)
      • returns true if function returned a promise and it's pending

this.rb.view

  • Properties
    • isReady :boolean (readonly, will be true when view is ready)

Callbacks (optional)

viewReady()

See how to use...
Executed once when view is ready and all its rb sub components views are ready.
Use when you need to make sure elements are accessible in the shadow dom.

Imports (optional)

guid service

  • Methods
    • create(maxLength = 12) :string (sometimes returns maxLength - 1 chars)
// Example
import Guid from '../../base/scripts/public/services/guid.js';
const guid = Guid.create();

property converters

All methods convert the attribute's value to a type and returns it.
The first param is the attribute's value which is always a string.

  • Methods
    • boolean(val) :boolean
    • valueless(val) :boolean
// Example
import Converter from from '../../base/scripts/public/props/converters.js';
class RbIcon {
	static get props() {
		return {
			spin: Object.assign({}, props.boolean, {
				deserialize: Converter.valueless
			})
		};
	}
}

type service

  • Methods (is.methods() :boolean)
    • get(val) :string (returns val type)
    • is.array(val)
    • is.boolean(val)
    • is.function(val)
    • is.int(val)
    • is.null(val)
    • is.number(val)
    • is.object(val)
    • is.promise(val)
    • is.string(val)
    • is.stringArray(val)
    • is.undefined(val)
// Example
import Type from '../../base/scripts/public/services/type.js';
const isString = Type.is.string('rapid');

view directives

Returns an object of lit-html directives to be used in view.

// Example
import View from '../../base/scripts/public/view/directives.js';
<!-- Example (import View object in js, see "How To Use"): -->
<ul>
	${View.repeat(
		['hulk','thor'],
		(hero, i) => html`<li>${i} ${hero}</li>`
	)}
</ul>

Slot Mixin

Adds helpers onto this for working with slots.

  • Constructor

    • sets this.state.slots = {}
      • Which can be used for conditionals in the view.
  • Getters

    • this._hasLightDom :boolean (readonly)

    • this._lightDomSlotNames :{ [slotName]: boolean } (readonly)

      • An object/hashmap with the names of all the light dom slot names.
  • Methods

    • this._initSlotStates() :void

      • Run in viewReady().
      • Runs this._setSlotStates(this._lightDomSlotNames).
    • this._cleanLightDomWhitespace() :void

      • Mutates this.childNodes.
    • this._setSlotStates(slotNames={}) :void

      • Mutates this.state.slots.