Skip to content

Commit 72f7bc9

Browse files
Moving slots into their own files
1 parent 6fc2174 commit 72f7bc9

File tree

1 file changed

+26
-107
lines changed

1 file changed

+26
-107
lines changed

src/plugin/VDrilldownTable.vue

Lines changed: 26 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
:item-title="loadedDrilldown.itemTitle"
1818
:item-value="loadedDrilldown.itemValue"
1919
:items="loadedDrilldown.items"
20+
:items-length="loadedDrilldown.itemsLength"
2021
:items-per-page="loadedDrilldown.itemsPerPage"
21-
:loading="loadedDrilldown.loading"
22-
:loading-text="loadedDrilldown.loadingText"
2322
:multi-sort="loadedDrilldown.multiSort"
2423
:must-sort="loadedDrilldown.mustSort"
2524
:no-filter="loadedDrilldown.noFilter"
@@ -80,48 +79,12 @@
8079
</template>
8180

8281
<!-- ================================================== Headers Slot -->
83-
<!-- ! The headers slot is currently missing the `props` -->
82+
<!-- // ! The headers slot is currently missing the `props` -->
8483
<template #headers>
85-
<tr
86-
class="v-drilldown-table--header-row"
87-
:class="headerRowClasses"
88-
>
89-
<template
90-
v-for="column in loadedDrilldown.headers"
91-
:key="column"
92-
>
93-
<!-- Column TH Slot -->
94-
<slot
95-
v-if="$slots.header"
96-
:column="column"
97-
name="header"
98-
/>
99-
<!-- Column Dynamic Name Header Slot -->
100-
<slot
101-
v-else-if="$slots[`header.${column.key}`]"
102-
:column="column"
103-
:name="`header.${column.key}`"
104-
/>
105-
<!-- Column Render `data-table-expand` -->
106-
<th
107-
v-else-if="column.key === 'data-table-expand'"
108-
class="v-drilldown-table--header-row-th"
109-
:class="headerRowThClasses(column)"
110-
:style="headerRowThStyles(column, true)"
111-
v-html="renderCellHeader(column /* , index */)"
112-
></th>
113-
<!-- Column Render TH -->
114-
<th
115-
v-else
116-
class="v-drilldown-table--header-row-th"
117-
:class="headerRowThClasses(column)"
118-
:style="headerRowThStyles(column)"
119-
v-html="renderCellHeader(column /* , index */)"
120-
></th>
121-
</template>
122-
</tr>
84+
<HeadersSlot :loadedDrilldown="loadedDrilldown" />
12385
</template>
12486

87+
12588
<!-- ================================================== Row Item Slot -->
12689
<template #item="{ columns, index, isExpanded, item, toggleExpand }">
12790
<tr>
@@ -150,16 +113,6 @@
150113
</v-icon>
151114

152115
</td>
153-
<!-- Item Slot -->
154-
<slot
155-
v-else-if="$slots.cell"
156-
:class="column.cellClass"
157-
:column="column"
158-
:index="index"
159-
:item="item"
160-
name="item"
161-
:value="item.raw[column.key]"
162-
/>
163116
<!-- Dynamic Name Item Slot -->
164117
<slot
165118
v-else-if="$slots[`item.${column.key}`]"
@@ -179,8 +132,8 @@
179132
</tr>
180133
</template>
181134

135+
182136
<!-- ================================================== Data Table Expand Slot -->
183-
<!-- @update:expanded="updateExpanded" -->
184137
<template #[`item.data-table-expand`]="{
185138
columns,
186139
index,
@@ -208,6 +161,7 @@
208161

209162
</template>
210163

164+
211165
<!-- ================================================== Expanded Row Slot -->
212166
<template #expanded-row="{ columns, item }">
213167
<tr>
@@ -244,21 +198,27 @@
244198
</template>
245199

246200
<!-- ! This also does not pass rollup bundle -->
247-
<template
201+
<!-- <template
248202
v-for="slot in Object.keys(slots)"
249203
v-slot:[`${slot}`]="scope"
250204
>
251205
<slot
252206
:name="slot"
253207
v-bind="scope"
254208
></slot>
255-
</template>
209+
</template> -->
256210
</VDrilldownTable>
257211
</td>
258212
</tr>
259213
</template>
260214

261215

216+
<!-- ================================================== tfoot Slot -->
217+
<!-- // ! The headers slot is currently missing the `props` -->
218+
<template #tfoot>
219+
<TfootSlot :loadedDrilldown="loadedDrilldown" />
220+
</template>
221+
262222

