项目作者: dsolimando

项目描述 :
A lightweight WebComponents based mobile JS lib
高级语言: JavaScript
项目地址: git://github.com/dsolimando/moko.git
创建时间: 2017-08-22T11:44:22Z
项目社区:https://github.com/dsolimando/moko

开源协议:Apache License 2.0

下载


Moko

Moko is a lightweight WebComponents based navigation library
highly inspired by React Navigation.

It supports three kinds of navigators:

  • switch navigator
  • stack navigator
  • tab navigator

Switch navigator

Switch navigator only show one content at a time, each route displaying a different content. Content is not cached

Code example:

  1. <moko-switch-navigator>
  2. <moko-route path="view1/:name" component="demo-view1">
  3. <span>diego</span>
  4. </moko-route>
  5. <moko-route path="view2/:name" component="demo-view2"></moko-route>
  6. <moko-route path="view3/:name" component="demo-view3"></moko-route>
  7. </moko-switch-navigator>

A navigator contains one or multiple <moko-route>. A route has two mandatory attributes path and component.

  • path associates the route to an url fragment. Each time an url match that path, the component associated with that route will be displayed. The path can contain placeholders
  • component name of the Web Component to be displayed for a matching route.

Navigation is triggered either with standard <a href="#some-route">Click</a> or with safer moko provided custom element
<moko-link to="some-route""></moko-link>. moko-link supports navigator nesting and only relative (to the closest parent navigator) path must be provided.

If the url fragment is empty, the component associated with the first route will be rendered.

It’s possible to define a default route to render with the default-path attribute.

By default a navigator will take all the space available in his node ancestor.

Server side rendering

First moko-route element can contain markup that will be displayed before corresponding web component is rendered properly.
It allows to server side render content and make the page SSO friendly.

Demo

See switchNavigator.html for a complete example.

Stack navigator

Stack navigator will display new content on top of previous one while navigating.

Code example:

  1. <moko-stack-navigator>
  2. <moko-route path="path1" component="demo-el1"></moko-route>
  3. <moko-route path="path2" component="demo-el2"></moko-route>
  4. <moko-route path="path3" component="demo-el3"></moko-route>
  5. </moko-stack-navigator>

Demo

See stackNavigator.html for a complete example.

Server side rendering

First moko-route element can contain markup that will be displayed before corresponding web component is rendered properly.
It allows to server side render content and make the page SSO friendly.

Tab navigator

Tab navigator will display a tabbar at the bottom of the screen. Each click on a tab entry will
display different content.

Code example:

  1. <moko-tab-navigator active-color="red">
  2. <moko-tab-route
  3. icon="trending-up"
  4. title="Home"
  5. path="home1"
  6. component="demo-home"
  7. >
  8. </moko-tab-route>
  9. <moko-tab-route
  10. icon="package"
  11. title="Home2"
  12. path="home2"
  13. component="demo-home2"
  14. >
  15. </moko-tab-route>
  16. <moko-tab-route
  17. icon="trending-down"
  18. title="Home3"
  19. path="home3"
  20. component="demo-home3"
  21. >
  22. </moko-tab-route>
  23. <div style="height: 200%; background: yellow">Home1</div>
  24. </moko-tab-navigator>

Demo

See tabNavigator.html for a complete example.

Server side rendering

moko-tab-navigator element can contain markup as last child that will be displayed before corresponding web component is rendered properly.
It allows to server side render content and make the page SSO friendly.

Using navigators in your webpage

Each navigator is available as Web Components through ES6 modules (see the dist folder).

Live Demos