uni-badge.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <text v-if="text" :class="inverted ? 'uni-badge-' + type + ' uni-badge--' + size + ' uni-badge-inverted' : 'uni-badge-' + type + ' uni-badge--' + size"
  3. class="uni-badge" @click="onClick()">{{ text }}</text>
  4. </template>
  5. <script>
  6. export default {
  7. name: 'UniBadge',
  8. props: {
  9. type: {
  10. type: String,
  11. default: 'default'
  12. },
  13. inverted: {
  14. type: Boolean,
  15. default: false
  16. },
  17. text: {
  18. type: String,
  19. default: ''
  20. },
  21. size: { // small.normal
  22. type: String,
  23. default: 'normal'
  24. }
  25. },
  26. methods: {
  27. onClick() {
  28. this.$emit('click')
  29. }
  30. }
  31. }
  32. </script>
  33. <style lang="scss">
  34. $bage-size:12px;
  35. $bage-small:scale(0.8);
  36. .uni-badge {
  37. font-family: 'Helvetica Neue', Helvetica, sans-serif;
  38. box-sizing: border-box;
  39. font-size: $bage-size;
  40. line-height: 1;
  41. display: inline-block;
  42. padding: 3px 6px;
  43. color: $uni-text-color;
  44. border-radius: 100px;
  45. background-color: $uni-bg-color-hover;
  46. &.uni-badge-inverted {
  47. padding: 0 5px 0 0;
  48. color: $uni-text-color-grey;
  49. background-color: transparent;
  50. }
  51. &-primary {
  52. color: $uni-text-color-inverse;
  53. background-color: $uni-color-primary;
  54. &.uni-badge-inverted {
  55. color: $uni-color-primary;
  56. background-color: transparent
  57. }
  58. }
  59. &-success {
  60. color: $uni-text-color-inverse;
  61. background-color: $uni-color-success;
  62. &.uni-badge-inverted {
  63. color: $uni-color-success;
  64. background-color: transparent
  65. }
  66. }
  67. &-warning {
  68. color: $uni-text-color-inverse;
  69. background-color: $uni-color-warning;
  70. &.uni-badge-inverted {
  71. color: $uni-color-warning;
  72. background-color: transparent
  73. }
  74. }
  75. &-error {
  76. color: $uni-text-color-inverse;
  77. background-color: $uni-color-error;
  78. &.uni-badge-inverted {
  79. color: $uni-color-error;
  80. background-color: transparent
  81. }
  82. }
  83. &--small {
  84. transform: $bage-small;
  85. transform-origin: center center;
  86. }
  87. }
  88. </style>