UNPKG

@nextcloud/vue

Version:
140 lines (139 loc) 4.64 kB
import '../assets/NcAppNavigation-fhylfTxx.css'; import { useIsMobile } from "../Composables/useIsMobile.mjs"; import { g as getTrapStack } from "./focusTrap-Cecv_gjR.mjs"; import { subscribe, emit, unsubscribe } from "@nextcloud/event-bus"; import { createFocusTrap } from "focus-trap"; import NcAppNavigationList from "../Components/NcAppNavigationList.mjs"; import { N as NcAppNavigationToggle } from "./NcAppNavigationToggle-BXainLDc.mjs"; import Vue from "vue"; import { n as normalizeComponent } from "./_plugin-vue2_normalizer-DU4iP6Vu.mjs"; const _sfc_main = { name: "NcAppNavigation", components: { NcAppNavigationList, NcAppNavigationToggle }, // Injected from NcContent inject: { setHasAppNavigation: { default: () => () => Vue.util.warn("NcAppNavigation is not mounted inside NcContent, this is probably an error."), from: "NcContent:setHasAppNavigation" } }, props: { /** * The aria label to describe the navigation */ ariaLabel: { type: String, default: "" }, /** * aria-labelledby attribute to describe the navigation */ ariaLabelledby: { type: String, default: "" } }, setup() { return { isMobile: useIsMobile() }; }, data() { return { open: !this.isMobile, focusTrap: null }; }, watch: { isMobile() { this.open = !this.isMobile; this.toggleFocusTrap(); }, open() { this.toggleFocusTrap(); } }, mounted() { this.setHasAppNavigation(true); subscribe("toggle-navigation", this.toggleNavigationByEventBus); emit("navigation-toggled", { open: this.open }); this.focusTrap = createFocusTrap(this.$refs.appNavigationContainer, { allowOutsideClick: true, fallbackFocus: this.$refs.appNavigationContainer, trapStack: getTrapStack(), escapeDeactivates: false }); this.toggleFocusTrap(); }, unmounted() { this.setHasAppNavigation(false); unsubscribe("toggle-navigation", this.toggleNavigationByEventBus); this.focusTrap.deactivate(); }, methods: { /** * Toggle the navigation * * @param {boolean} [state] set the state instead of inverting the current one */ toggleNavigation(state) { if (this.open === state) { emit("navigation-toggled", { open: this.open }); return; } this.open = typeof state === "undefined" ? !this.open : state; const bodyStyles = getComputedStyle(document.body); const animationLength = parseInt(bodyStyles.getPropertyValue("--animation-quick")) || 100; setTimeout(() => { emit("navigation-toggled", { open: this.open }); }, 1.5 * animationLength); }, toggleNavigationByEventBus({ open }) { this.toggleNavigation(open); }, /** * Activate focus trap if it is currently needed, otherwise deactivate */ toggleFocusTrap() { if (this.isMobile && this.open) { this.focusTrap.activate(); } else { this.focusTrap.deactivate(); } }, handleEsc() { if (this.isMobile) { this.toggleNavigation(false); } } } }; var _sfc_render = function render() { var _vm = this, _c = _vm._self._c; return _c("div", { ref: "appNavigationContainer", staticClass: "app-navigation", class: { "app-navigation--close": !_vm.open } }, [_c("nav", { staticClass: "app-navigation__content", attrs: { "id": "app-navigation-vue", "aria-hidden": _vm.open ? "false" : "true", "aria-label": _vm.ariaLabel || void 0, "aria-labelledby": _vm.ariaLabelledby || void 0, "inert": !_vm.open || void 0 }, on: { "keydown": function($event) { if (!$event.type.indexOf("key") && _vm._k($event.keyCode, "esc", 27, $event.key, ["Esc", "Escape"])) return null; return _vm.handleEsc.apply(null, arguments); } } }, [_c("div", { staticClass: "app-navigation__search" }, [_vm._t("search")], 2), _c("div", { staticClass: "app-navigation__body", class: { "app-navigation__body--no-list": !_vm.$scopedSlots.list } }, [_vm._t("default")], 2), _vm.$scopedSlots.list ? _c("NcAppNavigationList", { staticClass: "app-navigation__list" }, [_vm._t("list")], 2) : _vm._e(), _vm._t("footer")], 2), _c("NcAppNavigationToggle", { attrs: { "open": _vm.open }, on: { "update:open": _vm.toggleNavigation } })], 1); }; var _sfc_staticRenderFns = []; var __component__ = /* @__PURE__ */ normalizeComponent( _sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "e7d078cc" ); const NcAppNavigation = __component__.exports; export { NcAppNavigation as N };