JSPM

  • Created
  • Published
  • Downloads 180943
  • Score
    100M100P100Q165516F
  • License MIT

A Simple Web Component library

Package Exports

  • kapsule

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (kapsule) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Kapsule

A Simple Web Component library, inspired by the reusable charts pattern commonly found in D3 components.

NPM

Quick start

import Kapsule from 'kapsule';

or

var Kapsule = require('kapsule');

or even

<script src="//unpkg.com/kapsule/dist/kapsule.min.js"></script>

Usage example

Define the component

const ColoredText = Kapsule({
    
    props: {
        color: { default: 'red' },
        text: {}
    },
    
    init: (domElement, state) => {
        state.elem = document.createElement('span');
        domElement.appendChild(state.elem);
    },
    
    update: state => {
        state.elem.style.color = state.color;
        state.elem.textContent = state.text;
    }

});

Instantiate the component

let myText = ColoredText();

Render

myText(<myDOMElement>)
    .color('blue')
    .text('foo');

How to build

npm install
npm run build