All Projects → queckezz → Elementx

queckezz / Elementx

Licence: mit
⚡️ Functionally create DOM elements and compose them to a tree quickly

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Elementx

Nanohtml
🐉 HTML template strings for the Browser with support for Server Side Rendering in Node.
Stars: ✭ 651 (+950%)
Mutual labels:  element, frontend, dom
React Svg
🎨 A React component that injects SVG into the DOM.
Stars: ✭ 536 (+764.52%)
Mutual labels:  svg, dom
Imba
🐤 The friendly full-stack language
Stars: ✭ 5,434 (+8664.52%)
Mutual labels:  frontend, dom
Html To Image
✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
Stars: ✭ 595 (+859.68%)
Mutual labels:  svg, dom
Snuggsi
snuggsi ツ - Easy Custom Elements in ~1kB
Stars: ✭ 288 (+364.52%)
Mutual labels:  frontend, dom
Plain Draggable
The simple and high performance library to allow HTML/SVG element to be dragged.
Stars: ✭ 362 (+483.87%)
Mutual labels:  svg, dom
Displayjs
A simple JavaScript framework for building ambitious UIs 😊
Stars: ✭ 590 (+851.61%)
Mutual labels:  frontend, dom
Elemental2
Type checked access to browser APIs for Java code.
Stars: ✭ 115 (+85.48%)
Mutual labels:  svg, dom
Svg
Fork of the ms svg library (http://svg.codeplex.com/)
Stars: ✭ 676 (+990.32%)
Mutual labels:  svg, dom
Sinuous
🧬 Light, fast, reactive UI library
Stars: ✭ 740 (+1093.55%)
Mutual labels:  functional, dom
Zeroclipboard
The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
Stars: ✭ 6,650 (+10625.81%)
Mutual labels:  frontend, dom
ready
Detect element availability on the initial page load and those dynamically appended to the DOM
Stars: ✭ 77 (+24.19%)
Mutual labels:  dom, element
Lunasvg
A standalone c++ library to create, animate, manipulate and render SVG files.
Stars: ✭ 243 (+291.94%)
Mutual labels:  svg, dom
Ply
CSS inspection aided by visual regression pruning
Stars: ✭ 370 (+496.77%)
Mutual labels:  frontend, dom
Svgdom
Straightforward DOM implementation to make SVG.js run headless on Node.js
Stars: ✭ 154 (+148.39%)
Mutual labels:  svg, dom
React Svg Pan Zoom
👀 A React component that adds pan and zoom features to SVG
Stars: ✭ 569 (+817.74%)
Mutual labels:  svg, frontend
Omatsuri
PWA with 12 open source frontend focused tools
Stars: ✭ 1,131 (+1724.19%)
Mutual labels:  svg, frontend
Dom To Svg
Library to convert a given HTML DOM node into an accessible SVG "screenshot".
Stars: ✭ 67 (+8.06%)
Mutual labels:  svg, dom
Dompurify
DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
Stars: ✭ 8,177 (+13088.71%)
Mutual labels:  svg, dom
Crab
JavaScript library for building user interfaces with Custom Elements, Shadow DOM and React like API
Stars: ✭ 22 (-64.52%)
Mutual labels:  frontend, dom

logo

​⚡️​ Create complex DOM elements/trees using a functional approach.

npm version build status test coverage dependency status license js standard style downloads per month

This module provides an alternative to JSX or template strings for those who want to build up their DOM trees using plain function composition.

const { div, h1, h2, button, ul, li } = require('elementx')

div(
  h1({ class: 'bold' }, 'elementx'),
  h2({ id: 'subtitle' }, 'Create a DOM tree with ease'),
  button({ href: 'http://ghub.io/elementx' }, 'Open'),
  ul(
    ['simple', 'functional', 'fast']
      .map(key => li(key))
  )
)

Features

  • Universal - Works in Node and Browser
  • SVG Support - Supports creating SVG Elements
  • Functional - Since it's just function composition we can arbitrarily compose them
  • Small Only 1.99 kB minified and gzipped
  • Interoperability Can be used with diffing libraries like morphdom, nanomorph or anyhting that uses the DOM

Installation

> npm install elementx

Example

const { div, h1, a } = require('elementx')

const node = div(
  h1({ class: 'title' }, 'This is a title'),
  div({ class: 'bg-red' },
    a({ href: 'http://github.com' }, 'Github')
  )
)

// mount the tree to the DOM
document.body.appendChild(node)

console.log(tree.outerHTML)
/*
 * ->
 * <div class="title">
 *   <h1>This is a title</h1>
 *   <div class="bg-red">
 *     <a href="http://github.com">Github</a>
 *   </div>
 * </div>
 */

Getting Started

Each HTML tag is exposed as a function when requiring elementx.

// using destructuring
const { div, h1, p, button } = require('elementx')

These functions have the following syntax:

tag(tagName, attributes, children)

All arguments are optional with at least one argument needing to be present. This kind of function overloading allows you to iterate on your DOM structure really fast and reduce visual noise.

  • tagName any valid html tag
  • attributes is an object of dom attributes: { href: '#header' }
  • children can be a string for a text node or an array of nodes

Lifecycle hooks

This module aims to be just the element creation layer. It can be used with any view framework using DOM as their base element abstraction for diffing. Some libraries like this include choo or inu.

SVG

SVG works as expected. Sets the appropriate namespace for both elements and attributes. All SVG tags can only be created with the h-helper:

const { svg } = require('elementx')

const node = svg({
  viewBox: '0 0 0 32 32',
  fill: 'currentColor',
  height: '32px',
  width: '32px'
}, [
  h('use', { 'xlink:href': '#my-id' })
])

document.body.appendChild(node)

Use without helper functions

Sometimes you need to fall back to the traditional createElement(tag, attributes, children) (aliased to h), for example svg tags.

const h = require('elementx')

const node = h('h1', 'text')

console.log(node.outerHTML)
/*
 * ->
 * <h1>text</h1>
 */

Events

All HTML DOM Events can be attached. The casing of the event name doesn't matter (onClick, onclick, ONCLICK etc.)

const node = h.button({
  onClick: () => console.log('button has been clicked')
})

document.body.appendChild(node)

External tools

Tests

> npm test

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].