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

jsx-for-web-components

v1.2.1

Published

[![Build Status](https://travis-ci.com/slogsdon/jsx-for-web-components.svg?branch=master)](https://travis-ci.com/slogsdon/jsx-for-web-components)

Downloads

2,623

Readme

jsx-for-web-components

Build Status

WIP: A basic JSX factory for use in projects leveraging web components

Features

Requirements

  • Compiler that can convert JSX to JSX factory JavaScript calls

Installation

yarn add jsx-for-web-components

Getting Started

We'll use TypeScript and Rollup to build for the browser. Let's start with pulling in some dependencies:

yarn add --dev typescript rollup rollup-plugin-node-resolve rollup-plugin-typescript2

A couple configuration files to help the project build correctly:

./tsconfig.json

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "h",
    "moduleResolution": "node",
    "target": "es2015"
  }
}

./rollup.config.js

import resolve from "rollup-plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";

export default {
  input: "./src/index.tsx",
  output: {
    file: "./dist/index.js",
    format: "iife",
  },
  plugins: [
    resolve({
      extensions: [ '.js', '.ts', '.tsx' ],
    }),
    typescript({
      typescript: require("typescript"),
    }),
  ],
};

Define your custom element:

./src/index.tsx

import { h, JSXCustomElement } from "jsx-for-web-components";

class ExampleElement extends JSXCustomElement {
  static elementName = "example-element";

  public render() {
    return <div id="testing">hello</div>;
  }
}

ExampleElement.register();

Leverage your custom element:

./index.html

<!DOCTYPE html>
<script src="/dist/index.js" defer></script>
<example-element></example-element>

After building the project with rollup -c rollup.config.js, you should be able to load your HTML in a browser to see your work.

Notes

connectedCallback

While there is some setup performed within the constructor of JSXCustomElement, the DOM nodes defined by your render method are not attached until the connectedCallback method is called. If you need to leverage this callback within your code, be sure to call the super method, e.g.:

class ExampleElement extends JSXCustomElement {
  // ...
  public connectedCallback() {
    super.connectedCallback();

    // your code
  }
}

License

This project is licensed under the MIT License. See LICENSE for details.