feature(nav-push): initial implementation of nav-push

This commit is contained in:
Dan Bucholtz
2018-02-13 14:19:51 -06:00
parent 50ddcd4c7d
commit d4059ead58
4 changed files with 208 additions and 0 deletions

View File

@ -1840,6 +1840,38 @@ declare global {
}
import {
NavPop as IonNavPush
} from './components/nav-push/nav-push';
declare global {
interface HTMLIonNavPushElement extends IonNavPush, HTMLStencilElement {
}
var HTMLIonNavPushElement: {
prototype: HTMLIonNavPushElement;
new (): HTMLIonNavPushElement;
};
interface HTMLElementTagNameMap {
"ion-nav-push": HTMLIonNavPushElement;
}
interface ElementTagNameMap {
"ion-nav-push": HTMLIonNavPushElement;
}
namespace JSX {
interface IntrinsicElements {
"ion-nav-push": JSXElements.IonNavPushAttributes;
}
}
namespace JSXElements {
export interface IonNavPushAttributes extends HTMLAttributes {
component?: any;
data?: any;
url?: string;
}
}
}
import {
Nav as IonNav
} from './components/nav/nav';

View File

@ -0,0 +1,28 @@
import { Component, Element, Listen, Prop } from '@stencil/core';
import { NavResult } from '../../index';
@Component({
tag: 'ion-nav-push',
})
export class NavPop {
@Element() element: HTMLElement;
@Prop() component: any;
@Prop() url: string;
@Prop() data: any;
@Listen('child:click')
push(): Promise<NavResult> {
const nav = this.element.closest('ion-nav') as HTMLIonNavElement;
if (nav) {
const toPush = this.url || this.component;
return nav.push(toPush, this.data);
}
return Promise.resolve(null);
}
render() {
return <slot></slot>;
}
}

View File

@ -0,0 +1,45 @@
# ion-nav-push
<!-- Auto Generated Below -->
## Properties
#### component
any
#### data
any
#### url
string
## Attributes
#### component
any
#### data
any
#### url
string
----------------------------------------------
*Built with [StencilJS](https://stenciljs.com/)*

View File

@ -0,0 +1,103 @@
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="UTF-8">
<title>Nav Push</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="/dist/ionic.js"></script>
</head>
<body onload="loadFirstPage()">
<ion-app>
<ion-nav></ion-nav>
</ion-app>
<style>
f {
display: block;
margin: 15px auto;
max-width: 150px;
height: 150px;
background: blue;
}
f:last-of-type {
background: yellow;
}
</style>
</body>
<script>
class FirstPage extends HTMLElement {
async connectedCallback() {
this.innerHTML = `
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Page One</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h1>Page One</h1>
<ion-nav-push component="page-two">
<ion-button class="next">Go to Page Two</ion-button>
</ion-nav-push>
</ion-content>
</ion-page>
`;
}
}
class SecondPage extends HTMLElement {
async connectedCallback() {
this.innerHTML = `
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Page Two</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h1>Page Two</h1>
<ion-nav-push component="page-three">
<ion-button class="next">Go to Page Three</ion-button>
</ion-nav-push>
<ion-nav-pop>
<ion-button class="back">Go Back</ion-button>
</ion-nav-pop>
</ion-content>
</ion-page>
`;
}
}
class ThirdPage extends HTMLElement {
async connectedCallback() {
this.innerHTML = `
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Page Three</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h1>Page Three</h1>
<ion-nav-pop>
<ion-button class="back">Go Back</ion-button>
</ion-nav-pop>
</ion-content>
</ion-page>
`;
}
}
customElements.define('page-one', FirstPage);
customElements.define('page-two', SecondPage);
customElements.define('page-three', ThirdPage);
async function loadFirstPage() {
const nav = document.querySelector('ion-nav');
await nav.componentOnReady();
await nav.setRoot('page-one');
}
</script>
</html>