New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ledge/jsx

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledge/jsx

Simple JSX implementation for working directly with HTML elements. Types included.

latest
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

@ledge/jsx test status

Simple JSX implementation for working directly with HTML elements. Types included.

Features

  • Full Custom Elements support
  • Full TypeScript support
  • Tiny footprint
    • Zero runtime dependencies
    • Zero virtualization overhead

Usage

import { h } from '@ledge/jsx';

let clickCounter = 0;
const jsxButton = <button id='native-onlick' class='btn btn-dark my-4'
	onclick={() => console.info(`Clicked ${++clickCounter} times`)}>
	Click Me
</button>;

jsxButton.click(); // "Clicked 1 times"
jsxButton.click(); // "Clicked 2 times"

class CustomElementExample extends HTMLElement {
	connectedCallback() {
		this.classList.add('lead');
	}
}

customElements.define('custom-element-example', CustomElementExample);

const jsxSection =
	<section class='card'>
		<h2>DOM in JSX</h2>
		<h3>Work directly with DOM elements using JSX's declarative syntax</h3>
		<custom-element-example>Custom Elements?</custom-element-example>
		<br />
		<CustomElementExample>Fully Supported!</CustomElementExample>
		<br />
		{jsxButton}
	</section>;

document.body.appendChild(jsxSection);

jsxSection.parentElement === document.body; // true
jsxButton.closest('.card') === jsxSection;  // true

TypeScript

The following configuration is required:

{
	"compilerOptions": {
		"lib": ["dom"],
		"jsx": "react",
		"jsxFactory": "h"
	}
}

By default, the assigned type will be HTMLElement. If you need the subtype, cast the expression:

const tpl = <template>{/** ... */}</template> as HTMLTemplateElement;
const tplClone = tpl.content.cloneNode(true); // ok

A global CustomElement interface is provided for working with Custom Elements:

// error without extending HTMLElement
class CustomElementExample extends HTMLElement implements CustomElement {
	// autocompletion & documentation for callbacks
	public connectedCallback() {
			// ...
	}
	// error on mistyped parameter
	public attributeChangedCallback(name: string) {
			// ...
	}
}

FAQs

Package last updated on 07 Jan 2021

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