Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DataGrid): add empty state slot #2562

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strange-teachers-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sit-onyx": patch
---

Added empty slot to DataGrid to be able to pass custom empty content
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pin from "@sit-onyx/icons/pin.svg?raw";
import trash from "@sit-onyx/icons/trash.svg?raw";
import type { Meta, StoryObj } from "@storybook/vue3";
import { h } from "vue";
import OnyxEmpty from "../OnyxEmpty/OnyxEmpty.vue";
import OnyxIcon from "../OnyxIcon/OnyxIcon.vue";
import OnyxMenuItem from "../OnyxNavBar/modules/OnyxMenuItem/OnyxMenuItem.vue";
import OnyxSystemButton from "../OnyxSystemButton/OnyxSystemButton.vue";
Expand Down Expand Up @@ -72,3 +73,11 @@ export const HeaderInteractions = {
],
},
} satisfies Story;

export const CustomEmptyState = {
args: {
columns: ["name", "age", "birthday"],
data: undefined,
empty: () => h(OnyxEmpty, null, { default: "DataGrid is empty" }),
},
} satisfies Story;
15 changes: 14 additions & 1 deletion packages/sit-onyx/src/components/OnyxDataGrid/OnyxDataGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ const props = withDefaults(defineProps<OnyxDataGridProps<TEntry, TFeatures>>(),

const { t } = injectI18n();

defineSlots<{
/**
* Optional slot to customize the empty state when no data exist.
*
* If unset, the default empty content of OnyxTable will be displayed.
*/
empty?(): unknown;
}>();

// Using Ref types to avoid `UnwrapRef` issues
const renderColumns: Ref<DataGridRendererColumn<TEntry, object>[]> = ref([]);
const renderRows: Ref<DataGridRendererRow<TEntry, DataGridMetadata>[]> = ref([]);
Expand Down Expand Up @@ -53,5 +62,9 @@ watch(
</script>

<template>
<OnyxDataGridRenderer :columns="renderColumns" :rows="renderRows" />
<OnyxDataGridRenderer :columns="renderColumns" :rows="renderRows">
<template #empty>
<slot name="empty" />
</template>
</OnyxDataGridRenderer>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const props = withDefaults(defineProps<OnyxDataGridRendererProps<TEntry, TMetada
striped: true,
withVerticalBorders: true,
});

defineSlots<{
/**
* Optional slot to customize the empty state when no data exist.
*
* If unset, the default empty content of OnyxTable will be displayed.
*/
empty?(): unknown;
}>();
</script>

<template>
Expand All @@ -34,6 +43,10 @@ const props = withDefaults(defineProps<OnyxDataGridRendererProps<TEntry, TMetada
</td>
</template>
</tr>

<template #empty>
<slot name="empty" />
</template>
</OnyxTable>
</template>

Expand Down
Loading