263223
<!-- ================================================== Footer Prepend Slot -->
264224
<template #[`footer.prepend`]>
@@ -273,29 +233,31 @@
273233
<script setup lang="ts">
274234
import { useTheme } from 'vuetify';
275235
import {
276-
CSSProperties,
277236
computed,
278-
// onBeforeMount,
279237
onMounted,
280238
ref,
281239
StyleValue,
282240
useSlots,
283241
watch,
284242
} from 'vue';
243+
import { componentName } from './utils/globals';
285244
import { AllProps } from './utils/props';
286245
import { useGetLevelColors } from './composables/levelColors';
287246
import {
288-
useConvertToUnit,
289247
useDrilldownDebounce,
290-
useRenderCellHeader,
291248
useRenderCellItem,
292249
useMergeDeep,
293250
} from './composables/helpers';
294251
import {
252+
Column,
295253
DrilldownEvent,
296254
LoadedDrilldown,
297255
SortItem,
298256
} from '@/types/types';
257+
import {
258+
HeadersSlot,
259+
TfootSlot,
260+
} from './components';
299261
300262
301263
@@ -378,7 +340,7 @@ const loadedDrilldown = ref<LoadedDrilldown>({
378340
text: '--v-theme-on-surface',
379341
},
380342
header: {
381-
bg: 'orange',
343+
bg: 'primary',
382344
text: 'on-primary',
383345
},
384346
percentageChange: 25,
@@ -407,10 +369,11 @@ const loadedDrilldown = ref<LoadedDrilldown>({
407369
itemTitle: 'title', // * Works, but is weird
408370
itemValue: 'id', // * Works, but is weird
409371
items: [], // * Works
372+
itemsLength: 0,
410373
itemsPerPage: 10, // * Works
411374
// ! Not working yet `loading` & `loadingText`: https://github.com/vuetifyjs/vuetify/issues/16811 //
412-
loading: false,
413-
loadingText: 'Loading...',
375+
// loading: false,
376+
// loadingText: 'Loading...',
414377
modelValue: [], // ? Needs Testing
415378
multiSort: false, // * Works
416379
mustSort: false, // * Works
@@ -442,7 +405,6 @@ const loadedDrilldown = ref<LoadedDrilldown>({
442405
443406
444407
// -------------------------------------------------- Data //
445-
const componentName = 'v-drilldown-table';
446408
const parentTableRef = ref<string>('');
447409
const levelSearch = ref<string>('');
448410
const theme = useTheme();
@@ -516,44 +478,6 @@ const searchFieldClasses = computed<object>(() => {
516478
return classes;
517479
});
518480
519-
// -------------------------------------------------- Header #
520-
const headerRowClasses = computed<string>(() => {
521-
const classes = `${componentName}--header-row-${loadedDrilldown.value.level}`;
522-
523-
return classes;
524-
});
525-
526-
// TODO: Add column type
527-
const headerRowThClasses = (column): object => {
528-
const classes = {
529-
[`${componentName}--header-row-th-${loadedDrilldown.value.level}`]: true,
530-
[column.cellClass]: column.cellClass,
531-
};
532-
533-
return classes;
534-
};
535-
536-
const headerRowThStyles = (column: { width?: string | number; }, dataTableExpand = false): CSSProperties => {
537-
const headerColors = useGetLevelColors(loadedDrilldown.value, theme, 'header');
538-
539-
const styles = {
540-
backgroundColor: headerColors.bg,
541-
color: headerColors.text,
542-
minWidth: column.width ? useConvertToUnit(column.width) : 'auto',
543-
width: column.width ? useConvertToUnit(column.width) : 'auto',
544-
};
545-
546-
if (dataTableExpand && !column.width) {
547-
styles.width = '48px';
548-
styles.minWidth = '48px';
549-
}
550-
551-
return styles;
552-
};
553-
554-
555-
// -------------------------------------------------- Footer TBD #
556-
557481
558482
// -------------------------------------------------- Methods #
559483
function setLoadedDrilldown(): void {
@@ -586,17 +510,12 @@ function setLoadedDrilldown(): void {
586510
loadedDrilldown.value = useMergeDeep(loadedDrilldown.value, props);
587511
}
588512
589-
function renderCellHeader(column, /* , index */): unknown {
590-
// TODO: This needs to be updated once Vuetify fixes the header slot //
591-
const tempIndex = 0;
592-
return useRenderCellHeader(loadedDrilldown.value, column, tempIndex);
593-
}
594-
595-
function renderCellItem(item, column, index): unknown {
513+
function renderCellItem(item: object, column: Column, index: number): unknown {
596514
return useRenderCellItem(item.raw, column, index);
597515
}
598516
599517
518+
600519
// ------------------------- Table Events //
601520
function drilldownEvent(data: DrilldownEvent): void {
602521
// console.log('1 ---------------------------------------- drilldownEvent', { data });

0 commit comments

Comments
 (0)