Giter Site home page Giter Site logo

wc-f7's Introduction

wc-f7

wc-f7 is a Framework7 setup that provides seamless integration with Web Components

Architecture

wc-f7 extends Framework7 core modules replacing the router component loader with one that accepts a Web Component declaration (tag name or class constructor) instead of a Framework7 component model. As a side effect, vdom (Snabbdom) and parser/loader modules are not imported/bundled.

Features

  • Declares Framework7 pages as Web Components
  • Supports async rendering (e.g. LitElement / SkateJS)
  • Bundle size smaller than Framework7 core
  • Supports component lifecycle hooks and page events
  • No hard dependency on a specific Framework7 version (any v4 version should work)

Caveats

  • Does not works with shadow dom, due to the Framework7 architecture
  • Only ES modules build is provided

Install

$ npm install wc-f7 framework7

Usage

Define component class

import { LitElement, html } from 'lit-element'


export class IndexPage extends LitElement {
  // page events are declared in static property $on
  static get $on() {
    return {
      pageMounted: function(e, page) {
        console.log('page mounted')
      },
      pageInit: function(e, page) {
        console.log('page init', this.level)
      } 
    }
  }

  get level() {
    // $route, $router, $app, $f7, $theme properties are avaliable in instance 
    return +this.$route.params.level || 0
  }

  // disables shadow dom
  createRenderRoot() {
    return this
  }

  // lifecycle hooks must be declared with $ prefix
  $created() {
    console.log('$created', this.level)
  }

  $beforeMount() {
    console.log('$beforeMount', this.level)
  }

render() {
    const level = this.level
    const message = level ? 'Hello Again' : 'Hello World!'
    return html`
      <div class="navbar">
        <div class="navbar-inner">
          ${level
            ? html`
                <div class="left">
                  <a href="#" class="link icon-only back">
                    <i class="icon icon-back"></i>
                  </a>
                </div>
              `
            : ''}
          <div class="title">Page - Level ${level}</div>
        </div>
      </div>
      <div class="page-content">
        <div class="block-title">${message}</div>
        <div class="list links-list">
          <ul>
            <li>
              <a href="/my-page/level/${level + 1}" class="next-link">Next Page</a>
            </li>
          </ul>
        </div>
      </div>
    `
  }
}

customElements.define('index-page', IndexPage)

Create the app and setup the route

import Framework7 from 'wc-f7' // 'wc-f7/bundle' for all components bundled
import { IndexPage } from './index/index-page'

const app = new Framework7({
  root: '#app',
  routes: [
    {
      path: '/my-page/level/:level',
      component: IndexPage // or 'index-page'
    },
  ],
})

See examples folder for complete apps


Copyright © 2019 Luiz Américo Pereira Câmara

wc-f7's People

Contributors

blikblum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wc-f7's Issues

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.