0.17.3 • Published 2 years ago

hyperchain v0.17.3

Weekly downloads
90
License
-
Repository
github
Last release
2 years ago

hyperchain

npm

hyperscript-like DOM builder with chaining, composition, and reusability. Inspired by hyperscript-helpers.

Features

Note: Uses ES6 features (Proxy, Tagged Template Literals), use only where browser/env supports it.

Install

npm i hyperchain

Usage

import { createElement } from 'react'
import hyperchain from 'hyperchain'
const h = hyperchain(createElement, opts)
// or with helpers (available: react, preact)
const h =  require('hyperchain/react')(opts)
const h =  require('hyperchain/preact')(opts)
h.div('hi')          // => <div> hi </div>
h.span('hi')         // => <span> hi </span>
h.p('a', 'b')        // => <p> a b </p>
h.span`hi`           // => <span> hi </span>
h.div({attr:'a'})    // => <div attr="a"></div>
h.div.class('a')     // => <div class="class"> a </div>
h.div.class`a`       // => <div class="class"> a </div>
h.div.some.class()   // => <div class="some class">
h.div.someClass()    // => <div class="someClass">
h.div.someClass()    // => <div class="some-class">   (opts.dashifyClassnames: true)
h.div()              // => <div class="div">          (opts.tagClass: true)
h.div.CSS()          // => <div class="MODULES">      (opts.style: {CSS:'MODULES'})
h.div(1, 0, null, 2) // => <div> 1 2 </div>           (opts.filterFalseyChildren: true)
h.div['#id']()       // => <div id="id"></div>

API

hyperchain(createElement, options)
  • createElement [function] JSX/hyperscript reviver function
  • options [object]

    • style [object] Uses CSS Modules-compatible styles object to add appropriate classnames. See hyperstyles
    • stylePreserveNames [boolean] Preserves original classnames in addition to CSS Module names replaced by opts.style
    • styleOmitUnused [boolean] Omits classes from elements that aren't listed in opts.style
    • dashifyClassnames [boolean] Turns .className to class-name
    • tagClass [boolean] Adds tag-name as an additional class-name (which is also opts.style aware)
    • filterFalseyChildren [boolean] Filters out falsey children
    • elementMapMap [object] Map tagNames or components to something else
    • keyMap [object] Map keys/attrs to something else
h.tagName[...className]`innerText`
h.tagName[...className](...children)
h.tagName[...className]({...props}, ...children)
  • tagName [string] Tag name to use, eg. .div
  • className [string] Class name to use, eg. .someClass
  • children [array] Child nodes
  • props [object] Attributes to set as an object, eg. {id: …}
0.17.2

2 years ago

0.17.3

2 years ago

0.17.1

2 years ago

0.16.0

4 years ago

0.17.0

4 years ago

0.15.4

4 years ago

0.15.3

5 years ago

0.15.2

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.2

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.2

6 years ago

0.5.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago