index.sjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function setPositionStyle(position) {
  2. var offsetX = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-50%';
  3. var offsetY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '-50%';
  4. var transformStyle = "transform: translate(calc(".concat(offsetX, "), calc(").concat(offsetY, "));");
  5. switch (position) {
  6. case 'top-left':
  7. return "top: 0; left: 0; ".concat(transformStyle);
  8. case 'top-center':
  9. return "top: 0; left: 50%; ".concat(transformStyle);
  10. case 'top-right':
  11. return "top: 0; left: 100%; ".concat(transformStyle);
  12. case 'left':
  13. return "top: 50%; left: 0; ".concat(transformStyle);
  14. case 'right':
  15. return "top: 50%; left: 100%; ".concat(transformStyle);
  16. case 'bottom-left':
  17. return "top: 100%; left: 0; ".concat(transformStyle);
  18. case 'bottom-center':
  19. return "top: 100%; left: 50%; ".concat(transformStyle);
  20. case 'bottom-right':
  21. return "top: 100%; left: 100%; ".concat(transformStyle);
  22. default:
  23. return "top: 0; left: 0; ".concat(transformStyle);
  24. }
  25. }
  26. function setBubbleStyle(type, position) {
  27. if (type !== 'bubble') return '';
  28. switch (position) {
  29. case 'top-left':
  30. return 'border-bottom-right-radius: 0;';
  31. case 'top-right':
  32. return 'border-bottom-left-radius: 0;';
  33. case 'bottom-left':
  34. return 'border-top-right-radius: 0;';
  35. case 'bottom-right':
  36. return 'border-top-left-radius: 0;';
  37. default:
  38. return '';
  39. }
  40. }
  41. function getOverCount(text) {
  42. var overCount = false;
  43. if (typeof text === 'number') {
  44. if (text >= 100) {
  45. overCount = true;
  46. }
  47. }
  48. return overCount;
  49. }
  50. export default {
  51. setPositionStyle: setPositionStyle,
  52. setBubbleStyle: setBubbleStyle,
  53. getOverCount: getOverCount
  54. };