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.

VRating.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. require('../../../src/stylus/components/_rating.styl');
  6. var _VIcon = require('../VIcon');
  7. var _VIcon2 = _interopRequireDefault(_VIcon);
  8. var _colorable = require('../../mixins/colorable');
  9. var _colorable2 = _interopRequireDefault(_colorable);
  10. var _delayable = require('../../mixins/delayable');
  11. var _delayable2 = _interopRequireDefault(_delayable);
  12. var _sizeable = require('../../mixins/sizeable');
  13. var _sizeable2 = _interopRequireDefault(_sizeable);
  14. var _rippleable = require('../../mixins/rippleable');
  15. var _rippleable2 = _interopRequireDefault(_rippleable);
  16. var _themeable = require('../../mixins/themeable');
  17. var _themeable2 = _interopRequireDefault(_themeable);
  18. var _helpers = require('../../util/helpers');
  19. var _mixins = require('../../util/mixins');
  20. var _mixins2 = _interopRequireDefault(_mixins);
  21. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22. /* @vue/component */
  23. // Utilities
  24. // Components
  25. exports.default = (0, _mixins2.default)(_colorable2.default, _delayable2.default, _rippleable2.default, _sizeable2.default, _themeable2.default).extend({
  26. name: 'v-rating',
  27. props: {
  28. backgroundColor: {
  29. type: String,
  30. default: 'accent'
  31. },
  32. color: {
  33. type: String,
  34. default: 'primary'
  35. },
  36. dense: Boolean,
  37. emptyIcon: {
  38. type: String,
  39. default: '$vuetify.icons.ratingEmpty'
  40. },
  41. fullIcon: {
  42. type: String,
  43. default: '$vuetify.icons.ratingFull'
  44. },
  45. halfIcon: {
  46. type: String,
  47. default: '$vuetify.icons.ratingHalf'
  48. },
  49. halfIncrements: Boolean,
  50. length: {
  51. type: [Number, String],
  52. default: 5
  53. },
  54. clearable: Boolean,
  55. readonly: Boolean,
  56. hover: Boolean,
  57. value: {
  58. type: Number,
  59. default: 0
  60. }
  61. },
  62. data: function data() {
  63. return {
  64. hoverIndex: -1,
  65. internalValue: this.value
  66. };
  67. },
  68. computed: {
  69. directives: function directives() {
  70. if (this.readonly || !this.ripple) return [];
  71. return [{
  72. name: 'ripple',
  73. value: { circle: true }
  74. }];
  75. },
  76. iconProps: function iconProps() {
  77. var _$props = this.$props,
  78. dark = _$props.dark,
  79. medium = _$props.medium,
  80. large = _$props.large,
  81. light = _$props.light,
  82. small = _$props.small,
  83. size = _$props.size,
  84. xLarge = _$props.xLarge;
  85. return {
  86. dark: dark,
  87. medium: medium,
  88. large: large,
  89. light: light,
  90. size: size,
  91. small: small,
  92. xLarge: xLarge
  93. };
  94. },
  95. isHovering: function isHovering() {
  96. return this.hover && this.hoverIndex >= 0;
  97. }
  98. },
  99. watch: {
  100. internalValue: function internalValue(val) {
  101. val !== this.value && this.$emit('input', val);
  102. },
  103. value: function value(val) {
  104. this.internalValue = val;
  105. }
  106. },
  107. methods: {
  108. createClickFn: function createClickFn(i) {
  109. var _this = this;
  110. return function (e) {
  111. if (_this.readonly) return;
  112. var newValue = _this.genHoverIndex(e, i);
  113. if (_this.clearable && _this.internalValue === newValue) {
  114. _this.internalValue = 0;
  115. } else {
  116. _this.internalValue = newValue;
  117. }
  118. };
  119. },
  120. createProps: function createProps(i) {
  121. var props = {
  122. index: i,
  123. value: this.internalValue,
  124. click: this.createClickFn(i),
  125. isFilled: Math.floor(this.internalValue) > i,
  126. isHovered: Math.floor(this.hoverIndex) > i
  127. };
  128. if (this.halfIncrements) {
  129. props.isHalfHovered = !props.isHovered && (this.hoverIndex - i) % 1 > 0;
  130. props.isHalfFilled = !props.isFilled && (this.internalValue - i) % 1 > 0;
  131. }
  132. return props;
  133. },
  134. genHoverIndex: function genHoverIndex(e, i) {
  135. return i + (this.isHalfEvent(e) ? 0.5 : 1);
  136. },
  137. getIconName: function getIconName(props) {
  138. var isFull = this.isHovering ? props.isHovered : props.isFilled;
  139. var isHalf = this.isHovering ? props.isHalfHovered : props.isHalfFilled;
  140. return isFull ? this.fullIcon : isHalf ? this.halfIcon : this.emptyIcon;
  141. },
  142. getColor: function getColor(props) {
  143. if (this.isHovering) {
  144. if (props.isHovered || props.isHalfHovered) return this.color;
  145. } else {
  146. if (props.isFilled || props.isHalfFilled) return this.color;
  147. }
  148. return this.backgroundColor;
  149. },
  150. isHalfEvent: function isHalfEvent(e) {
  151. if (this.halfIncrements) {
  152. var rect = e.target && e.target.getBoundingClientRect();
  153. if (rect && e.pageX - rect.left < rect.width / 2) return true;
  154. }
  155. return false;
  156. },
  157. onMouseEnter: function onMouseEnter(e, i) {
  158. var _this2 = this;
  159. this.runDelay('open', function () {
  160. _this2.hoverIndex = _this2.genHoverIndex(e, i);
  161. });
  162. },
  163. onMouseLeave: function onMouseLeave() {
  164. var _this3 = this;
  165. this.runDelay('close', function () {
  166. return _this3.hoverIndex = -1;
  167. });
  168. },
  169. genItem: function genItem(i) {
  170. var _this4 = this;
  171. var props = this.createProps(i);
  172. if (this.$scopedSlots.item) return this.$scopedSlots.item(props);
  173. var listeners = {
  174. click: props.click
  175. };
  176. if (this.hover) {
  177. listeners.mouseenter = function (e) {
  178. return _this4.onMouseEnter(e, i);
  179. };
  180. listeners.mouseleave = this.onMouseLeave;
  181. if (this.halfIncrements) {
  182. listeners.mousemove = function (e) {
  183. return _this4.onMouseEnter(e, i);
  184. };
  185. }
  186. }
  187. return this.$createElement(_VIcon2.default, this.setTextColor(this.getColor(props), {
  188. directives: this.directives,
  189. props: this.iconProps,
  190. on: listeners
  191. }), [this.getIconName(props)]);
  192. }
  193. },
  194. render: function render(h) {
  195. var _this5 = this;
  196. var children = (0, _helpers.createRange)(Number(this.length)).map(function (i) {
  197. return _this5.genItem(i);
  198. });
  199. return h('div', {
  200. staticClass: 'v-rating',
  201. class: {
  202. 'v-rating--readonly': this.readonly,
  203. 'v-rating--dense': this.dense
  204. }
  205. }, children);
  206. }
  207. });
  208. // Mixins
  209. // Styles
  210. //# sourceMappingURL=VRating.js.map