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

@brightspace-ui/polymer-behaviors

v4.0.0

Published

Shared Polymer behaviors for use in web components

Downloads

4,823

Readme

@brightspace-ui/polymer-behaviors

Shared Polymer-based behaviors and modules for implementing and consuming web components.

Installation

Install from NPM:

npm install @brightspace-ui/polymer-behaviors

Usage

Methods

D2L.Dom

// returns null or the closest ancestor that fulfills the specified predicate fxn
D2L.Dom.findComposedAncestor(node, predicate);

// gets the composed children (including shadow children & distributed children)
D2L.Dom.getComposedChildren(element);

// gets the composed parent (including shadow host & insertion points)
D2L.Dom.getComposedParent(node);

// returns true/false whether the specified ancestorNode is an ancestor of node
D2L.Dom.isComposedAncestor(ancestorNode, node);

// browser consistent implementation of HTMLElement.offsetParent
D2L.Dom.getOffsetParent(node);

D2L.Dom.Focus

// get the composed active element (i.e. the actual element that has focus)
D2L.Dom.Focus.getComposedActiveElement();

// get first focusable child or descendant
D2L.Dom.Focus.getFirstFocusableDescendant(element);

// get last focusable child or descendant
D2L.Dom.Focus.getLastFocusableDescendant(element);

// get the next focusable child, sibling, etc.
D2L.Dom.Focus.getNextFocusable(element);

// get the previous focusable child, sibling, etc.
D2L.Dom.Focus.getPreviousFocusable(element);

// get the nearest focusable ancestor
D2L.Dom.Focus.getPreviousFocusableAncestor(element);

// check is focusable (tabindex or white-listed elements)
D2L.Dom.Focus.isFocusable(element);

D2L.Dom.Visibility

// checks DOM visibility (includes inline & computed style of element and ancestors)
// ... does not check opacity, elements hidden due to overflow or scrolled out of view
D2L.Dom.Visibility.isVisible(element);

D2L.Id

// gets a unique indexed id (for lifetime of page)
D2L.Id.getUniqueId();

Behaviors

D2L.PolymerBehaviors.FocusableArrowKeysBehavior

The FocusableArrowKeysBehavior can be used for managing focus with the arrow keys.

  • right/down - focuses next element, or first if currently at the end
  • left/up - focuses previous element, or last if currently at beginning
  • home - focuses first
  • end - focuses last

// include the behavior
behaviors: [
  D2L.PolymerBehaviors.FocusableArrowKeysBehavior
],

attached: function() {
  Polymer.RenderStatus.afterNextRender(this, function() {

    // indicate the direction (default is leftright)
    this.arrowKeyFocusablesDirection = 'updown';

    // required container element of focusables (used to listen for key events)
    this.arrowKeyFocusablesContainer = container;

    // required provider method that can return list of focusables - possible async
    this.arrowKeyFocusablesProvider = function() {

      // simple case
      return Promise.resolve(focusables);

      // other cases (ex. check visibility when querying focusables)
      return new Promise(function(resolve) {
        fastdom.measure(function() {
          // ...
          resolve(focusables);
        });
      });

    };

    // optional callback before focus is applied
    this.arrowKeyFocusablesOnBeforeFocus = function(elem) {
        return new Promise(function(resolve) {
            // do some stuff
            resolve();
        });
    };

  });
}

D2L.PolymerBehaviors.VisibleOnAncestorBehavior

The VisibleOnAncestorBehavior can be used to show an element when a specified ancestor is being hovered, or a child of the ancestor has the focus. Likewise, the element will be hidden if the specified ancestor is not being hovered and none of its children have the focus. To define a component with this behavior, simply include the styles and behavior as shown in the example below.

<dom-module id="d2l-example">
  <template>
    <style include="d2l-visible-on-ancestor-styles"></style>
  </template>
  <script>
  Polymer({
    is: 'd2l-example',
    behaviors: [
      D2L.PolymerBehaviors.VisibleOnAncestorBehavior
    ]
  });
  </script>
</dom-module>

The consumer of d2l-example adds the d2l-visible-on-ancestor-target class to the desired ancestor that will be the target for mouse and focus events. If the user hovers the target, or focuses any element contained within, d2l-example will be displayed.

<div class="d2l-visible-on-ancestor-target">
  ...
  <d2l-example visible-on-ancestor></d2l-example>
  ...
</div>

Versioning and Releasing

This repo is configured to use semantic-release. Commits prefixed with fix: and feat: will trigger patch and minor releases when merged to main.

To learn how to create major releases and release from maintenance branches, refer to the semantic-release GitHub Action documentation.