Star.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.starProps = exports.default = void 0;
  7. var _vue = require("vue");
  8. var _propsUtil = require("../_util/props-util");
  9. var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));
  10. var starProps = {
  11. value: Number,
  12. index: Number,
  13. prefixCls: String,
  14. allowHalf: {
  15. type: Boolean,
  16. default: undefined
  17. },
  18. disabled: {
  19. type: Boolean,
  20. default: undefined
  21. },
  22. character: _vueTypes.default.any,
  23. characterRender: Function,
  24. focused: {
  25. type: Boolean,
  26. default: undefined
  27. },
  28. count: Number,
  29. onClick: Function,
  30. onHover: Function
  31. };
  32. exports.starProps = starProps;
  33. var _default = (0, _vue.defineComponent)({
  34. compatConfig: {
  35. MODE: 3
  36. },
  37. name: 'Star',
  38. inheritAttrs: false,
  39. props: starProps,
  40. emits: ['hover', 'click'],
  41. setup: function setup(props, _ref) {
  42. var slots = _ref.slots,
  43. emit = _ref.emit;
  44. var onHover = function onHover(e) {
  45. var index = props.index;
  46. emit('hover', e, index);
  47. };
  48. var onClick = function onClick(e) {
  49. var index = props.index;
  50. emit('click', e, index);
  51. };
  52. var onKeyDown = function onKeyDown(e) {
  53. var index = props.index;
  54. if (e.keyCode === 13) {
  55. emit('click', e, index);
  56. }
  57. };
  58. var cls = (0, _vue.computed)(function () {
  59. var prefixCls = props.prefixCls,
  60. index = props.index,
  61. value = props.value,
  62. allowHalf = props.allowHalf,
  63. focused = props.focused;
  64. var starValue = index + 1;
  65. var className = prefixCls;
  66. if (value === 0 && index === 0 && focused) {
  67. className += " ".concat(prefixCls, "-focused");
  68. } else if (allowHalf && value + 0.5 >= starValue && value < starValue) {
  69. className += " ".concat(prefixCls, "-half ").concat(prefixCls, "-active");
  70. if (focused) {
  71. className += " ".concat(prefixCls, "-focused");
  72. }
  73. } else {
  74. className += starValue <= value ? " ".concat(prefixCls, "-full") : " ".concat(prefixCls, "-zero");
  75. if (starValue === value && focused) {
  76. className += " ".concat(prefixCls, "-focused");
  77. }
  78. }
  79. return className;
  80. });
  81. return function () {
  82. var disabled = props.disabled,
  83. prefixCls = props.prefixCls,
  84. characterRender = props.characterRender,
  85. index = props.index,
  86. count = props.count,
  87. value = props.value;
  88. var character = (0, _propsUtil.getPropsSlot)(slots, props, 'character');
  89. var star = (0, _vue.createVNode)("li", {
  90. "class": cls.value
  91. }, [(0, _vue.createVNode)("div", {
  92. "onClick": disabled ? null : onClick,
  93. "onKeydown": disabled ? null : onKeyDown,
  94. "onMousemove": disabled ? null : onHover,
  95. "role": "radio",
  96. "aria-checked": value > index ? 'true' : 'false',
  97. "aria-posinset": index + 1,
  98. "aria-setsize": count,
  99. "tabindex": disabled ? -1 : 0
  100. }, [(0, _vue.createVNode)("div", {
  101. "class": "".concat(prefixCls, "-first")
  102. }, [character]), (0, _vue.createVNode)("div", {
  103. "class": "".concat(prefixCls, "-second")
  104. }, [character])])]);
  105. if (characterRender) {
  106. star = characterRender(star, props);
  107. }
  108. return star;
  109. };
  110. }
  111. });
  112. exports.default = _default;