cl-badge.uvue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view
  3. class="cl-badge"
  4. :class="[
  5. {
  6. 'bg-primary-500': type == 'primary',
  7. 'bg-green-500': type == 'success',
  8. 'bg-yellow-500': type == 'warn',
  9. 'bg-red-500': type == 'error',
  10. 'bg-surface-500': type == 'info',
  11. 'cl-badge--dot': dot,
  12. 'cl-badge--position': position
  13. },
  14. pt.className
  15. ]"
  16. >
  17. <text class="cl-badge__text" v-if="!dot">
  18. {{ value }}
  19. </text>
  20. <slot></slot>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { computed } from "vue";
  25. import type { PropType } from "vue";
  26. import type { Type } from "../../types";
  27. import { parsePt } from "@/cool";
  28. defineOptions({
  29. name: "cl-badge"
  30. });
  31. const props = defineProps({
  32. pt: {
  33. type: Object,
  34. default: () => ({})
  35. },
  36. type: {
  37. type: String as PropType<Type>,
  38. default: "error"
  39. },
  40. dot: {
  41. type: Boolean,
  42. default: false
  43. },
  44. value: {
  45. type: [Number, String],
  46. default: 0
  47. },
  48. position: {
  49. type: Boolean,
  50. default: false
  51. }
  52. });
  53. type PassThrough = {
  54. className?: string;
  55. };
  56. const pt = computed(() => parsePt<PassThrough>(props.pt));
  57. </script>
  58. <style lang="scss" scoped>
  59. .cl-badge {
  60. @apply flex flex-row items-center justify-center;
  61. @apply rounded-full;
  62. height: 30rpx;
  63. min-width: 30rpx;
  64. padding: 0 6rpx;
  65. &__text {
  66. @apply text-white;
  67. font-size: 18rpx;
  68. }
  69. &--dot {
  70. height: 10rpx;
  71. width: 10rpx;
  72. min-width: 10rpx;
  73. padding: 0;
  74. }
  75. &--position {
  76. @apply absolute z-10 right-0 top-0;
  77. transform: translate(50%, -50%);
  78. &.cl-badge--dot {
  79. transform: translate(-5rpx, 5rpx);
  80. }
  81. }
  82. }
  83. </style>