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.

selectable.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _VInput = require('../components/VInput');
  6. var _VInput2 = _interopRequireDefault(_VInput);
  7. var _rippleable = require('./rippleable');
  8. var _rippleable2 = _interopRequireDefault(_rippleable);
  9. var _comparable = require('./comparable');
  10. var _comparable2 = _interopRequireDefault(_comparable);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /* @vue/component */
  13. // Mixins
  14. exports.default = _VInput2.default.extend({
  15. name: 'selectable',
  16. mixins: [_rippleable2.default, _comparable2.default],
  17. model: {
  18. prop: 'inputValue',
  19. event: 'change'
  20. },
  21. props: {
  22. color: {
  23. type: String,
  24. default: 'accent'
  25. },
  26. id: String,
  27. inputValue: null,
  28. falseValue: null,
  29. trueValue: null,
  30. multiple: {
  31. type: Boolean,
  32. default: null
  33. },
  34. label: String
  35. },
  36. data: function data(vm) {
  37. return {
  38. lazyValue: vm.inputValue
  39. };
  40. },
  41. computed: {
  42. computedColor: function computedColor() {
  43. return this.isActive ? this.color : this.validationState;
  44. },
  45. isMultiple: function isMultiple() {
  46. return this.multiple === true || this.multiple === null && Array.isArray(this.internalValue);
  47. },
  48. isActive: function isActive() {
  49. var _this = this;
  50. var value = this.value;
  51. var input = this.internalValue;
  52. if (this.isMultiple) {
  53. if (!Array.isArray(input)) return false;
  54. return input.some(function (item) {
  55. return _this.valueComparator(item, value);
  56. });
  57. }
  58. if (this.trueValue === undefined || this.falseValue === undefined) {
  59. return value ? this.valueComparator(value, input) : Boolean(input);
  60. }
  61. return this.valueComparator(input, this.trueValue);
  62. },
  63. isDirty: function isDirty() {
  64. return this.isActive;
  65. }
  66. },
  67. watch: {
  68. inputValue: function inputValue(val) {
  69. this.lazyValue = val;
  70. }
  71. },
  72. methods: {
  73. genLabel: function genLabel() {
  74. if (!this.hasLabel) return null;
  75. var label = _VInput2.default.options.methods.genLabel.call(this);
  76. label.data.on = { click: this.onChange };
  77. return label;
  78. },
  79. genInput: function genInput(type, attrs) {
  80. return this.$createElement('input', {
  81. attrs: Object.assign({
  82. 'aria-label': this.label,
  83. 'aria-checked': this.isActive.toString(),
  84. disabled: this.isDisabled,
  85. id: this.id,
  86. role: type,
  87. type: type
  88. }, attrs),
  89. domProps: {
  90. value: this.value,
  91. checked: this.isActive
  92. },
  93. on: {
  94. blur: this.onBlur,
  95. change: this.onChange,
  96. focus: this.onFocus,
  97. keydown: this.onKeydown
  98. },
  99. ref: 'input'
  100. });
  101. },
  102. onBlur: function onBlur() {
  103. this.isFocused = false;
  104. },
  105. onChange: function onChange() {
  106. var _this2 = this;
  107. if (this.isDisabled) return;
  108. var value = this.value;
  109. var input = this.internalValue;
  110. if (this.isMultiple) {
  111. if (!Array.isArray(input)) {
  112. input = [];
  113. }
  114. var length = input.length;
  115. input = input.filter(function (item) {
  116. return !_this2.valueComparator(item, value);
  117. });
  118. if (input.length === length) {
  119. input.push(value);
  120. }
  121. } else if (this.trueValue !== undefined && this.falseValue !== undefined) {
  122. input = this.valueComparator(input, this.trueValue) ? this.falseValue : this.trueValue;
  123. } else if (value) {
  124. input = this.valueComparator(input, value) ? null : value;
  125. } else {
  126. input = !input;
  127. }
  128. this.validate(true, input);
  129. this.internalValue = input;
  130. },
  131. onFocus: function onFocus() {
  132. this.isFocused = true;
  133. },
  134. /** @abstract */
  135. onKeydown: function onKeydown(e) {}
  136. }
  137. }); // Components
  138. //# sourceMappingURL=selectable.js.map