UNPKG

@ionic/core

Version:
194 lines (193 loc) • 7.94 kB
/*! * (C) Ionic http://ionicframework.com - MIT License */ import { Host, h } from "@stencil/core"; import { inheritAriaAttributes } from "../../utils/helpers"; import { menuController } from "../../utils/menu-controller/index"; import { createColorClasses, hostContext } from "../../utils/theme"; import { menuOutline, menuSharp } from "ionicons/icons"; import { config } from "../../global/config"; import { getIonMode } from "../../global/ionic-global"; import { updateVisibility } from "../menu-toggle/menu-toggle-util"; /** * @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use. * * @part native - The native HTML button element that wraps all child elements. * @part icon - The menu button icon (uses ion-icon). */ export class MenuButton { constructor() { this.inheritedAttributes = {}; this.onClick = async () => { return menuController.toggle(this.menu); }; this.visible = false; this.color = undefined; this.disabled = false; this.menu = undefined; this.autoHide = true; this.type = 'button'; } componentWillLoad() { this.inheritedAttributes = inheritAriaAttributes(this.el); } componentDidLoad() { this.visibilityChanged(); } async visibilityChanged() { this.visible = await updateVisibility(this.menu); } render() { const { color, disabled, inheritedAttributes } = this; const mode = getIonMode(this); const menuIcon = config.get('menuIcon', mode === 'ios' ? menuOutline : menuSharp); const hidden = this.autoHide && !this.visible; const attrs = { type: this.type, }; const ariaLabel = inheritedAttributes['aria-label'] || 'menu'; return (h(Host, { key: '3cde3704f28eb275f4a5ff2985bbb68c1024e79c', onClick: this.onClick, "aria-disabled": disabled ? 'true' : null, "aria-hidden": hidden ? 'true' : null, class: createColorClasses(color, { [mode]: true, button: true, // ion-buttons target .button 'menu-button-hidden': hidden, 'menu-button-disabled': disabled, 'in-toolbar': hostContext('ion-toolbar', this.el), 'in-toolbar-color': hostContext('ion-toolbar[color]', this.el), 'ion-activatable': true, 'ion-focusable': true, }) }, h("button", Object.assign({ key: 'a02a3374288bd1759b6e352ada8eab0d45c6422f' }, attrs, { disabled: disabled, class: "button-native", part: "native", "aria-label": ariaLabel }), h("span", { key: 'ba699f2277a4e7b27ce5e42faeefc53d8805bb43', class: "button-inner" }, h("slot", { key: '829fe6cbdeb173f50d1a670389d1565baa6273e4' }, h("ion-icon", { key: 'a9a9f7b8dcffc648a8429fe0adbe766869de72fd', part: "icon", icon: menuIcon, mode: mode, lazy: false, "aria-hidden": "true" }))), mode === 'md' && h("ion-ripple-effect", { key: '48deca9a771a249f2fc76eaa8b9741c8d66d8355', type: "unbounded" })))); } static get is() { return "ion-menu-button"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "ios": ["menu-button.ios.scss"], "md": ["menu-button.md.scss"] }; } static get styleUrls() { return { "ios": ["menu-button.ios.css"], "md": ["menu-button.md.css"] }; } static get properties() { return { "color": { "type": "string", "mutable": false, "complexType": { "original": "Color", "resolved": "\"danger\" | \"dark\" | \"light\" | \"medium\" | \"primary\" | \"secondary\" | \"success\" | \"tertiary\" | \"warning\" | string & Record<never, never> | undefined", "references": { "Color": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Color" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The color to use from your application's color palette.\nDefault options are: `\"primary\"`, `\"secondary\"`, `\"tertiary\"`, `\"success\"`, `\"warning\"`, `\"danger\"`, `\"light\"`, `\"medium\"`, and `\"dark\"`.\nFor more information on colors, see [theming](/docs/theming/basics)." }, "attribute": "color", "reflect": true }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "If `true`, the user cannot interact with the menu button." }, "attribute": "disabled", "reflect": false, "defaultValue": "false" }, "menu": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "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" }, "attribute": "menu", "reflect": false }, "autoHide": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Automatically hides the menu button when the corresponding menu is not active" }, "attribute": "auto-hide", "reflect": false, "defaultValue": "true" }, "type": { "type": "string", "mutable": false, "complexType": { "original": "'submit' | 'reset' | 'button'", "resolved": "\"button\" | \"reset\" | \"submit\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The type of the button." }, "attribute": "type", "reflect": false, "defaultValue": "'button'" } }; } static get states() { return { "visible": {} }; } static get elementRef() { return "el"; } static get listeners() { return [{ "name": "ionMenuChange", "method": "visibilityChanged", "target": "body", "capture": false, "passive": false }, { "name": "ionSplitPaneVisible", "method": "visibilityChanged", "target": "body", "capture": false, "passive": false }]; } }