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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | 51x 51x 176x 51x 51x 51x 51x 51x 51x 51x 129x 51x 51x 51x 51x 51x 129x 3x 126x 121x 51x 51x 51x 51x 51x 51x 51x 51x 51x 23x 58x 142x 3x 139x 136x 51x 51x 51x 51x 7x 51x 7x 51x 7x 51x 7x 51x 51x 51x 14x 51x 14x 51x 51x 13x 51x 14x 51x 13x 51x 13x 51x 14x 14x 51x 51x 51x 51x 50x 14x 13x 13x 13x 156x 157x 161x 518x 522x 537x 537x 51x 50x 50x 50x 50x 40x 40x 40x | <script setup lang="ts">
import { computed } from "vue";
import Skeleton from "../Skeleton.vue";
import type { SkeletonBaseProps } from "../types";
type TableOptions = {
rows?: number;
columns?: number;
columnWidths?: number | string | (number | string)[];
minColumnWidth?: number | string;
rowHeight?: number | string;
/** Width of the decorative bar inside each body cell. Default is a
* single uniform value applied to every cell (not randomized) —
* pass an array to vary it per column, or a single value to change
* the uniform width. */
cellWidths?: number | string | (number | string)[];
align?: "left" | "center" | "right" | ("left" | "center" | "right")[];
padding?: number | string;
gridLines?: boolean;
borderColor?: string;
cellColor?: string;
cellHighlight?: string;
header?: boolean;
headerHeight?: number | string;
headerColor?: string;
headerHighlight?: string;
/** Width of each header bar. Defaults to the same as cellWidths. */
headerWidths?: number | string | (number | string)[];
/* ---------------- Footer (now more flexible) ---------------- */
footer?: boolean;
footerHeight?: number | string;
footerColor?: string;
footerHighlight?: string;
/** Show the label bar on the left side of the footer. Default true. */
footerLabel?: boolean;
/** Width of that label bar. Default "110px". */
footerLabelWidth?: number | string;
/** Number of control blocks (e.g. pagination buttons) on the right. */
footerItems?: number;
/** Width of each control block. Defaults to footerHeight (square). */
footerControlWidth?: number | string;
/** Radius of each control block. Default "6px". */
footerControlRadius?: number | string;
/** How the label and controls are positioned. Default "between". */
footerAlign?: "between" | "start" | "end";
};
const props = defineProps<SkeletonBaseProps>();
const options = computed(() => (props.options ?? {}) as TableOptions);
function toUnit(value: number | string) {
return typeof value === "number" ? `${value}px` : value;
}
/* ---------------- Layout ---------------- */
const rows = computed(() => Math.max(1, options.value.rows ?? 5));
const columns = computed(() => Math.max(1, options.value.columns ?? 4));
const rowHeight = computed(() => toUnit(options.value.rowHeight ?? 16));
const padding = computed(() => toUnit(options.value.padding ?? 12));
const alignments = computed(() => {
const value = options.value.align ?? "left";
return Array.from({ length: columns.value }, (_, index) =>
Array.isArray(value) ? value[index] ?? "left" : value
);
});
const columnTemplate = computed(() => {
const custom = options.value.columnWidths;
const minWidth = options.value.minColumnWidth;
const defaultTrack =
minWidth != null ? `minmax(${toUnit(minWidth)}, 1fr)` : "1fr";
return Array.from({ length: columns.value }, (_, index) => {
if (Array.isArray(custom)) {
return custom[index] != null ? toUnit(custom[index]) : defaultTrack;
}
if (custom != null) return toUnit(custom);
return defaultTrack;
}).join(" ");
});
const gridLines = computed(() => options.value.gridLines ?? true);
const borderColor = computed(
() => options.value.borderColor ?? "rgba(148,163,184,.18)"
);
/* ---------------- Colors ---------------- */
const cellColor = computed(() => options.value.cellColor ?? props.color);
const cellHighlight = computed(
() => options.value.cellHighlight ?? props.highlight
);
const forwardedProps = computed(() => {
const { width, options, ...rest } = props;
return rest;
});
/* ---------------- Bar widths (now uniform by default) ---------------- */
/* Previously this cycled through a preset array of varying percentages
(70%, 95%, 60%, ...), which made cells look randomly sized even when
the user never asked for variety. Now every cell gets the SAME width
unless cellWidths is explicitly given as an array. */
const DEFAULT_CELL_WIDTH = "80%";
function resolveWidths(
custom: number | string | (number | string)[] | undefined,
fallback: string
) {
return Array.from({ length: columns.value }, (_, index) => {
if (Array.isArray(custom)) {
return custom[index] != null ? toUnit(custom[index]) : fallback;
}
if (custom != null) return toUnit(custom);
return fallback;
});
}
const skeletonWidths = computed(() =>
resolveWidths(options.value.cellWidths, DEFAULT_CELL_WIDTH)
);
/* ---------------- Header ---------------- */
const showHeader = computed(() => options.value.header ?? false);
const headerHeight = computed(() =>
toUnit(options.value.headerHeight ?? options.value.rowHeight ?? 14)
);
const headerColor = computed(
() => options.value.headerColor ?? cellColor.value
);
const headerHighlight = computed(
() => options.value.headerHighlight ?? cellHighlight.value
);
const headerWidths = computed(() =>
resolveWidths(options.value.headerWidths ?? options.value.cellWidths, "50%")
);
/* ---------------- Footer ---------------- */
const showFooter = computed(() => options.value.footer ?? false);
const footerHeight = computed(() => toUnit(options.value.footerHeight ?? 28));
const footerColor = computed(
() => options.value.footerColor ?? cellColor.value
);
const footerHighlight = computed(
() => options.value.footerHighlight ?? cellHighlight.value
);
const showFooterLabel = computed(() => options.value.footerLabel ?? true);
const footerLabelWidth = computed(() =>
toUnit(options.value.footerLabelWidth ?? 110)
);
const footerItems = computed(() =>
Math.max(0, options.value.footerItems ?? 3)
);
const footerControlWidth = computed(() =>
toUnit(options.value.footerControlWidth ?? options.value.footerHeight ?? 28)
);
const footerControlRadius = computed(() =>
toUnit(options.value.footerControlRadius ?? 6)
);
const footerJustify = computed(() => {
const align = options.value.footerAlign ?? "between";
return align === "between"
? "space-between"
: align === "end"
? "flex-end"
: "flex-start";
});
/* ---------------- Styles ---------------- */
const tableStyle = computed(() => ({
width:
props.width != null
? typeof props.width === "number"
? `${props.width}px`
: props.width
: undefined,
"--vslk-border-color": borderColor.value,
}));
const rowStyle = computed(() => ({
gridTemplateColumns: columnTemplate.value,
}));
</script>
<template>
<div class="vslk-table-wrapper">
<div class="vslk-table" :style="tableStyle">
<!-- Header -->
<div
v-if="showHeader"
class="vslk-table__row vslk-table__row--header"
:class="{ 'vslk-table__row--grid': gridLines }"
:style="rowStyle"
>
<div
v-for="(width, col) in headerWidths"
:key="col"
class="vslk-table__cell"
:class="`vslk-table__cell--${alignments[col]}`"
:style="{ padding }"
>
<Skeleton
v-bind="forwardedProps"
variant="text"
:width="width"
:height="headerHeight"
:color="headerColor"
:highlight="headerHighlight"
class="vslk-table__skeleton"
/>
</div>
</div>
<!-- Body -->
<div
v-for="row in rows"
:key="row"
class="vslk-table__row"
:class="{ 'vslk-table__row--grid': gridLines }"
:style="rowStyle"
>
<div
v-for="(width, col) in skeletonWidths"
:key="col"
class="vslk-table__cell"
:class="`vslk-table__cell--${alignments[col]}`"
:style="{ padding }"
>
<Skeleton
v-bind="forwardedProps"
variant="text"
:width="width"
:height="rowHeight"
:color="cellColor"
:highlight="cellHighlight"
class="vslk-table__skeleton"
/>
</div>
</div>
<!-- Footer -->
<div
v-if="showFooter"
class="vslk-table__footer"
:style="{ padding, justifyContent: footerJustify }"
>
<Skeleton
v-if="showFooterLabel"
v-bind="forwardedProps"
variant="text"
:width="footerLabelWidth"
:height="footerHeight"
:color="footerColor"
:highlight="footerHighlight"
class="vslk-table__skeleton"
/>
<div v-if="footerItems > 0" class="vslk-table__footer-controls">
<Skeleton
v-for="item in footerItems"
:key="item"
v-bind="forwardedProps"
variant="block"
:width="footerControlWidth"
:height="footerHeight"
:radius="footerControlRadius"
:color="footerColor"
:highlight="footerHighlight"
/>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.vslk-table-wrapper {
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.vslk-table {
display: flex;
flex-direction: column;
width: max-content;
min-width: 100%;
border: 1px solid var(--vslk-border-color);
border-radius: 12px;
overflow: hidden;
box-sizing: border-box;
}
.vslk-table__row {
display: grid;
}
.vslk-table__row:not(:last-child) {
border-bottom: 1px solid var(--vslk-border-color);
}
.vslk-table__row--header {
background: rgba(148, 163, 184, 0.08);
border-bottom-width: 2px;
}
.vslk-table__cell {
display: flex;
align-items: center;
min-width: 0;
box-sizing: border-box;
}
/* Required so percentage cellWidths resolve against the cell's real
width instead of an indefinite flex-item size (see Table debugging
history) — this necessarily makes the wrapper fill the cell, so
alignment can no longer be done via justify-content on the cell
(there's no free space left to justify). Alignment is instead
applied directly on the inner shape via auto margins below, which
works correctly even at 100% wrapper width. */
.vslk-table__cell :deep(.vslk-skeleton-container) {
width: 100%;
}
.vslk-table__skeleton {
max-width: 100%;
}
.vslk-table__cell:not(:last-child) {
border-right: 1px solid var(--vslk-border-color);
}
/* Alignment: margin-auto on the actual bar, not justify-content on the
cell — this is what makes a less-than-100%-wide bar visibly shift
left/center/right within the full-width wrapper. */
.vslk-table__cell--left :deep(.vslk-sk-shape) {
margin-right: auto;
}
.vslk-table__cell--center :deep(.vslk-sk-shape) {
margin-left: auto;
margin-right: auto;
}
.vslk-table__cell--right :deep(.vslk-sk-shape) {
margin-left: auto;
}
.vslk-table__row:not(.vslk-table__row--grid) {
gap: 12px;
}
.vslk-table__row:not(.vslk-table__row--grid) .vslk-table__cell {
border: none;
}
.vslk-table__row:not(.vslk-table__row--grid):not(:last-child) {
border-bottom: none;
}
.vslk-table__footer {
display: flex;
align-items: center;
border-top: 1px solid var(--vslk-border-color);
gap: 12px;
}
.vslk-table__footer-controls {
display: flex;
align-items: center;
gap: 8px;
}
.vslk-table-wrapper::-webkit-scrollbar {
height: 8px;
}
.vslk-table-wrapper::-webkit-scrollbar-thumb {
background: rgba(148, 163, 184, 0.35);
border-radius: 9999px;
}
.vslk-table-wrapper::-webkit-scrollbar-track {
background: transparent;
}
</style> |