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.

VExpansionPanel.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. 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; };
  6. require('../../../src/stylus/components/_expansion-panel.styl');
  7. var _themeable = require('../../mixins/themeable');
  8. var _themeable2 = _interopRequireDefault(_themeable);
  9. var _registrable = require('../../mixins/registrable');
  10. var _mixins = require('../../util/mixins');
  11. var _mixins2 = _interopRequireDefault(_mixins);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. /* @vue/component */
  14. exports.default = (0, _mixins2.default)(_themeable2.default, (0, _registrable.provide)('expansionPanel')).extend({
  15. name: 'v-expansion-panel',
  16. provide: function provide() {
  17. return {
  18. expansionPanel: this
  19. };
  20. },
  21. props: {
  22. disabled: Boolean,
  23. readonly: Boolean,
  24. expand: Boolean,
  25. focusable: Boolean,
  26. inset: Boolean,
  27. popout: Boolean,
  28. value: {
  29. type: [Number, Array],
  30. default: function _default() {
  31. return null;
  32. }
  33. }
  34. },
  35. data: function data() {
  36. return {
  37. items: [],
  38. open: []
  39. };
  40. },
  41. computed: {
  42. classes: function classes() {
  43. return _extends({
  44. 'v-expansion-panel--focusable': this.focusable,
  45. 'v-expansion-panel--popout': this.popout,
  46. 'v-expansion-panel--inset': this.inset
  47. }, this.themeClasses);
  48. }
  49. },
  50. watch: {
  51. expand: function expand(v) {
  52. var openIndex = -1;
  53. if (!v) {
  54. // Close all panels unless only one is open
  55. var openCount = this.open.reduce(function (acc, val) {
  56. return val ? acc + 1 : acc;
  57. }, 0);
  58. var open = Array(this.items.length).fill(false);
  59. if (openCount === 1) {
  60. openIndex = this.open.indexOf(true);
  61. }
  62. if (openIndex > -1) {
  63. open[openIndex] = true;
  64. }
  65. this.open = open;
  66. }
  67. this.$emit('input', v ? this.open : openIndex > -1 ? openIndex : null);
  68. },
  69. value: function value(v) {
  70. this.updateFromValue(v);
  71. }
  72. },
  73. mounted: function mounted() {
  74. this.value !== null && this.updateFromValue(this.value);
  75. },
  76. methods: {
  77. updateFromValue: function updateFromValue(v) {
  78. if (Array.isArray(v) && !this.expand) return;
  79. var open = Array(this.items.length).fill(false);
  80. if (typeof v === 'number') {
  81. open[v] = true;
  82. } else if (v !== null) {
  83. open = v;
  84. }
  85. this.updatePanels(open);
  86. },
  87. updatePanels: function updatePanels(open) {
  88. this.open = open;
  89. for (var i = 0; i < this.items.length; i++) {
  90. this.items[i].toggle(open && open[i]);
  91. }
  92. },
  93. panelClick: function panelClick(uid) {
  94. var open = this.expand ? this.open.slice() : Array(this.items.length).fill(false);
  95. for (var i = 0; i < this.items.length; i++) {
  96. if (this.items[i]._uid === uid) {
  97. open[i] = !this.open[i];
  98. !this.expand && this.$emit('input', open[i] ? i : null);
  99. }
  100. }
  101. this.updatePanels(open);
  102. if (this.expand) this.$emit('input', open);
  103. },
  104. register: function register(content) {
  105. var i = this.items.push(content) - 1;
  106. this.value !== null && this.updateFromValue(this.value);
  107. content.toggle(!!this.open[i]);
  108. },
  109. unregister: function unregister(content) {
  110. var index = this.items.findIndex(function (i) {
  111. return i._uid === content._uid;
  112. });
  113. this.items.splice(index, 1);
  114. this.open.splice(index, 1);
  115. }
  116. },
  117. render: function render(h) {
  118. return h('ul', {
  119. staticClass: 'v-expansion-panel',
  120. class: this.classes
  121. }, this.$slots.default);
  122. }
  123. });
  124. //# sourceMappingURL=VExpansionPanel.js.map