All Projects â†’ bgotink â†’ lit-html-brackets

bgotink / lit-html-brackets

Licence: MIT license
🌈 Lit-html extension that uses a bracket syntax similar to Angular's template syntax.

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to lit-html-brackets

bui
‹b› Web components for creating applications – built by Blackstone Publishing using lit-html and lit-element
Stars: ✭ 29 (+61.11%)
Mutual labels:  lit-html
pwa-lit-template
A template for building Progressive Web Applications using Lit and Vaadin Router.
Stars: ✭ 159 (+783.33%)
Mutual labels:  lit-html
create-evergreen-app
Get up and running with an evergreen web application development stack designed by, and for, today's modern web.
Stars: ✭ 16 (-11.11%)
Mutual labels:  lit-html
Nanny-State
simple state management
Stars: ✭ 68 (+277.78%)
Mutual labels:  lit-html
MoleculeJS
A library for creating fast and reactive Custom Elements
Stars: ✭ 39 (+116.67%)
Mutual labels:  lit-html
districtr
A free, open-source web app for drawing districting plans.
Stars: ✭ 68 (+277.78%)
Mutual labels:  lit-html
highcharts-webcomponent
Highcharts Web Component usable with any Framework
Stars: ✭ 21 (+16.67%)
Mutual labels:  lit-html
lit-components
Moved to https://github.com/vaadin/component-mixins
Stars: ✭ 59 (+227.78%)
Mutual labels:  lit-html
effectiveweb.training
Repository for Effective Web Online Course / airhacks.io
Stars: ✭ 17 (-5.56%)
Mutual labels:  lit-html
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (+94.44%)
Mutual labels:  lit-html
Wired Elements
Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.
Stars: ✭ 8,848 (+49055.56%)
Mutual labels:  lit-html
pattern-library
AXA CH UI component library. Please share, comment, create issues and work with us!
Stars: ✭ 103 (+472.22%)
Mutual labels:  lit-html
emerald-web-framework
A open-source framework that makes it easy to build top quality components for high-performance financial applications
Stars: ✭ 80 (+344.44%)
Mutual labels:  lit-html
polymerx-cli
âš¡ Unlock the power of Polymer 3, Web Components and modern web tools.
Stars: ✭ 30 (+66.67%)
Mutual labels:  lit-html
lit-state
Simple shared app state management for LitElement.
Stars: ✭ 93 (+416.67%)
Mutual labels:  lit-html
awesome-lit
A curated list of awesome Lit resources.
Stars: ✭ 880 (+4788.89%)
Mutual labels:  lit-html
fuco
Functional Component like React, but for Web Components.
Stars: ✭ 71 (+294.44%)
Mutual labels:  lit-html
lit
Lit is a simple library for building fast, lightweight web components.
Stars: ✭ 12,406 (+68822.22%)
Mutual labels:  lit-html
bce.design
minimal magic, minimal tooling, essential dependencies, high productivity, no transpilations and no migrations. The Web Components starter ships with integrated lit-html, redux-toolkit and vaadin router components.
Stars: ✭ 67 (+272.22%)
Mutual labels:  lit-html
tailwind-layouts
Collection of Tailwind Layouts
Stars: ✭ 53 (+194.44%)
Mutual labels:  lit-html

lit-html-brackets

Extension to lit-html that supports a syntax using brackets, similar to Angular's templates.

Build status

Overview

const template = ({ isAuthenticated, login, logout, options, refs }) => html`
  <label>
    <input #rememberMe=${refs} type="checkbox" [(checked::change)]=${bind(options, 'rememberMe')}>
    Remember me?
  </label>

  <button #=${bind(refs, 'loginButton')}
    class="login-cta" [class.login-cta--logged-on]=${isAuthenticated}
    (click)="${isAuthenticated ? logout : login}" (keyup.enter)=${isAuthenticated ? logout : login}
    >
    ${isAuthenticated ? 'Log out' : 'Log in'}
  </button>
`;
  • Use [] in attributes to get property binding
    • Use [class.foo] to show/hide the class foo depending on the truthiness of the value
    • Use [style.foo] to bind the value to to the foo style property
  • Use () in attributes for event binding
    • Listeners for keyup/keydown support binding to a single key or a key with modifiers, with slightly different semantics from Angular.
  • Use [()] for two way binding. This requires use of the bind function.
  • Use # to get references to the elements. This can be used with #prop=${object} where object.prop will be set to the element instance, or #name=${callback} where callback(elementRef, 'name') will be called. The name can be empty.
  • The bind function which can be used with the three types of bindings.
    • [prop]=${bind(obj, propName)}: identical to [prop]=${obj[propName]}
    • (event)=${bind(obj, propName)}: identical to (event)=${e => obj[propName] = e.detail}. This uses CustomEvent#detail and as such only works for custom events, not for browser events.
    • [(prop)]=${bind(obj, propName)}: identical to [prop]=${obj[propName]} combined with (prop-changed)=${() => obj[propName] = elementRef.prop} where elementRef is the element on which the property is bound.
    • [(prop::some-event)]=${bind(obj, propName)}: identical to [prop]=${obj[propName]} combined with (some-event)=${() => obj[propName] = elementRef.prop} where elementRef is the element on which the property is bound.
    • #=${bind(obj, propName)}: identical to #propName=${obj}
  • All other bindings are left as is, i.e. node bindings are not changed and attributes that don't use [] or () are simply set as attributes.
  • The [], () and [()] syntax only works in attributes with a ${} value due to how lit-html internally works.

Motivation

  • lit-html is awesome but by default it lacks options to set properties or event binding.

  • The extension provided by lit-html to introduce a Polymer-like syntax for setting properties and event listeners (property, attribute$ and on-event) leads to confusing behaviour, which this extension's syntax ([property], attribute and (event)) doesn't:
    This extension defaults to attributes, so if you don't write [] or () anywhere you are really just writing regular HTML, while the lit-html extension makes you set properties instead of attributes:

    /* The following template behaves differently depending on the render function used:
     * - The default `render` exposed by lit-html and the `render` function exposed by lit-html-brackets
     *   will set attributes `a` to `"foo"` and `b` to `"bar"`.
     * - The `render` function exposed by lit-html's extension sets the `a` attribute to `"foo"` but it
     *   sets the `b` property to `"bar"`.
     */
    const template = html`<div a="foo" b=${'bar'}></div>`;

Differences with Angular template syntax

  • Events listeners should be passed instead of called, that is:

    // lit-html-brackets syntax
    html`<div (click)=${onClick}></div>`

    vs

    <!-- angular syntax -->
    <div (click)="onClick($event)"></div>
  • Event listeners can be registered with negative modifiers noshift, noalt, nocontrol and nometa. These will only fire the listener if the modifier is absent.

  • Event listeners are fired even if unspecified modifiers are present. Let's take the example of a listener registered to keyup.enter. In Angular 5 that listener wouldn't fire for shift+enter key-ups. In lit-html-brackets that listener will fire. Use keyup.noshift.enter to get a listener that doesn't fire when shift is pressed.

  • Event listeners in Angular can be bound to window/document events. This is arguably more useful when used with Angular's @HostBinding('window:scroll') annotation than inside a template <div (window:scroll)="...">. As such, lit-html-brackets doesn't support these global event listeners.

  • Two way binding has to be used with the bind function, otherwise it results in one-way binding. This simply because we need the object and the property key to create two way binding. In Angular's templates, the object is known: the component instance. This is not the case for lit-html-brackets.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].