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

haunted-lit-element

v0.1.3

Published

A missing connection between LitElement and Haunted

Downloads

71

Readme

Haunted Lit Element

Build Status npm size downloads

A missing connection between Haunted and LitElement.

It makes it possible to use LitElement's features like properties and styles in Haunted.

This project follows the open-wc recommendation.

Installation

npm i haunted-lit-element

Usage

This library provides component function that is made in the way as it is in Haunted.

component(MyEl)

Similar to haunted but the base class is LitElement:

import {html} from 'lit-html';
import {component} from 'haunted-lit-element';
window.customElements.define('my-el', component(() => html`hello world`));

component(MyEl, optsOrBaseCls)

The second parameter in component function can be options or a base class which should be derived from HauntedLitElement.

The options in most cases are properties and styles from LitElement. But it can actually be anything as at the end it is just a static field in the base class. It is done in that way because there are LitElement extensions that use similar approach with their own configuration.

Example of defining options as second argument:

import {css} from 'lit-element';
import {component} from 'haunted-lit-element';

const MyEl = () => { /*...*/ };

const properties = {myParam: {type: String}, /*...*/};
const styles = css`/* my css styles */`;

window.customElements.define('my-el', component(MyEl, {properties, styles}));

Example of defining base class as second argument:

import {component, HauntedLitElement} from 'haunted-lit-element';

class MyExtHauntedLitElement extends HauntedLitElement {
    // ... my own stuff
}

const MyEl = () => { /*...*/ };

window.customElements.define('my-el', component(MyEl, MyExtHauntedLitElement));

component(myEl, baseCls, opts)

If you want to use options and a base class than the base class is the second argument and options are the third.

Example of using LitElement's properties and styles helper with a custom base class.

<my-el
  mystring="hello world"
  mynumber="5"
  mybool
  myobj='{"stuff":"hi"}'
  myarray='[1,2,3,4]'
></my-el>


<script type="module">
    import {useState} from "haunted";
    import {css, html} from "lit-element";
    import {component, HauntedLitElement} from "haunted-lit-element";

    class MyExtLitElement extends HauntedLitElement {
        // ... my own stuff
    }

    const renderer = ({mystring, mynumber, mybool, myobj, myarray}) => {
        const [count, setCount] = useState(0);
        return html`
            <p>${count}</p>
            <button @click=${() => setCount(count + 1)}>+</button>
            <pre>
                typeof mystring = ${typeof mystring}
                typeof mynumber = ${typeof mynumber}
                typeof mybool = ${typeof mybool}
                typeof myobj = ${typeof myobj}
                Array.isArray(myarray) = ${Array.isArray(myarray)}
            </pre>`;
    };

    /** LitElement's Properties */
    const properties = {
        mystring: {type: String},
        mynumber: {type: Number},
        mybool: {type: Boolean},
        myobj: {type: Object},
        myarray: {type: Array}
    };
    /** LitElement's css helper function */
    const styles = css`p {color:red}`;
    window.customElements.define('my-el', component(renderer, {properties, styles}, MyExtLitElement));
</script>

The output for properties is going to be:

typeof mystring = string
typeof mynumber = number
typeof mybool = boolean
typeof myobj = object
Array.isArray(myarray) = true

Testing using karma

npm run test

Linting

npm run lint