import { Prop, Component } from "vue-property-decorator"; // Interfaces import { INavigationBarTerminal } from "@/types"; // Components import Icon from "@/components/Icon/index.vue"; import Logo from "@/components/Logo/index.vue"; import Button from "@/components/Button/index.vue"; import KeyNavigate from "@/utils/class_components/KeyNavigate"; import toInt from "@/utils/converts"; import NavItem from "./NavItem/index.vue"; import SwitchTerminalPopover from "./SwitchTerminalPopover/index.vue"; @Component({ components: { Icon, Logo, NavItem, SwitchTerminalPopover, Button, }, }) export default class NavigationBar extends KeyNavigate { @Prop({ type: Array }) readonly terminals!: INavigationBarTerminal[]; @Prop({ type: Array, required: true }) readonly navItems!: INavigationBarTerminal[]; @Prop({ type: Object }) readonly activeTerminal?: INavigationBarTerminal; @Prop({ type: String }) readonly createLink?: string; @Prop({ type: Function }) readonly onEnterLink?: () => void; isCollapsed = false; isVisible = false; isDrawer = false; isFixed = false; isToggle = false; zplLogo = "topbar"; menuBurger = "topbar"; showSwitch = false; curActiveMenu = ""; // private iShowSwitch = false created(): void { this.kOrder = ["switchTerminalPopover", "navItem"]; this.kOnMySec = true; this.kMainNav = this; this.kSetCurComp(this); window.addEventListener("keyup", this.kOnGlobalKeyup); document.body.addEventListener("keyup", this.kOnGlobalKeyup); this.kCreated(); } private detStats() { const [xl, slg] = toInt("1200px", "992px"); const width = window.innerWidth; if (width > slg) { this.showSwitch = true; this.isVisible = true; if (this.isToggle) { if (width < xl) { this.isDrawer = true; } else { this.isDrawer = false; } this.isCollapsed = false; } else { this.isCollapsed = true; this.isDrawer = false; } } else { this.isVisible = false; this.showSwitch = false; this.isCollapsed = false; if (this.isToggle) { this.isDrawer = true; } else { this.isDrawer = false; } } if (width > xl) { this.menuBurger = "topbar"; this.zplLogo = "topbar"; if (this.isToggle) { this.isFixed = true; } else { this.isFixed = false; } } else { this.isFixed = false; if (this.isToggle) { if (this.isDrawer) { this.zplLogo = "navbar"; this.menuBurger = "navbar"; } else { this.menuBurger = "topbar"; } } else { this.zplLogo = "topbar"; this.menuBurger = "topbar"; } } } clkOccured(menuTitle) { this.$nextTick(() => { this.curActiveMenu = menuTitle; }); } toggleMenu() { this.isToggle = !this.isToggle; this.detStats(); } initStats() { const [slg] = toInt("1200px"); const width = window.innerWidth; if (width < slg) { this.isToggle = false; } else { this.isToggle = true; } this.detStats(); } mounted(): void { this.initStats(); window.addEventListener("resize", this.initStats); window.addEventListener("click", this.kOnGlobalClick); } onKeyDown(e: KeyboardEvent) { this.kDoKeyDown(e); } onKeyup(e: KeyboardEvent) { const { key } = e; const curComp = this.kCurComp ?? this; if (curComp.kOnMySec) { this.kDbg?.dbgRun({ key }); curComp.kDoKeyup(e); } else if (curComp.kMainNav) { this.kDbg?.dbgRun({ key }); // in yani dar iteme akhari mainNav hastim va mikhahim beparim biroon if (key === "Tab" || (key === "Tab" && this.kFindKeyDown("Shift"))) { this.kDoBlurComp(e); this.kOnMySec = true; if ( (this.kCurKeyMove === "Tab" && key === "Tab" && this.kFindKeyDown("Shift")) || (this.kCurKeyMove === "ShiftTab" && key === "Tab") ) { curComp.kDoKeyup(e); } else { this.kDestroyKeyUp("onKeyup navigationBar"); this.kDoFocusOut(); } } } } beforeDestroy(): void { window.removeEventListener("resize", this.initStats); window.removeEventListener("keyup", this.kOnGlobalKeyup); window.removeEventListener("click", this.kOnGlobalClick); document.body.removeEventListener("keyup", this.kOnGlobalKeyup); this.kDestroyKeyUp("beforeDestroy navigationBar"); } }