🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@browserkids/web-components

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@browserkids/web-components

Non-transpiled ES13+ web components helper functions.

latest
Source
npmnpm
Version
0.8.0
Version published
Weekly downloads
6
-14.29%
Maintainers
1
Weekly downloads
 
Created
Source

@browserkids/web-components

npm version Known Vulnerabilities Build Status Dependency Status

This is a collection of useful web components helper functions. They are all written in latest/cutting edge ECMAScript 2022 code and are not transpiled.


Installation

Using a CDN

Fastest way to get going. See for yourself:

<script type="module">
import { define } from 'https://unpkg.com/@browserkids/web-components';

define(class MyElement extends HTMLElement {
  /* Your custom element logic. */
});
</script>

Using a bundler

Semi-fast way as well. Just install it via npm.

npm install -S @browserkids/web-components

Import the functions where you need them.

import { define } from '@browserkids/web-components';

Browser support

Almost every function uses at least one feature of ECMAScript 2022 , but no ESNext features — promised. So support should be fine for “evergreen” browsers at the time of writing. This means that Internet Explorer is out of the game.

As this library is not transpiled nor ever will be, you should use polyfills in case you need to support a specific browser version.


API

  • define(elementConstructor)

    The define() helper function registers a custom element constructor to the CustomElementRegistry. To reduce redundant tasks like creating a ShadowDOM, binding attributes, setting up event listeners or fetching DOM references, the given element constructor will be extended and enhanced to have a consistent developing experience.

    <my-element></my-element>
    
    <script type="module">
      import { define } from 'https://unpkg.com/@browserkids/web-components';
    
      define(class MyElement extends HTMLElement {
      // By default define() uses the class name as element name, 
      // you can override this by defining a custom name.
      static name = 'my-element';
    
      // You can define a static settings field to override the settings 
      // for the individual functions that define() is using.
      static settings = {
        bindAttributes: {},
        bindEventListeners: {},
        createShadowRoot: {},
        findReferences: {},
      };
      
      // Will be used by bindAttributes and turns into a proxy object.
      data = {};
    
      // Will be used by createShadowRoot for shadow dom creation.
      template = '';
      
      // Will be called once the element has been inserted to the DOM,
      // and the constructor of that class has finished.
      ready() {}
    });
    
    </script>
    

Keywords

web-components

FAQs

Package last updated on 01 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts