Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | 34x 34x 34x 34x 34x 33x 33x 34x 33x 33x 34x 34x 34x 34x 33x 33x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 181x 94x 8x 8x 34x 33x 86x 87x 90x 90x 90x 90x 174x 177x 181x | <script setup lang="ts">
import { computed } from "vue";
import Skeleton from "../Skeleton.vue";
import type { SkeletonBaseProps } from "../types";
type ListOptions = {
items?: number;
dot?: boolean;
dotSize?: number | string;
dotRadius?: number | string;
lines?: number;
titleWidth?: number | string;
subtitleWidth?: number | string;
lineHeight?: number | string;
itemGap?: number | string;
contentGap?: number | string;
padding?: number | string;
divider?: boolean;
borderColor?: string;
};
const props = defineProps<SkeletonBaseProps>();
const options = computed(() => (props.options ?? {}) as ListOptions);
const items = computed(() => Math.max(1, options.value.items ?? 4));
const dot = computed(() => options.value.dot ?? true);
const dotSize = computed(() => {
const v = options.value.dotSize ?? 8;
return typeof v === "number" ? `${v}px` : v;
});
const dotRadius = computed(() => {
const v = options.value.dotRadius ?? "9999px";
return typeof v === "number" ? `${v}px` : v;
});
const lines = computed(() => Math.max(0, options.value.lines ?? 2));
const titleWidth = computed(() => options.value.titleWidth ?? "68%");
const subtitleWidth = computed(() => options.value.subtitleWidth ?? "52%");
const lineHeight = computed(() => {
const v = options.value.lineHeight ?? "12px";
return typeof v === "number" ? `${v}px` : v;
});
const itemGap = computed(() => {
const v = options.value.itemGap ?? "12px";
return typeof v === "number" ? `${v}px` : v;
});
const contentGap = computed(() => {
const v = options.value.contentGap ?? "8px";
return typeof v === "number" ? `${v}px` : v;
});
const padding = computed(() => {
const v = options.value.padding ?? "12px 0";
return typeof v === "number" ? `${v}px` : v;
});
const divider = computed(() => options.value.divider ?? false);
const borderColor = computed(
() => options.value.borderColor ?? "rgba(148, 163, 184, 0.18)"
);
const containerWidth = computed(() =>
typeof props.width === "number" ? `${props.width}px` : props.width ?? "100%"
);
/* Exclude props that are explicitly re-bound per nested element (width,
height via dotSize/lineHeight, size, lines via options.lines) so a
stray top-level value passed to <Skeleton variant="list"> can never
leak into the nested marker/text calls — e.g. a top-level `lines`
prop would otherwise be forwarded into every item's text-line
Skeleton and make each one recursively multi-line. */
const forwardedProps = computed(() => {
const { width, options, size, lines: topLevelLines, ...rest } = props;
return rest;
});
function getLineWidth(itemIndex: number, lineIndex: number) {
if (lineIndex === 0) return titleWidth.value;
if (lineIndex === 1) return subtitleWidth.value;
const presets = ["90%", "75%", "62%", "84%", "70%"];
return presets[(itemIndex + lineIndex) % presets.length];
}
const itemAlign = computed(() => (lines.value <= 1 ? "center" : "flex-start"));
</script>
<template>
<div class="vslk-list" :style="{ width: containerWidth, gap: itemGap }">
<div
v-for="item in items"
:key="item"
class="vslk-list__item"
:class="{ 'vslk-list__item--divider': divider && item !== items }"
:style="{
padding,
borderBottomColor: borderColor,
alignItems: itemAlign,
}"
>
<div v-if="dot" class="vslk-list__marker">
<Skeleton
v-bind="forwardedProps"
variant="block"
:width="dotSize"
:height="dotSize"
:radius="dotRadius"
/>
</div>
<div class="vslk-list__content" :style="{ gap: contentGap }">
<Skeleton
v-for="line in lines"
:key="line"
v-bind="forwardedProps"
variant="text"
:width="getLineWidth(item - 1, line - 1)"
:height="lineHeight"
/>
</div>
</div>
</div>
</template>
<style scoped>
.vslk-list {
display: flex;
flex-direction: column;
box-sizing: border-box;
min-width: 0;
}
.vslk-list__item {
display: flex;
gap: 12px;
min-width: 0;
box-sizing: border-box;
}
.vslk-list__item--divider {
border-bottom: 1px solid;
}
.vslk-list__marker {
flex: 0 0 auto;
display: flex;
align-items: center;
padding-top: 1px;
}
.vslk-list__content {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
}
</style> |