dom-widget

Sugar to create a widget

npm install dom-widget
2 downloads in the last week
8 downloads in the last month

dom-widget

browser support

Sugar to create a widget

Example

A widget in this case is a combination of a HTML string and an JavaScript implementation.

Widget returns a function which when called will create a new elements hash from unpack-html using the given HTML template and pass it to you.

The value you return will be passed through but if it doesn't have a view property then a view property will be set to be elements.root

var events = require("dom-reduce/event")
var fold = require("reducers/fold")
var document = require("global-scope/document")
var console = require("console")

var Widget = require("dom-widget")

var html = "<div><input data-marker='foo' /></div>"

var widget = Widget(html, function (elements, data) {
    console.log("args", arguments)
    elements.foo.value = data

    return events(elements.foo, "keypress")
})

var item = widget("hello world")
document.body.appendChild(item.view)

fold(item, function (event) {
    console.log("keypress events", event)
    // keypress events
})

Installation

npm install dom-widget

Contributors

  • Raynos

MIT Licenced

npm loves you