项目原始demo,不改动
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
Den här utvecklingskatalogen är arkiverad. Du kan se filer och klona katalogen, men inte öppna ärenden eller genomföra push- eller pull-förfrågningar.

VRating.js 6.3 KiB

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