0.1.6 • Published 8 months ago

@web-companions/lit v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

A @web-companions/gfc preset for creating element and node Views with lit-html render.

This package is useful for creating views – HTML Elements and Nodes. It's possible to develop any UI components. This package uses lit-html render under the hood.


Table of contents


Installation

npm install @web-companions/lit --save

Usage

For better DX suggest using this library with babel-plugin-transform-jsx-to-tt.

index.jsx

import { litView } from '@web-companions/lit';

/**
 * Counter element
 */
export const counterElement = litView.element({
  props: {
    msg: p.req<string>(),
  },
})(function* (props) {
  let count = 0;

  while (true) {
    props = yield (
      <>
        <button
          type="button"
          onclick={() => {
            count++;
            this.next();
          }}
        >
          {props?.msg}
        </button>
        <i>{count}</i>
      </>
    );
  }
});

// define a new custom Counter element with tag 'demo-counter-element'
const CounterElement = counterElement('demo-counter-element');

/**
 * ROOT element
 */
litView.element({
  props: {
    header: p.req<string>('header'),
  },
})(function* (props) {
  while (true) {
    props = yield (
      <div
        style={css`
          margin: 10px;
        `}
      >
        <h3>{props.header}</h3>

        <CounterElement msg={'Counter Element'}></CounterElement>
      </div>
    );
  }
})('demo-fc');

More examples are here.


MIT License

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

12 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.1.0-develop.0

1 year ago