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

synergy-web-components

v0.0.1

Published

Simple web components using plain objects and factory functions

Downloads

6

Readme

synergy-web-components

npm Build Status Coverage Status gzip size

Synergy-web-components is a lightweight wrapper around the Synergy library, allowing you to create reusable Custom Elements with declarative templates and reactive data bindings using plain objects and factory functions.

Browser Support

Works in any modern browser that supports JavaScript Proxy.

Install

Using npm:

$ npm i synergy-web-components

Using unpkg CDN:

<script type="module">
  import define from 'https://unpkg.com/[email protected]';
</script>

Define

The define() function registers your Custom Element.

Syntax

define(tagName, factory, template);

Parameters

  • tagName Name for the new custom element. Note that custom element names must contain a hyphen.

  • factory A Factory function that returns a plain JavaScript object that will provide the data for your element.

  • template (optional) Either an HTML string or a <template> element. If ommited, Elementary expects your document to include a Template element with an id matching tagName.

Example

<script type="module">
  import define from 'https://unpkg.com/[email protected]';

  let count = 0;

  const factory = ({ expanded = false, title, disabled = false }) => {
    return {
      id: `drawer-${count++}`,
      title,
      expanded,
      disabled,
      toggle() {
        this.expanded = !this.expanded;
      },
    };
  };

  factory.observedAttributes = ['expanded'];

  define('x-drawer', factory);
</script>
<template id="x-drawer">
  <style scoped>
    button {
      all: inherit;
    }
  </style>
  <h3>
    <button
      id="{{ id }}"
      disabled="{{ disabled }}"
      aria-expanded="{{ expanded }}"
      onclick="toggle"
    >
      {{ title }}
    </button>
  </h3>
  <div hidden="{{ !expanded }}" aria-labelledby="{{ id }}">
    <slot></slot>
  </div>
</template>

In the example above, we create a new x-drawer Custom Element that can be used anywhere on the page, like so...

<x-drawer title="foo"></x-drawer>

Factory Props

The elements initial attribute keys and values will be passed to your factory function during initialisation

Observed Attributes

Observed attributes can be declared directly on your factory function like so...

const factory = (props) => props;

factory.observedAttributes = ['name'];

Shadow Dom

SWC doesn't support Shadow DOM at the moment. This is to preserve the pre-rendering / hydration capabilities of Synergy. There are open proposals for the Web Platform that intend to make Shadow DOM declarative and serialisable. Until then, SWC provides a polyfill for Slots, as well as a limited CSS scoping mechanism.

Slots

Elementary doesn't support Shadow DOM, but it does polyfill (slots)[https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot], so you can use these as per the spec to provide placeholders for custom markup.

Scoped CSS

Elementary provides lightweight, opt-in CSS scoping. Apply the scoped boolean attribute to a style tag within your Custom Elements template, and all of the selectors will be prefixed with an additional type selector and hoisted up into the document head, giving you one style tag shared between all instances. This effectively stops your Custom Element styles from leaking out into the document, but doesn't stop anything from sneaking in.