1.0.0 • Published 8 years ago

h0 v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
8 years ago

h0

h0

Hyperminimal functional DOM element microlibrary

Build Status

Experimental

npm i h0

Basic usage

import h from 'h0'

const tree = h('div')({
  style: {
    padding: 32
  }
})(
  h('h1')('hello')
)

Creating element functions

const div = h('div')
const h1 = h('h1')
const a = h('a')

const tree = div(
  h1('hello'),
  a({ href: '/hello' })('hi')
)

Creating styled element functions

const h1 = h('h1')({
  style: {
    fontSize: 48,
    fontWeight: 500
  }
})

const tree = h1('hello')

API

h()

Function that returns an element creation function with the given tagname. The returned function accepts either a plain object to set attributes, or a string or child elements to return an element.

h('div')
// returns an element creation function
h('div')({ class: 'hi' })
// returns an element creation function with attributes
h('div')({ class: 'hi' })('hello')
// returns a DOM element with an id and text content
// <div class='hi'>hello</div>
h('div')({
  style: {
    color: 'blue'
  }
})('hello')
// Style objects are converted to strings
// <div style='color:blue'>hello</div>
h('div')('hello')
// returns a DOM element with text content
// <div>hello</div>
h('div')(
  h('h1')('hello')
)
// returns a DOM element with child element
// <div>
//   <h1>hello</h1>
// </div>

MIT License

1.0.0

8 years ago

1.0.0-beta.4

8 years ago

1.0.0-beta.3

8 years ago

1.0.0-beta.2

8 years ago

1.0.0-beta.1

8 years ago