|
1 | 1 | <template>
|
2 |
| - <b-table-simple v-bind="tableProps"> |
3 |
| - <thead v-if="!hideHeaderBoolean"> |
4 |
| - <tr> |
5 |
| - <th v-for="(_, i) in headerColumns ?? columns" :key="i"> |
6 |
| - <b-placeholder v-bind="placeholderAttrs" :width="headerWidth" /> |
7 |
| - </th> |
8 |
| - </tr> |
9 |
| - </thead> |
10 |
| - <tbody> |
11 |
| - <tr v-for="(_, j) in rows" :key="j"> |
12 |
| - <td v-for="(__, k) in columns" :key="k"> |
13 |
| - <b-placeholder v-bind="placeholderAttrs" :width="cellWidth" /> |
14 |
| - </td> |
15 |
| - </tr> |
16 |
| - </tbody> |
17 |
| - <tfoot v-if="showFooterBoolean"> |
18 |
| - <tr> |
19 |
| - <th v-for="(_, l) in footerColumns ?? columns" :key="l"> |
20 |
| - <b-placeholder v-bind="placeholderAttrs" :width="footerWidth" /> |
21 |
| - </th> |
22 |
| - </tr> |
23 |
| - </tfoot> |
| 2 | + <b-table-simple> |
| 3 | + <slot name="thead"> |
| 4 | + <thead v-if="!hideHeaderBoolean"> |
| 5 | + <tr> |
| 6 | + <th v-for="(_, i) in headerColumns ?? columns" :key="i"> |
| 7 | + <b-placeholder v-bind="headerAttrs" /> |
| 8 | + </th> |
| 9 | + </tr> |
| 10 | + </thead> |
| 11 | + </slot> |
| 12 | + <slot> |
| 13 | + <tbody> |
| 14 | + <tr v-for="(_, j) in rows" :key="j"> |
| 15 | + <td v-for="(__, k) in columns" :key="k"> |
| 16 | + <b-placeholder v-bind="placeholderAttrs" /> |
| 17 | + </td> |
| 18 | + </tr> |
| 19 | + </tbody> |
| 20 | + </slot> |
| 21 | + <slot name="tfoot"> |
| 22 | + <tfoot v-if="showFooterBoolean"> |
| 23 | + <tr> |
| 24 | + <th v-for="(_, l) in footerColumns ?? columns" :key="l"> |
| 25 | + <b-placeholder v-bind="footerAttrs" /> |
| 26 | + </th> |
| 27 | + </tr> |
| 28 | + </tfoot> |
| 29 | + </slot> |
24 | 30 | </b-table-simple>
|
25 | 31 | </template>
|
26 | 32 |
|
27 | 33 | <script setup lang="ts">
|
28 | 34 | // import type {BSkeletonTableProps} from '../../types/components'
|
29 | 35 | import {computed, toRef} from 'vue'
|
30 |
| -import type {Booleanish, ColorVariant} from '../../types' |
| 36 | +import type {Booleanish, ColorVariant, PlaceholderAnimation, PlaceholderSize} from '../../types' |
31 | 37 | import {useBooleanish} from '../../composables'
|
32 | 38 | import BTableSimple from '../BTable/BTableSimple.vue'
|
33 | 39 | import BPlaceholder from './BPlaceholder.vue'
|
34 | 40 |
|
35 | 41 | interface BSkeletonTableProps {
|
36 |
| - animation?: 'wave' | 'glow' |
37 |
| - columns?: number |
38 |
| - hideHeader?: Booleanish |
39 | 42 | rows?: number
|
40 |
| - showFooter?: Booleanish |
41 |
| - variant?: ColorVariant |
42 |
| - size?: 'xs' | 'sm' | 'lg' |
43 |
| - tableProps?: Record<string, unknown> |
44 |
| - footerWidth?: string | number |
45 |
| - headerWidth?: string | number |
| 43 | +
|
| 44 | + columns?: number |
46 | 45 | cellWidth?: string | number
|
| 46 | + size?: PlaceholderSize |
| 47 | + animation?: PlaceholderAnimation |
| 48 | + variant?: ColorVariant |
| 49 | +
|
47 | 50 | headerColumns?: number
|
| 51 | + hideHeader?: Booleanish |
| 52 | + headerCellWidth?: string | number |
| 53 | + headerSize?: PlaceholderSize |
| 54 | + headerAnimation?: PlaceholderAnimation |
| 55 | + headerVariant?: ColorVariant |
| 56 | +
|
48 | 57 | footerColumns?: number
|
| 58 | + showFooter?: Booleanish |
| 59 | + footerCellWidth?: string | number |
| 60 | + footerSize?: PlaceholderSize |
| 61 | + footerAnimation?: PlaceholderAnimation |
| 62 | + footerVariant?: ColorVariant |
49 | 63 | }
|
50 | 64 |
|
51 | 65 | const props = withDefaults(defineProps<BSkeletonTableProps>(), {
|
52 | 66 | columns: 5,
|
53 |
| - hideHeader: false, |
54 | 67 | rows: 3,
|
55 |
| - showFooter: false, |
56 | 68 | cellWidth: 100,
|
57 |
| - footerWidth: 100, |
58 |
| - headerWidth: 100, |
| 69 | + showFooter: false, |
| 70 | + footerCellWidth: 100, |
| 71 | + hideHeader: false, |
| 72 | + headerCellWidth: 100, |
59 | 73 | })
|
60 | 74 |
|
61 | 75 | const placeholderAttrs = computed(() => ({
|
62 | 76 | size: props.size,
|
63 | 77 | variant: props.variant,
|
64 | 78 | animation: props.animation,
|
| 79 | + width: props.cellWidth, |
| 80 | +})) |
| 81 | +
|
| 82 | +const headerAttrs = computed(() => ({ |
| 83 | + size: props.headerSize, |
| 84 | + variant: props.headerVariant, |
| 85 | + animation: props.headerAnimation, |
| 86 | + width: props.headerCellWidth, |
| 87 | +})) |
| 88 | +
|
| 89 | +const footerAttrs = computed(() => ({ |
| 90 | + size: props.footerSize, |
| 91 | + variant: props.footerVariant, |
| 92 | + animation: props.footerAnimation, |
| 93 | + width: props.footerCellWidth, |
65 | 94 | }))
|
66 | 95 |
|
67 | 96 | const hideHeaderBoolean = useBooleanish(toRef(props, 'hideHeader'))
|
|
0 commit comments