feat(split-pane): integrated with ion-menu

This commit is contained in:
Manuel Mtz-Almeida
2017-09-16 23:08:34 -04:00
parent 9dcd00d9b9
commit 9e44b281e4
4 changed files with 35 additions and 21 deletions

View File

@ -1,5 +1,5 @@
import { Component, Element, Event, EventEmitter, Prop, PropDidChange } from '@stencil/core'; import { Component, Element, Event, EventEmitter, Prop, PropDidChange, Listen } from '@stencil/core';
import { Config, Animation } from '../../index'; import { Config, Animation, SplitPaneAlert } from '../../index';
import { MenuController } from './menu-controller'; import { MenuController } from './menu-controller';
import { isRightSide, Side, assert, checkEdgeSide } from '../../utils/helpers'; import { isRightSide, Side, assert, checkEdgeSide } from '../../utils/helpers';
@ -102,6 +102,11 @@ export class Menu {
// const isRTL = false; // const isRTL = false;
// // this.isRightSide = isRightSide(side, isRTL); // // this.isRightSide = isRightSide(side, isRTL);
// } // }
@Listen('body:ionSplitPaneDidChange')
splitPaneChanged(ev: SplitPaneAlert) {
this._isPane = ev.detail.splitPane.isPane(this.el);
this._updateState();
}
@PropDidChange('enabled') @PropDidChange('enabled')
enabledChanged() { enabledChanged() {
@ -155,6 +160,7 @@ export class Menu {
// mask it as enabled / disabled // mask it as enabled / disabled
this.enable(isEnabled); this.enable(isEnabled);
this._init = true;
} }
hostData() { hostData() {
@ -266,7 +272,7 @@ export class Menu {
this._isAnimating = true; this._isAnimating = true;
this._startAnimation(false, false) this._startAnimation(false, false)
.then(() => this._after(false)); this._after(false);
} }
getWidth(): number { getWidth(): number {
@ -521,14 +527,6 @@ export class Menu {
return false; return false;
} }
/**
* @internal
*/
paneChanged(isPane: boolean) {
this._isPane = isPane;
this._updateState();
}
/** /**
* @hidden * @hidden
*/ */

View File

@ -160,6 +160,7 @@ export class SplitPane {
/** /**
* @output {any} Expression to be called when the split-pane visibility has changed * @output {any} Expression to be called when the split-pane visibility has changed
*/ */
@Event() ionSplitPaneDidChange: EventEmitter;
@Event() ionChange: EventEmitter; @Event() ionChange: EventEmitter;
ionViewDidLoad() { ionViewDidLoad() {
@ -181,16 +182,16 @@ export class SplitPane {
var isMain = child.hasAttribute('main'); var isMain = child.hasAttribute('main');
if (isMain) { if (isMain) {
if (foundMain) { if (foundMain) {
// console.warn('split pane can not have more than one main node'); console.warn('split pane can not have more than one main node');
return; return;
} }
foundMain = true; foundMain = true;
} }
setPaneClass(child, isMain); setPaneClass(child, isMain);
} }
// if (!foundMain) { if (!foundMain) {
// console.warn('split pane could not found any main node'); console.warn('split pane could not found any main node');
// } }
} }
@PropDidChange('when') @PropDidChange('when')
@ -234,7 +235,9 @@ export class SplitPane {
private _setVisible(visible: boolean) { private _setVisible(visible: boolean) {
if (this.visible !== visible) { if (this.visible !== visible) {
this.visible = visible; this.visible = visible;
this.ionChange.emit(this); const detail = { splitPane: this };
this.ionChange.emit(detail);
this.ionSplitPaneDidChange.emit(detail);
} }
} }
@ -246,6 +249,14 @@ export class SplitPane {
return this.visible; return this.visible;
} }
isPane(element: HTMLElement): boolean {
if (!this.visible) {
return false;
}
return element.parentElement === this.ele
&& element.classList.contains(SPLIT_PANE_SIDE);
}
hostData() { hostData() {
return { return {
class: { class: {
@ -260,6 +271,12 @@ export class SplitPane {
} }
export interface SplitPaneAlert {
detail: {
splitPane: SplitPane
}
}
function setPaneClass(ele: HTMLElement, isMain: boolean) { function setPaneClass(ele: HTMLElement, isMain: boolean) {
let toAdd; let toAdd;
let toRemove; let toRemove;

View File

@ -55,7 +55,6 @@
<ion-content padding> <ion-content padding>
<ion-button onclick="openLeft()">Open left menu</ion-button> <ion-button onclick="openLeft()">Open left menu</ion-button>
<ion-button onclick="openRight()">Open right menu</ion-button>
</ion-content> </ion-content>
</ion-page> </ion-page>
@ -70,10 +69,6 @@
console.log('Open left menu'); console.log('Open left menu');
menu.open('left'); menu.open('left');
} }
function openRight() {
console.log('Open right menu');
menu.open('right');
}
</script> </script>
</body> </body>
</html> </html>

View File

@ -20,6 +20,8 @@ import { PopoverController } from './components/popover-controller/popover-contr
import { Scroll, ScrollCallback, ScrollDetail } from './components/scroll/scroll'; import { Scroll, ScrollCallback, ScrollDetail } from './components/scroll/scroll';
import { Segment } from './components/segment/segment'; import { Segment } from './components/segment/segment';
import { SegmentButton, SegmentButtonEvent } from './components/segment-button/segment-button'; import { SegmentButton, SegmentButtonEvent } from './components/segment-button/segment-button';
import { SplitPane, SplitPaneAlert } from './components/split-pane/split-pane';
import { Toast, ToastEvent, ToastOptions } from './components/toast/toast' import { Toast, ToastEvent, ToastOptions } from './components/toast/toast'
import { ToastController } from './components/toast-controller/toast-controller' import { ToastController } from './components/toast-controller/toast-controller'
@ -90,6 +92,8 @@ export {
Segment, Segment,
SegmentButton, SegmentButton,
SegmentButtonEvent, SegmentButtonEvent,
SplitPane,
SplitPaneAlert,
TransitionBuilder, TransitionBuilder,
Toast, Toast,
ToastEvent, ToastEvent,