Git Product home page Git Product logo

slim-element's Introduction

Slim Element

A tiny base class for building web components.

It enables some super light abstractions over vanilla web component authoring, catered to my personal preferences.

Usage

npm install slim-element
import { SlimElement } from 'slim-element';

class SimpleGreeting extends SlimElement {
  // Component styles can be *optionally* defined as a static property
  // If constructable style sheets are supported they will be used, otherwise 
  // the styles will be placed in a <style> tag inside the shadow DOM
  static styles = `
    h1 { color: teal; }
  `;

  // A constructor method can be *optionally* defined
  // Calling super() will create and attach a shadow DOM
  constructor() {
    super();
    // ... your custom component code ...
  }

  // A connectedCallback method can be *optionally* defined
  // Calling super.connectedCallback() will handle rendering the component
  connectedCallback() {
    super.connectedCallback();
    // ... your custom component code ...
  }

  // A render method is required for defining component markup
  render() {
    return `<h1>Hey there!</h1>`;
  }
}

customElements.define('simple-greeting', SimpleGreeting);

Example

See an example of SlimElement in action in simple-greeting.js or counter-button.js.

License

This is licensed under MIT. Feel free to use, remix, and adapt the code found this repo in your own projects.

slim-element's People

Contributors

hawkticehurst avatar

Stargazers

 avatar

Watchers

 avatar

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.