badge.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <script>
  2. export default {
  3. name: "LemonBadge",
  4. props: {
  5. count: [Number, Boolean],
  6. overflowCount: {
  7. type: Number,
  8. default: 99
  9. }
  10. },
  11. render() {
  12. return (
  13. <span class="lemon-badge">
  14. {this.$slots.default}
  15. {this.count !== 0 && this.count !== undefined && (
  16. <span
  17. class={[
  18. "lemon-badge__label",
  19. this.isDot && "lemon-badge__label--dot"
  20. ]}
  21. >
  22. {this.label}
  23. </span>
  24. )}
  25. </span>
  26. );
  27. },
  28. computed: {
  29. isDot() {
  30. return this.count === true;
  31. },
  32. label() {
  33. if (this.isDot) return "";
  34. return this.count > this.overflowCount
  35. ? `${this.overflowCount}+`
  36. : this.count;
  37. }
  38. },
  39. methods: {}
  40. };
  41. </script>
  42. <style lang="stylus">
  43. @import '~styles/utils/index'
  44. +b(lemon-badge)
  45. position relative
  46. display inline-block
  47. +e(label)
  48. border-radius 10px
  49. background #f5222d
  50. color #fff
  51. text-align center
  52. font-size 12px
  53. font-weight normal
  54. white-space nowrap
  55. box-shadow 0 0 0 1px #fff
  56. z-index 10
  57. position absolute
  58. transform translateX(50%)
  59. transform-origin 100%
  60. display inline-block
  61. padding 0 4px
  62. height 18px
  63. line-height 17px
  64. min-width 10px
  65. top -4px
  66. right 6px
  67. +m(dot)
  68. width 10px
  69. height 10px
  70. min-width auto
  71. padding 0
  72. top -3px
  73. right 2px
  74. </style>