Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VNavigationDrawer.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. // Styles
  3. import '../../../src/stylus/components/_navigation-drawer.styl';
  4. // Mixins
  5. import Applicationable from '../../mixins/applicationable';
  6. import Dependent from '../../mixins/dependent';
  7. import Overlayable from '../../mixins/overlayable';
  8. import SSRBootable from '../../mixins/ssr-bootable';
  9. import Themeable from '../../mixins/themeable';
  10. // Directives
  11. import ClickOutside from '../../directives/click-outside';
  12. import Resize from '../../directives/resize';
  13. import Touch from '../../directives/touch';
  14. // Utilities
  15. import { convertToUnit } from '../../util/helpers';
  16. import mixins from '../../util/mixins';
  17. export default mixins(Applicationable('left', ['miniVariant', 'right', 'width']), Dependent, Overlayable, SSRBootable, Themeable
  18. /* @vue/component */
  19. ).extend({
  20. name: 'v-navigation-drawer',
  21. directives: {
  22. ClickOutside: ClickOutside,
  23. Resize: Resize,
  24. Touch: Touch
  25. },
  26. props: {
  27. clipped: Boolean,
  28. disableRouteWatcher: Boolean,
  29. disableResizeWatcher: Boolean,
  30. height: {
  31. type: [Number, String],
  32. default: '100%'
  33. },
  34. floating: Boolean,
  35. miniVariant: Boolean,
  36. miniVariantWidth: {
  37. type: [Number, String],
  38. default: 80
  39. },
  40. mobileBreakPoint: {
  41. type: [Number, String],
  42. default: 1264
  43. },
  44. permanent: Boolean,
  45. right: Boolean,
  46. stateless: Boolean,
  47. temporary: Boolean,
  48. touchless: Boolean,
  49. width: {
  50. type: [Number, String],
  51. default: 300
  52. },
  53. value: { required: false }
  54. },
  55. data: function data() {
  56. return {
  57. isActive: false,
  58. touchArea: {
  59. left: 0,
  60. right: 0
  61. }
  62. };
  63. },
  64. computed: {
  65. /**
  66. * Used for setting an app value from a dynamic
  67. * property. Called from applicationable.js
  68. */
  69. applicationProperty: function applicationProperty() {
  70. return this.right ? 'right' : 'left';
  71. },
  72. calculatedTransform: function calculatedTransform() {
  73. if (this.isActive) return 0;
  74. return this.right ? this.calculatedWidth : -this.calculatedWidth;
  75. },
  76. calculatedWidth: function calculatedWidth() {
  77. return parseInt(this.miniVariant ? this.miniVariantWidth : this.width);
  78. },
  79. classes: function classes() {
  80. return _extends({
  81. 'v-navigation-drawer': true,
  82. 'v-navigation-drawer--absolute': this.absolute,
  83. 'v-navigation-drawer--clipped': this.clipped,
  84. 'v-navigation-drawer--close': !this.isActive,
  85. 'v-navigation-drawer--fixed': !this.absolute && (this.app || this.fixed),
  86. 'v-navigation-drawer--floating': this.floating,
  87. 'v-navigation-drawer--is-mobile': this.isMobile,
  88. 'v-navigation-drawer--mini-variant': this.miniVariant,
  89. 'v-navigation-drawer--open': this.isActive,
  90. 'v-navigation-drawer--right': this.right,
  91. 'v-navigation-drawer--temporary': this.temporary
  92. }, this.themeClasses);
  93. },
  94. hasApp: function hasApp() {
  95. return this.app && !this.isMobile && !this.temporary;
  96. },
  97. isMobile: function isMobile() {
  98. return !this.stateless && !this.permanent && !this.temporary && this.$vuetify.breakpoint.width < parseInt(this.mobileBreakPoint, 10);
  99. },
  100. marginTop: function marginTop() {
  101. if (!this.hasApp) return 0;
  102. var marginTop = this.$vuetify.application.bar;
  103. marginTop += this.clipped ? this.$vuetify.application.top : 0;
  104. return marginTop;
  105. },
  106. maxHeight: function maxHeight() {
  107. if (!this.hasApp) return null;
  108. var maxHeight = this.$vuetify.application.bottom + this.$vuetify.application.footer + this.$vuetify.application.bar;
  109. if (!this.clipped) return maxHeight;
  110. return maxHeight + this.$vuetify.application.top;
  111. },
  112. reactsToClick: function reactsToClick() {
  113. return !this.stateless && !this.permanent && (this.isMobile || this.temporary);
  114. },
  115. reactsToMobile: function reactsToMobile() {
  116. return !this.disableResizeWatcher && !this.stateless && !this.permanent && !this.temporary;
  117. },
  118. reactsToRoute: function reactsToRoute() {
  119. return !this.disableRouteWatcher && !this.stateless && (this.temporary || this.isMobile);
  120. },
  121. resizeIsDisabled: function resizeIsDisabled() {
  122. return this.disableResizeWatcher || this.stateless;
  123. },
  124. showOverlay: function showOverlay() {
  125. return this.isActive && (this.isMobile || this.temporary);
  126. },
  127. styles: function styles() {
  128. var styles = {
  129. height: convertToUnit(this.height),
  130. marginTop: this.marginTop + 'px',
  131. maxHeight: this.maxHeight != null ? 'calc(100% - ' + +this.maxHeight + 'px)' : undefined,
  132. transform: 'translateX(' + this.calculatedTransform + 'px)',
  133. width: this.calculatedWidth + 'px'
  134. };
  135. return styles;
  136. }
  137. },
  138. watch: {
  139. $route: function $route() {
  140. if (this.reactsToRoute && this.closeConditional()) {
  141. this.isActive = false;
  142. }
  143. },
  144. isActive: function isActive(val) {
  145. this.$emit('input', val);
  146. this.callUpdate();
  147. },
  148. /**
  149. * When mobile changes, adjust the active state
  150. * only when there has been a previous value
  151. */
  152. isMobile: function isMobile(val, prev) {
  153. !val && this.isActive && !this.temporary && this.removeOverlay();
  154. if (prev == null || this.resizeIsDisabled || !this.reactsToMobile) return;
  155. this.isActive = !val;
  156. this.callUpdate();
  157. },
  158. permanent: function permanent(val) {
  159. // If enabling prop enable the drawer
  160. if (val) {
  161. this.isActive = true;
  162. }
  163. this.callUpdate();
  164. },
  165. showOverlay: function showOverlay(val) {
  166. if (val) this.genOverlay();else this.removeOverlay();
  167. },
  168. temporary: function temporary() {
  169. this.callUpdate();
  170. },
  171. value: function value(val) {
  172. if (this.permanent) return;
  173. // TODO: referring to this directly causes type errors
  174. // all over the place for some reason
  175. var _this = this;
  176. if (val == null) return _this.init();
  177. if (val !== this.isActive) this.isActive = val;
  178. }
  179. },
  180. beforeMount: function beforeMount() {
  181. this.init();
  182. },
  183. methods: {
  184. calculateTouchArea: function calculateTouchArea() {
  185. if (!this.$el.parentNode) return;
  186. var parentRect = this.$el.parentNode.getBoundingClientRect();
  187. this.touchArea = {
  188. left: parentRect.left + 50,
  189. right: parentRect.right - 50
  190. };
  191. },
  192. closeConditional: function closeConditional() {
  193. return this.isActive && this.reactsToClick;
  194. },
  195. genDirectives: function genDirectives() {
  196. var _this2 = this;
  197. var directives = [{
  198. name: 'click-outside',
  199. value: function value() {
  200. return _this2.isActive = false;
  201. },
  202. args: {
  203. closeConditional: this.closeConditional,
  204. include: this.getOpenDependentElements
  205. }
  206. }];
  207. !this.touchless && directives.push({
  208. name: 'touch',
  209. value: {
  210. parent: true,
  211. left: this.swipeLeft,
  212. right: this.swipeRight
  213. }
  214. });
  215. return directives;
  216. },
  217. /**
  218. * Sets state before mount to avoid
  219. * entry transitions in SSR
  220. */
  221. init: function init() {
  222. if (this.permanent) {
  223. this.isActive = true;
  224. } else if (this.stateless || this.value != null) {
  225. this.isActive = this.value;
  226. } else if (!this.temporary) {
  227. this.isActive = !this.isMobile;
  228. }
  229. },
  230. swipeRight: function swipeRight(e) {
  231. if (this.isActive && !this.right) return;
  232. this.calculateTouchArea();
  233. if (Math.abs(e.touchendX - e.touchstartX) < 100) return;
  234. if (!this.right && e.touchstartX <= this.touchArea.left) this.isActive = true;else if (this.right && this.isActive) this.isActive = false;
  235. },
  236. swipeLeft: function swipeLeft(e) {
  237. if (this.isActive && this.right) return;
  238. this.calculateTouchArea();
  239. if (Math.abs(e.touchendX - e.touchstartX) < 100) return;
  240. if (this.right && e.touchstartX >= this.touchArea.right) this.isActive = true;else if (!this.right && this.isActive) this.isActive = false;
  241. },
  242. /**
  243. * Update the application layout
  244. */
  245. updateApplication: function updateApplication() {
  246. return !this.isActive || this.temporary || this.isMobile ? 0 : this.calculatedWidth;
  247. }
  248. },
  249. render: function render(h) {
  250. var _this3 = this;
  251. var data = {
  252. 'class': this.classes,
  253. style: this.styles,
  254. directives: this.genDirectives(),
  255. on: {
  256. click: function click() {
  257. if (!_this3.miniVariant) return;
  258. _this3.$emit('update:miniVariant', false);
  259. },
  260. transitionend: function transitionend(e) {
  261. if (e.target !== e.currentTarget) return;
  262. _this3.$emit('transitionend', e);
  263. // IE11 does not support new Event('resize')
  264. var resizeEvent = document.createEvent('UIEvents');
  265. resizeEvent.initUIEvent('resize', true, false, window, 0);
  266. window.dispatchEvent(resizeEvent);
  267. }
  268. }
  269. };
  270. return h('aside', data, [this.$slots.default, h('div', { 'class': 'v-navigation-drawer__border' })]);
  271. }
  272. });
  273. //# sourceMappingURL=VNavigationDrawer.js.map