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

simple-component-v0

v1.0.2

Published

Helper functions for creating simple web components

Downloads

3

Readme

simpleComponent

Helps you make stateless web components that serve visual purposes only, e.g. a "bold-gold" element.

<bold-gold>Gold diggin'</bold-gold>

Here's how a browser would render it.

bold and gold text

Deprecated!

Use easy-element instead.

Usage

We can easily define our <bold-gold> web component with a <template> and the simpleComponent function.

The id of the template must be the same as the name of the web component we're registering, but with the suffix -template. Pass the name of the web component as the first argument to simpleComponent.

<template id="bold-gold-template">
  <style>
    bold-gold {
      background-color: black;
      color: gold;
      font-weight: bold;
    }
  </style>
</template>
<script>
  simpleComponent('bold-gold')
</script>

For something fancier, provide an object with lifecycle callbacks.

<template id="simple-hello-template">
  <p>Hello!</p>
</template>
<script>
simpleComponent('simple-hello', {
  createdCallback: function() {
    console.log('simple-hello instance created', this)
  }
})
</script>

Browser Support

This does not support slots, Shadow DOM, Shady DOM, style-scoping or anything fancy. We recommend styling simple components using a BEM-like approach to prevent styles from leaking out. See test/search-bar.css for an example.

For full browser support use simple-component-v0 alonside a dependency on webcomponents v0.

Installation

In package.json

"dependencies": {
  "webcomponentsjsv0": "git://github.com/webcomponents/webcomponentsjs.git#v0",
  "simple-component-v0": "^1.0.0"
}

Then install these, via yarn install and reference them in script tags.

<script src="node_modules/webcomponentsjsv0/webcomponents-lite.js"></script>
<script src="node_modules/simple-component-v0/index.js"></script>

Documancy

For more information, clone this repository. Start the server with yarn start then navigate to localhost:3007/docs in your browser.

Or see an even more complex (but still simple) example of a search-bar web component at localhost:3007/test.

Why?

Why does this even exist, if web components v1 is the hotness, and simple-component-v0 doesn't offer any features?

  • The v1 spec wants you to write a class for each web componenent. Should you support older browsers that don't know what a class is, what hoops are you willing to jump through to make that happen? Here's a Stack Overflow answer to that.
  • At the time of this writing Shadow DOM hasn't yet been implemented in all major browsers, and the polyfills for it are expensive.
  • Some developers want their components to easily inherit global styles. For instance, you may want all your web components to have have their text in the same font as you're using on the page. Again, what hoops do you want to jump through?
  • This works in code bases that use the web components v0 specification.
  • Some developers may find the <template> approach more attractive than JavaScript options.
  • Virtual DOM rendering engines, such as those in Elm, React, and Vue, create and discard HTMLElements flippantly, so there's a benefit to having some simple web components with low performance overhead.