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.

VTabs.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. require('../../../src/stylus/components/_tabs.styl');
  6. var _VItemGroup = require('../VItemGroup/VItemGroup');
  7. var _tabsComputed = require('./mixins/tabs-computed');
  8. var _tabsComputed2 = _interopRequireDefault(_tabsComputed);
  9. var _tabsGenerators = require('./mixins/tabs-generators');
  10. var _tabsGenerators2 = _interopRequireDefault(_tabsGenerators);
  11. var _tabsProps = require('./mixins/tabs-props');
  12. var _tabsProps2 = _interopRequireDefault(_tabsProps);
  13. var _tabsTouch = require('./mixins/tabs-touch');
  14. var _tabsTouch2 = _interopRequireDefault(_tabsTouch);
  15. var _tabsWatchers = require('./mixins/tabs-watchers');
  16. var _tabsWatchers2 = _interopRequireDefault(_tabsWatchers);
  17. var _colorable = require('../../mixins/colorable');
  18. var _colorable2 = _interopRequireDefault(_colorable);
  19. var _ssrBootable = require('../../mixins/ssr-bootable');
  20. var _ssrBootable2 = _interopRequireDefault(_ssrBootable);
  21. var _themeable = require('../../mixins/themeable');
  22. var _themeable2 = _interopRequireDefault(_themeable);
  23. var _resize = require('../../directives/resize');
  24. var _resize2 = _interopRequireDefault(_resize);
  25. var _touch = require('../../directives/touch');
  26. var _touch2 = _interopRequireDefault(_touch);
  27. var _console = require('../../util/console');
  28. var _ThemeProvider = require('../../util/ThemeProvider');
  29. var _ThemeProvider2 = _interopRequireDefault(_ThemeProvider);
  30. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  31. /* @vue/component */
  32. // Directives
  33. // Component level mixins
  34. // Styles
  35. exports.default = _VItemGroup.BaseItemGroup.extend({
  36. name: 'v-tabs',
  37. directives: {
  38. Resize: _resize2.default,
  39. Touch: _touch2.default
  40. },
  41. mixins: [_colorable2.default, _ssrBootable2.default, _tabsComputed2.default, _tabsProps2.default, _tabsGenerators2.default, _tabsTouch2.default, _tabsWatchers2.default, _themeable2.default],
  42. provide: function provide() {
  43. return {
  44. tabGroup: this,
  45. tabProxy: this.tabProxy,
  46. registerItems: this.registerItems,
  47. unregisterItems: this.unregisterItems
  48. };
  49. },
  50. data: function data() {
  51. return {
  52. bar: [],
  53. content: [],
  54. isOverflowing: false,
  55. nextIconVisible: false,
  56. prevIconVisible: false,
  57. resizeTimeout: null,
  58. scrollOffset: 0,
  59. sliderWidth: null,
  60. sliderLeft: null,
  61. startX: 0,
  62. tabItems: null,
  63. transitionTime: 300,
  64. widths: {
  65. bar: 0,
  66. container: 0,
  67. wrapper: 0
  68. }
  69. };
  70. },
  71. watch: {
  72. items: 'onResize',
  73. tabs: 'onResize'
  74. },
  75. mounted: function mounted() {
  76. this.init();
  77. },
  78. methods: {
  79. checkIcons: function checkIcons() {
  80. this.prevIconVisible = this.checkPrevIcon();
  81. this.nextIconVisible = this.checkNextIcon();
  82. },
  83. checkPrevIcon: function checkPrevIcon() {
  84. return this.scrollOffset > 0;
  85. },
  86. checkNextIcon: function checkNextIcon() {
  87. // Check one scroll ahead to know the width of right-most item
  88. return this.widths.container > this.scrollOffset + this.widths.wrapper;
  89. },
  90. callSlider: function callSlider() {
  91. var _this = this;
  92. if (this.hideSlider || !this.activeTab) return false;
  93. // Give screen time to paint
  94. var activeTab = this.activeTab;
  95. this.$nextTick(function () {
  96. /* istanbul ignore if */
  97. if (!activeTab || !activeTab.$el) return;
  98. _this.sliderWidth = activeTab.$el.scrollWidth;
  99. _this.sliderLeft = activeTab.$el.offsetLeft;
  100. });
  101. },
  102. // Do not process
  103. // until DOM is
  104. // painted
  105. init: function init() {
  106. /* istanbul ignore next */
  107. if (this.$listeners['input']) {
  108. (0, _console.deprecate)('@input', '@change', this);
  109. }
  110. },
  111. /**
  112. * When v-navigation-drawer changes the
  113. * width of the container, call resize
  114. * after the transition is complete
  115. */
  116. onResize: function onResize() {
  117. if (this._isDestroyed) return;
  118. this.setWidths();
  119. var delay = this.isBooted ? this.transitionTime : 0;
  120. clearTimeout(this.resizeTimeout);
  121. this.resizeTimeout = setTimeout(this.updateTabsView, delay);
  122. },
  123. overflowCheck: function overflowCheck(e, fn) {
  124. this.isOverflowing && fn(e);
  125. },
  126. scrollTo: function scrollTo(direction) {
  127. this.scrollOffset = this.newOffset(direction);
  128. },
  129. setOverflow: function setOverflow() {
  130. this.isOverflowing = this.widths.bar < this.widths.container;
  131. },
  132. setWidths: function setWidths() {
  133. var bar = this.$refs.bar ? this.$refs.bar.clientWidth : 0;
  134. var container = this.$refs.container ? this.$refs.container.clientWidth : 0;
  135. var wrapper = this.$refs.wrapper ? this.$refs.wrapper.clientWidth : 0;
  136. this.widths = { bar: bar, container: container, wrapper: wrapper };
  137. this.setOverflow();
  138. },
  139. parseNodes: function parseNodes() {
  140. var item = [];
  141. var items = [];
  142. var slider = [];
  143. var tab = [];
  144. var length = (this.$slots.default || []).length;
  145. for (var i = 0; i < length; i++) {
  146. var vnode = this.$slots.default[i];
  147. if (vnode.componentOptions) {
  148. switch (vnode.componentOptions.Ctor.options.name) {
  149. case 'v-tabs-slider':
  150. slider.push(vnode);
  151. break;
  152. case 'v-tabs-items':
  153. items.push(vnode);
  154. break;
  155. case 'v-tab-item':
  156. item.push(vnode);
  157. break;
  158. // case 'v-tab' - intentionally omitted
  159. default:
  160. tab.push(vnode);
  161. }
  162. } else {
  163. tab.push(vnode);
  164. }
  165. }
  166. return { tab: tab, slider: slider, items: items, item: item };
  167. },
  168. registerItems: function registerItems(fn) {
  169. this.tabItems = fn;
  170. fn(this.internalValue);
  171. },
  172. unregisterItems: function unregisterItems() {
  173. this.tabItems = null;
  174. },
  175. updateTabsView: function updateTabsView() {
  176. this.callSlider();
  177. this.scrollIntoView();
  178. this.checkIcons();
  179. },
  180. scrollIntoView: function scrollIntoView() {
  181. /* istanbul ignore next */
  182. if (!this.activeTab) return;
  183. if (!this.isOverflowing) return this.scrollOffset = 0;
  184. var totalWidth = this.widths.wrapper + this.scrollOffset;
  185. var _activeTab$$el = this.activeTab.$el,
  186. clientWidth = _activeTab$$el.clientWidth,
  187. offsetLeft = _activeTab$$el.offsetLeft;
  188. var itemOffset = clientWidth + offsetLeft;
  189. var additionalOffset = clientWidth * 0.3;
  190. if (this.activeTab === this.items[this.items.length - 1]) {
  191. additionalOffset = 0; // don't add an offset if selecting the last tab
  192. }
  193. /* istanbul ignore else */
  194. if (offsetLeft < this.scrollOffset) {
  195. this.scrollOffset = Math.max(offsetLeft - additionalOffset, 0);
  196. } else if (totalWidth < itemOffset) {
  197. this.scrollOffset -= totalWidth - itemOffset - additionalOffset;
  198. }
  199. },
  200. tabProxy: function tabProxy(val) {
  201. this.internalValue = val;
  202. }
  203. },
  204. render: function render(h) {
  205. var _parseNodes = this.parseNodes(),
  206. tab = _parseNodes.tab,
  207. slider = _parseNodes.slider,
  208. items = _parseNodes.items,
  209. item = _parseNodes.item;
  210. return h('div', {
  211. staticClass: 'v-tabs',
  212. directives: [{
  213. name: 'resize',
  214. modifiers: { quiet: true },
  215. value: this.onResize
  216. }]
  217. }, [this.genBar([this.hideSlider ? null : this.genSlider(slider), tab]), h(_ThemeProvider2.default, {
  218. props: { dark: this.theme.isDark, light: !this.theme.isDark }
  219. }, [this.genItems(items, item)])]);
  220. }
  221. });
  222. // Utils
  223. // Mixins
  224. // Extensions
  225. //# sourceMappingURL=VTabs.js.map