index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _utils = require("../utils");
  5. var _number = require("../utils/validate/number");
  6. var _createNamespace = (0, _utils.createNamespace)('badge'),
  7. createComponent = _createNamespace[0],
  8. bem = _createNamespace[1];
  9. var _default = createComponent({
  10. props: {
  11. dot: Boolean,
  12. max: [Number, String],
  13. color: String,
  14. content: [Number, String],
  15. tag: {
  16. type: String,
  17. default: 'div'
  18. }
  19. },
  20. methods: {
  21. hasContent: function hasContent() {
  22. return !!(this.$scopedSlots.content || (0, _utils.isDef)(this.content) && this.content !== '');
  23. },
  24. renderContent: function renderContent() {
  25. var dot = this.dot,
  26. max = this.max,
  27. content = this.content;
  28. if (!dot && this.hasContent()) {
  29. if (this.$scopedSlots.content) {
  30. return this.$scopedSlots.content();
  31. }
  32. if ((0, _utils.isDef)(max) && (0, _number.isNumeric)(content) && +content > max) {
  33. return max + "+";
  34. }
  35. return content;
  36. }
  37. },
  38. renderBadge: function renderBadge() {
  39. var h = this.$createElement;
  40. if (this.hasContent() || this.dot) {
  41. return h("div", {
  42. "class": bem({
  43. dot: this.dot,
  44. fixed: !!this.$scopedSlots.default
  45. }),
  46. "style": {
  47. background: this.color
  48. }
  49. }, [this.renderContent()]);
  50. }
  51. }
  52. },
  53. render: function render() {
  54. var h = arguments[0];
  55. if (this.$scopedSlots.default) {
  56. var tag = this.tag;
  57. return h(tag, {
  58. "class": bem('wrapper')
  59. }, [this.$scopedSlots.default(), this.renderBadge()]);
  60. }
  61. return this.renderBadge();
  62. }
  63. });
  64. exports.default = _default;