Skip to content

Commit

Permalink
feat: add empty slot to datatable (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWaldschmidt authored May 7, 2024
1 parent 07d4d3c commit 86b0dba
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v2.0.55

- Add `empty` slot to `DataTable`

## v2.0.54

- Fixes the `DataTable` error rendering
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lob/ui-components",
"version": "2.0.54",
"version": "2.0.55",
"engines": {
"node": ">=20.2.0",
"npm": ">=10.2.0"
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataTable/DataTable.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const Primary: StoryObj<typeof DataTable> = {
setup: () => ({ args }),
template: `
<DataTable v-bind="args">
<Column field="firstName" header="First Name" />
<Column field="lastName" header="Last Name" />
<Column field="favoriteColor" header="Favorite Color" />
<Column field="firstName" header="First Name" class="w-96" />
<Column field="lastName" header="Last Name" class="w-96" />
<Column field="favoriteColor" header="Favorite Color" class="w-96" />
</DataTable>
`
}),
Expand Down
8 changes: 5 additions & 3 deletions src/components/DataTable/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<template #empty>
<template v-if="!loading">
<Alert v-if="error" variant="error">{{ error }}</Alert>
<Alert v-else variant="info">No results</Alert>
<Alert v-else-if="!$slots['empty']" variant="info">No results</Alert>
<slot v-else name="empty" />
</template>
</template>

Expand All @@ -49,7 +50,7 @@

<Column v-if="clickable" class="w-14 text-center">
<template #body>
<Icon :icon="IconName.DETAILS" size="xl" />
<Icon :icon="IconName.DETAILS" size="xl" class="mx-auto" />
</template>
</Column>

Expand Down Expand Up @@ -170,6 +171,7 @@ defineEmits<{
defineSlots<{
default(): any;
toolbar(): any;
empty(): any;
}>();
</script>

Expand Down Expand Up @@ -311,6 +313,6 @@ defineSlots<{
@apply py-2;
}
.uic-datatable-toolbar {
@apply py-2;
@apply pb-6;
}
</style>
6 changes: 5 additions & 1 deletion src/components/DataTable/DataTableTotalResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const totalRows = computed(() => {
if (typeof props.total !== 'number') {
return '-';
}
return props.total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
const commaFormatted = props.total
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
// When our ES total is 10,000, we want to display 10,000+.
return props.total === 10000 ? `${commaFormatted}+` : commaFormatted;
});
</script>

Expand Down

0 comments on commit 86b0dba

Please sign in to comment.