mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
feature(nav-push): initial implementation of nav-push
This commit is contained in:
32
packages/core/src/components.d.ts
vendored
32
packages/core/src/components.d.ts
vendored
@ -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';
|
||||
|
28
packages/core/src/components/nav-push/nav-push.tsx
Normal file
28
packages/core/src/components/nav-push/nav-push.tsx
Normal 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>;
|
||||
}
|
||||
|
||||
}
|
45
packages/core/src/components/nav-push/readme.md
Normal file
45
packages/core/src/components/nav-push/readme.md
Normal 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/)*
|
103
packages/core/src/components/nav-push/test/basic/index.html
Normal file
103
packages/core/src/components/nav-push/test/basic/index.html
Normal 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>
|
Reference in New Issue
Block a user