Files
Manu MA 34dfc3ce98 refactor(all): updating to newest stencil apis (#18578)
* chore(): update ionicons

* refactor(all): updating to newest stencil apis

* fix lint issues

* more changes

* moreee

* fix treeshaking

* fix config

* fix checkbox

* fix stuff

* chore(): update ionicons

* fix linting errors
2019-06-23 11:26:42 +02:00

85 lines
2.2 KiB
TypeScript

import { Component, ComponentInterface, Host, Listen, Prop, State, h } from '@stencil/core';
import { getIonMode } from '../../global/ionic-global';
@Component({
tag: 'ion-menu-toggle',
styleUrl: 'menu-toggle.scss',
shadow: true
})
export class MenuToggle implements ComponentInterface {
@State() visible = false;
/**
* Optional property that maps to a Menu's `menuId` prop.
* Can also be `start` or `end` for the menu side.
* This is used to find the correct menu to toggle.
*
* If this property is not used, `ion-menu-toggle` will toggle the
* first menu that is active.
*/
@Prop() menu?: string;
/**
* Automatically hides the content when the corresponding menu is not active.
*
* By default, it's `true`. Change it to `false` in order to
* keep `ion-menu-toggle` always visible regardless the state of the menu.
*/
@Prop() autoHide = true;
componentDidLoad() {
return this.updateVisibility();
}
@Listen('ionMenuChange', { target: 'body' })
@Listen('ionSplitPaneVisible', { target: 'body' })
async updateVisibility() {
const menuCtrl = await getMenuController(document);
if (menuCtrl) {
const menu = await menuCtrl.get(this.menu);
if (menu && await menu.isActive()) {
this.visible = true;
return;
}
}
this.visible = false;
}
private onClick = async () => {
const menuCtrl = await getMenuController(document);
if (menuCtrl) {
const menu = await menuCtrl.get(this.menu);
if (menu) {
menuCtrl.toggle(this.menu);
}
}
}
render() {
const mode = getIonMode(this);
const hidden = this.autoHide && !this.visible;
return (
<Host
onClick={this.onClick}
aria-hidden={hidden ? 'true' : null}
class={{
[mode]: true,
'menu-toggle-hidden': hidden,
}}
>
<slot></slot>
</Host>
);
}
}
function getMenuController(doc: Document): Promise<HTMLIonMenuControllerElement | undefined> {
const menuControllerElement = doc.querySelector('ion-menu-controller');
if (!menuControllerElement) {
return Promise.resolve(undefined);
}
return menuControllerElement.componentOnReady();
}