cl-list.uvue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view
  3. class="cl-list dark:!border-surface-700"
  4. :class="[
  5. {
  6. 'cl-list--border': border
  7. },
  8. pt.className
  9. ]"
  10. >
  11. <slot name="header">
  12. <text class="cl-list__title" v-if="title != ''">{{ title }}</text>
  13. </slot>
  14. <view class="cl-list__items">
  15. <view v-for="(item, index) in list" :key="index">
  16. <cl-list-item
  17. :icon="item.icon"
  18. :label="item.label"
  19. :arrow="item.arrow"
  20. :hoverable="item.hoverable"
  21. :pt="{
  22. className: `bg-white dark:!bg-surface-700 ${pt.item?.className}`,
  23. inner: pt.item?.inner,
  24. label: pt.item?.label,
  25. content: pt.item?.content,
  26. icon: pt.item?.icon
  27. }"
  28. >
  29. <slot name="item" :item="item">
  30. <cl-text>{{ item.content }}</cl-text>
  31. </slot>
  32. </cl-list-item>
  33. <view class="cl-list__line" v-if="index != list.length - 1">
  34. <view class="cl-list__line-inner"></view>
  35. </view>
  36. </view>
  37. <slot></slot>
  38. </view>
  39. </view>
  40. </template>
  41. <script lang="ts" setup>
  42. import type { ClListItem, PassThroughProps } from "../../types";
  43. import type { ClListItemPassThrough } from "../cl-list-item/props";
  44. import { computed, type PropType } from "vue";
  45. import { parsePt } from "@/cool";
  46. defineOptions({
  47. name: "cl-list"
  48. });
  49. defineSlots<{
  50. header(): any;
  51. item(props: { item: ClListItem }): any;
  52. }>();
  53. const props = defineProps({
  54. pt: {
  55. type: Object,
  56. default: () => ({})
  57. },
  58. list: {
  59. type: Array as PropType<ClListItem[]>,
  60. default: () => []
  61. },
  62. title: {
  63. type: String,
  64. default: ""
  65. },
  66. border: {
  67. type: Boolean,
  68. default: false
  69. }
  70. });
  71. type PassThrough = {
  72. className?: string;
  73. list?: PassThroughProps;
  74. item?: ClListItemPassThrough;
  75. };
  76. const pt = computed(() => parsePt<PassThrough>(props.pt));
  77. </script>
  78. <style lang="scss" scoped>
  79. .cl-list {
  80. @apply duration-200;
  81. transition-property: border-color, background-color;
  82. &__title {
  83. @apply text-surface-500 text-sm pb-2;
  84. padding-left: 24rpx;
  85. }
  86. &__items {
  87. @apply rounded-2xl overflow-hidden;
  88. }
  89. &__line {
  90. padding: 0 24rpx;
  91. &-inner {
  92. @apply bg-surface-50 w-full;
  93. height: 1rpx;
  94. }
  95. }
  96. &--border {
  97. @apply border border-solid border-surface-200 rounded-2xl;
  98. }
  99. }
  100. </style>