mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
- updates components to use shadow DOM or scoped if they require css variables - moves global styles to an external stylesheet that needs to be imported - adds support for additional colors and removes the Sass loops to generate colors for each component - several property renames, bug fixes, and test updates Co-authored-by: Manu Mtz.-Almeida <manu.mtza@gmail.com> Co-authored-by: Adam Bradley <adambradley25@gmail.com> Co-authored-by: Cam Wiegert <cam@camwiegert.com>
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { Component, Listen, Prop, State } from '@stencil/core';
|
|
|
|
@Component({
|
|
tag: 'ion-menu-toggle',
|
|
})
|
|
export class MenuToggle {
|
|
@Prop({ context: 'document' })
|
|
doc!: Document;
|
|
|
|
@State() visible = false;
|
|
|
|
/**
|
|
* Optional property that maps to a Menu's `menuId` prop.
|
|
* Can also be `left` or `right` for the menu side.
|
|
* This is used to find the correct menu to toggle
|
|
*/
|
|
@Prop() menu?: string;
|
|
|
|
/**
|
|
* Automatically hides the content when the corresponding menu is not active
|
|
*/
|
|
@Prop() autoHide = true;
|
|
|
|
componentDidLoad() {
|
|
this.updateVisibility();
|
|
}
|
|
|
|
@Listen('click')
|
|
async onClick() {
|
|
const menuCtrl = await getMenuController(this.doc);
|
|
if (menuCtrl) {
|
|
const menu = menuCtrl.get(this.menu);
|
|
if (menu && menu.isActive()) {
|
|
return menuCtrl.toggle(this.menu);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Listen('body:ionMenuChange')
|
|
@Listen('body:ionSplitPaneVisible')
|
|
async updateVisibility() {
|
|
const menuCtrl = await getMenuController(this.doc);
|
|
if (menuCtrl) {
|
|
const menu = menuCtrl.get(this.menu);
|
|
if (menu && menu.isActive()) {
|
|
this.visible = true;
|
|
return;
|
|
}
|
|
}
|
|
this.visible = false;
|
|
}
|
|
|
|
hostData() {
|
|
const hidden = this.autoHide && !this.visible;
|
|
return {
|
|
'hidden': hidden
|
|
};
|
|
}
|
|
}
|
|
|
|
function getMenuController(doc: Document): Promise<HTMLIonMenuControllerElement|undefined> {
|
|
const menuControllerElement = doc.querySelector('ion-menu-controller');
|
|
if (!menuControllerElement) {
|
|
return Promise.resolve(undefined);
|
|
}
|
|
return menuControllerElement.componentOnReady();
|
|
}
|