cl-list.uvue 2.0 KB

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