import '../../../src/stylus/components/_menus.styl'; import Vue from 'vue'; // Mixins import Delayable from '../../mixins/delayable'; import Dependent from '../../mixins/dependent'; import Detachable from '../../mixins/detachable'; import Menuable from '../../mixins/menuable.js'; import Returnable from '../../mixins/returnable'; import Toggleable from '../../mixins/toggleable'; import Themeable from '../../mixins/themeable'; // Component level mixins import Activator from './mixins/menu-activator'; import Generators from './mixins/menu-generators'; import Keyable from './mixins/menu-keyable'; import Position from './mixins/menu-position'; // Directives import ClickOutside from '../../directives/click-outside'; import Resize from '../../directives/resize'; // Helpers import { convertToUnit, getSlotType } from '../../util/helpers'; import ThemeProvider from '../../util/ThemeProvider'; import { consoleError } from '../../util/console'; /* @vue/component */ export default Vue.extend({ name: 'v-menu', provide: function provide() { return { // Pass theme through to default slot theme: this.theme }; }, directives: { ClickOutside: ClickOutside, Resize: Resize }, mixins: [Activator, Dependent, Delayable, Detachable, Generators, Keyable, Menuable, Position, Returnable, Toggleable, Themeable], props: { auto: Boolean, closeOnClick: { type: Boolean, default: true }, closeOnContentClick: { type: Boolean, default: true }, disabled: Boolean, fullWidth: Boolean, maxHeight: { default: 'auto' }, openOnClick: { type: Boolean, default: true }, offsetX: Boolean, offsetY: Boolean, openOnHover: Boolean, origin: { type: String, default: 'top left' }, transition: { type: [Boolean, String], default: 'v-menu-transition' } }, data: function data() { return { defaultOffset: 8, hasJustFocused: false, resizeTimeout: null }; }, computed: { calculatedLeft: function calculatedLeft() { var menuWidth = Math.max(this.dimensions.content.width, parseFloat(this.calculatedMinWidth)); if (!this.auto) return this.calcLeft(menuWidth); return this.calcXOverflow(this.calcLeftAuto(), menuWidth) + 'px'; }, calculatedMaxHeight: function calculatedMaxHeight() { return this.auto ? '200px' : convertToUnit(this.maxHeight); }, calculatedMaxWidth: function calculatedMaxWidth() { return isNaN(this.maxWidth) ? this.maxWidth : this.maxWidth + 'px'; }, calculatedMinWidth: function calculatedMinWidth() { if (this.minWidth) { return isNaN(this.minWidth) ? this.minWidth : this.minWidth + 'px'; } var minWidth = Math.min(this.dimensions.activator.width + this.nudgeWidth + (this.auto ? 16 : 0), Math.max(this.pageWidth - 24, 0)); var calculatedMaxWidth = isNaN(parseInt(this.calculatedMaxWidth)) ? minWidth : parseInt(this.calculatedMaxWidth); return Math.min(calculatedMaxWidth, minWidth) + 'px'; }, calculatedTop: function calculatedTop() { if (!this.auto || this.isAttached) return this.calcTop(); return this.calcYOverflow(this.calculatedTopAuto) + 'px'; }, styles: function styles() { return { maxHeight: this.calculatedMaxHeight, minWidth: this.calculatedMinWidth, maxWidth: this.calculatedMaxWidth, top: this.calculatedTop, left: this.calculatedLeft, transformOrigin: this.origin, zIndex: this.zIndex || this.activeZIndex }; } }, watch: { activator: function activator(newActivator, oldActivator) { this.removeActivatorEvents(oldActivator); this.addActivatorEvents(newActivator); }, disabled: function disabled(_disabled) { if (!this.activator) return; if (_disabled) { this.removeActivatorEvents(this.activator); } else { this.addActivatorEvents(this.activator); } }, isContentActive: function isContentActive(val) { this.hasJustFocused = val; } }, mounted: function mounted() { this.isActive && this.activate(); if (getSlotType(this, 'activator', true) === 'v-slot') { consoleError('v-tooltip\'s activator slot must be bound, try \'