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.

VOverflowBtn.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Styles
  2. import '../../../src/stylus/components/_overflow-buttons.styl';
  3. // Extensions
  4. import VSelect from '../VSelect/VSelect';
  5. import VAutocomplete from '../VAutocomplete';
  6. import VTextField from '../VTextField/VTextField';
  7. import VBtn from '../VBtn';
  8. import { consoleWarn } from '../../util/console';
  9. /* @vue/component */
  10. export default VAutocomplete.extend({
  11. name: 'v-overflow-btn',
  12. props: {
  13. segmented: Boolean,
  14. editable: Boolean,
  15. transition: VSelect.options.props.transition
  16. },
  17. computed: {
  18. classes: function classes() {
  19. return Object.assign(VAutocomplete.options.computed.classes.call(this), {
  20. 'v-overflow-btn': true,
  21. 'v-overflow-btn--segmented': this.segmented,
  22. 'v-overflow-btn--editable': this.editable
  23. });
  24. },
  25. isAnyValueAllowed: function isAnyValueAllowed() {
  26. return this.editable || VAutocomplete.options.computed.isAnyValueAllowed.call(this);
  27. },
  28. isSingle: function isSingle() {
  29. return true;
  30. },
  31. computedItems: function computedItems() {
  32. return this.segmented ? this.allItems : this.filteredItems;
  33. },
  34. $_menuProps: function $_menuProps() {
  35. var props = VAutocomplete.options.computed.$_menuProps.call(this);
  36. props.transition = props.transition || 'v-menu-transition';
  37. return props;
  38. }
  39. },
  40. methods: {
  41. genSelections: function genSelections() {
  42. return this.editable ? VAutocomplete.options.methods.genSelections.call(this) : VSelect.options.methods.genSelections.call(this); // Override v-autocomplete's override
  43. },
  44. genCommaSelection: function genCommaSelection(item, index, last) {
  45. return this.segmented ? this.genSegmentedBtn(item) : VSelect.options.methods.genCommaSelection.call(this, item, index, last);
  46. },
  47. genInput: function genInput() {
  48. var input = VTextField.options.methods.genInput.call(this);
  49. input.data.domProps.value = this.editable ? this.internalSearch : '';
  50. input.data.attrs.readonly = !this.isAnyValueAllowed;
  51. return input;
  52. },
  53. genLabel: function genLabel() {
  54. if (this.editable && this.isFocused) return null;
  55. var label = VTextField.options.methods.genLabel.call(this);
  56. if (!label) return label;
  57. // Reset previously set styles from parent
  58. label.data.style = {};
  59. return label;
  60. },
  61. genSegmentedBtn: function genSegmentedBtn(item) {
  62. var _this = this;
  63. var itemValue = this.getValue(item);
  64. var itemObj = this.computedItems.find(function (i) {
  65. return _this.getValue(i) === itemValue;
  66. }) || item;
  67. if (!itemObj.text || !itemObj.callback) {
  68. consoleWarn('When using \'segmented\' prop without a selection slot, items must contain both a text and callback property', this);
  69. return null;
  70. }
  71. return this.$createElement(VBtn, {
  72. props: { flat: true },
  73. on: {
  74. click: function click(e) {
  75. e.stopPropagation();
  76. itemObj.callback(e);
  77. }
  78. }
  79. }, [itemObj.text]);
  80. }
  81. }
  82. });
  83. //# sourceMappingURL=VOverflowBtn.js.map