Skip to content

Commit

Permalink
Support for message in empty table body (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
jardakotesovec authored Aug 28, 2024
1 parent c42ffaf commit c006bca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 65 deletions.
64 changes: 4 additions & 60 deletions src/components/TableNext/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</template>

<script setup>
import {provide, toRefs, defineEmits} from 'vue';
import {provide, toRefs, defineEmits, ref} from 'vue';
const emit = defineEmits([
/**
Expand All @@ -32,69 +32,13 @@ const props = defineProps({
const {sortDescriptor} = toRefs(props);
const columnsCount = ref(0);
const tableContext = {
sortDescriptor,
onSort,
columnsCount,
};
provide('tableContext', tableContext);
</script>

<style lang="less">
@import '../../styles/_import';
.pkpTableNext {
width: 100%;
max-width: 100%;
border: @grid-border;
border-collapse: collapse;
border-radius: 10px;
font-size: @font-sml;
line-height: 1.2em;
td,
th {
padding: 0.5rem 1rem;
font-weight: @normal;
text-align: inherit;
&:focus {
outline: 0;
box-shadow: inset 0 0 0 1px @primary;
}
}
tr {
&:nth-child(even) {
background: @bg-very-light;
}
}
thead {
tr {
background: @table-header;
}
th {
font-size: @font-tiny;
font-weight: @semibold;
text-transform: uppercase;
}
}
}
[dir='rtl'] {
.pkpTable {
thead {
.pkpTable__sortIcon {
right: auto;
left: 4px;
}
}
}
}
.pkpTable + .pkpPagination {
margin-top: 1rem;
}
</style>
36 changes: 35 additions & 1 deletion src/components/TableNext/TableBody.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
<template>
<tbody class=""><slot></slot></tbody>
<tbody class="">
<slot></slot>
<tr v-if="noContent" class="">
<td
:colspan="tableContext.columnsCount.value"
class="border-x border-b border-light p-4 text-center text-base-normal"
>
{{ emptyText }}
</td>
</tr>
</tbody>
</template>

<script setup>
import {useSlots, computed, inject} from 'vue';
import {useLocalize} from '@/composables/useLocalize';
const props = defineProps({
emptyText: {type: String, default: ''},
});
const slots = useSlots();
const {t} = useLocalize();
const tableContext = inject('tableContext');
const noContent = computed(() => {
const defaultSlot = slots.default();
return !defaultSlot?.[0]?.children?.length;
});
const emptyText = computed(() => {
return props.emptyText || t('grid.noItems');
});
</script>
6 changes: 2 additions & 4 deletions src/components/TableNext/TableColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const props = defineProps({
});
const tableContext = inject('tableContext');
</script>
<style lang="less">
@import '../../styles/_import';
</style>
tableContext.columnsCount.value++;
</script>

0 comments on commit c006bca

Please sign in to comment.