Code Monkey home page Code Monkey logo

lit-html-examples's Introduction

lit-html-examples's People

Contributors

larsdenbakker avatar mnixo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lit-html-examples's Issues

@font-face

Hey, thanks for your examples. They have been really helpful.

I'm stuck understanding one thing. If I want to inherit styles from a parent and remove the shadowDom.

For example:

_createRoot() {
return this;
}

I lose the ability to compose a component with slots. I'm not against having shadowed styles though, so alternatively how would you enable @font-face for a custom element

Why are tagnames prepended with x-

customElements.define('x-repeat-templates', RepeatTemplates);

customElements.define('x-conditional-templates', ConditionalTemplates);

customElements.define('x-default-property', DefaultProperty);

Is this just something random so the name doesn't overlap with another element with a similar name?

Add more examples

  • to use with pwa-helpers
  • to use redux
  • to use redux with localStorage

Run examples in online editors

It would be cool to run the examples in jsbin, codepen or something similar. That way people can more easily see them in action and fork them.

Ideally they'd be synced with the source code.

Clarification on use of "."

Hi,

@ 1-basic/07-set-attributes.js you write:

  return html`
      <!--
        LitElement sets javascript properties by default. To set html attributes, prefix the the attribute
        with a '.'. It depends on the element you're rendering whether attributes or properties should be used.
        In this case the <a> element has a href attribute which we want to set.
        See set-properties example on how to set properties.
      -->
      <a .href="${this.href}">
        ${this.label}
      </a>

But
@ https://lit-element.polymer-project.org/guide/templates

Bind to an attribute
Bind prop2 to an attribute:

it mentions that

html`<div id="${this.prop2}"></div>`

id is a global attribute as well as href is an attribute of <a> element, isn't it?

On the other hand, a little bit further it mentions:

Bind to a property
Bind prop4 to a property:

html`<input type="checkbox" .value="${this.prop4}"/>`

but value is also an input attribute! Isn't it?

In addition,
@ 1-basic/06-set-properties.js you write:

...
          <input placeholder="${this.placeholder}">
...

     <x-custom-input
        helpText="${this.helpText}"
        placeholder="${this.placeholder}">
     </x-custom-input>
...

Although placeholder is an attribute you do not write .placeholder.

Moreover, shouldn't be:

     <x-custom-input
        .helpText="${this.helpText}"
        .placeholder="${this.placeholder}">
     </x-custom-input>

since both helpText and placeholder are properties of <x-custom-input> element.

Tia

Reflect property to attribute example is outdated

LitElement now supports property option called reflect, so instead of this whole method:

/**
* Sometimes it's useful to reflect js property values back to html attributes.
* This can be done from the update callback, which contains all
* property change information.
*/
update(changedProperties) {
// Make sure to call super, as this callback is used by LitElement as well.
super.update(changedProperties);
// In this case we are iterating over all properties and reflecting them.
Object.keys(this.constructor.properties).forEach((key) => {
// Only update if property changed
if (changedProperties.has(key)) {
const value = changedProperties.get(key);
if (value !== undefined) {
this.setAttribute(key, value);
} else {
// Values are stringified as attributes. We don't like to see undefined
// in the DOM, so we remove the attribute.
this.removeAttribute(key);
}
}
});
// Instead of reflect all properties all the time, you could implement a separate property
// to control which properties are reflected:
// this._reflectedProperties.forEach((key) => {
// ... same as above
// });
}

you could just set properties like so:

{ 
  count: { type: Number, reflect: true }
  message: { type: String }, 
}

I'd make a PR, but I'm not sure if this example is even needed anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.