Giter Club home page Giter Club logo

paper's Introduction

Paper

Paper is a JavaScript UI library which is usable as an ESM module and has no dependencies.

Installation

script Tag

<script src="https://tomashubelbauer.github.io/paper/index.js" type="module"></script>

Git Submodule

git submodule add https://github.com/tomashubelbauer/paper

Usage

HelloWorld.js

import { Component, h1, div, ... } from './paper/index.js';

// Note that the component class must inherit from Component directly
export default class HelloWorld extends Component {
  // This constructor must be present for Paper to be able to define the WC
  // This web component will be defined with tag `paper-hello-world`
  constructor() {
    super(HelloWorld);
  }

  // This method will comprise the component's closed shadow DOM content
  // A `HelloWorld.css` stylesheet will be imported (and effectively scoped)
  // A wrapper `div` element surrounds the component with ID equal to its name
  async *render() {
    yield h1('Hello, world!');
    const loaderDiv = div('Loading data…');
    yield loaderDiv;

    const data = await fetch('/api/data').then(response => response.json());
    loaderDiv.remove();
    for (const item of data.items) {
      yield div('Item: ', JSON.stringify(item));
    }

    if (data.more === 0) {
      return '(no more items)';
    }

    yield `There are ${data.more} more items!`;
  }
}

HelloWorld.css

This file must exist, even if empty. Paper will import it to the closed shadow DOM.

index.js

document.body.append(new HelloWorld());

Purpose

I built Paper accidentally, by finding various tricks and hacks to make the UI code in my personal pure-JS, no-dependencies project a little less tedious to write. At some point it started making sense to pull it out and use it as a Git submodule and import it as an ESM module.

Limitations

The component class must inherit from Component directly. This is because of some trickery used to determine if the class name matches the file name. If you do not want this feature, fork Paper and remove this restriction.

To-Do

Split off Component.js into a new paper-wc repository

Paper should be usable without it and essentially implement the ideas I have been contemplating in my acter and fragment repositories. By pulling this web component helper class out, I'll be able to add non-web-components based demos and delete the acter and fragment repositories making Paper my final word on a build-system-less UI framework.

paper's People

Contributors

tomashubelbauer avatar

Watchers

 avatar  avatar  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.