Skip to content

Commit

Permalink
add Table
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaboud committed Jun 7, 2024
1 parent c24c69c commit 27d6613
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
99 changes: 99 additions & 0 deletions houston-common-ui/lib/components/Table.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!--
Copyright (C) 2022 Josh Boudreau <jboudreau@45drives.com>
This file is part of Cockpit File Sharing.
Cockpit File Sharing is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
Cockpit File Sharing is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Cockpit File Sharing.
If not, see <https://www.gnu.org/licenses/>.
-->

<script setup lang="ts">
import { defineProps, withDefaults } from "vue";
withDefaults(
defineProps<{
emptyText?: string;
stickyHeaders?: boolean;
noScroll?: boolean;
}>(),
{
emptyText: "Nothing to show.",
stickyHeaders: false,
noScroll: false,
}
);
</script>

<template>
<div class="h-full overflow-hidden bg-accent">
<div
v-if="$slots.header"
class="py-3 px-4 lg:px-6 text-sm font-semibold flex flex-row"
>
<div class="grow">
<slot name="header"></slot>
</div>
<div
:class="{ 'overflow-y-scroll': !noScroll }"
:style="{ 'scrollbar-gutter': noScroll ? 'auto' : 'stable' }"
></div>
</div>
<div
class="flex flex-col overflow-x-auto"
:class="{ 'overflow-y-scroll': !noScroll }"
:style="{ 'scrollbar-gutter': noScroll ? 'auto' : 'stable' }"
>
<table class="min-w-full divide-y divide-default houston-table">
<thead :class="{ 'use-sticky': stickyHeaders }">
<slot name="thead" />
</thead>
<tbody class="bg-default w-full">
<slot name="tbody">
<tr>
<td
colspan="100%"
class="text-center align-middle text-muted text-sm"
>
{{ emptyText }}
</td>
</tr>
</slot>
</tbody>
</table>
</div>
</div>
</template>

<style>
@import "@45drives/houston-common-css/src/index.css";
table.houston-table thead.use-sticky tr th {
@apply sticky z-10 top-0;
}
table.houston-table th,
table.houston-table td {
@apply py-2 px-4 lg:px-6 whitespace-nowrap text-sm;
}
table.houston-table th:not(.text-right):not(.text-center),
table.houston-table td:not(.text-right):not(.text-center) {
@apply text-left;
}
table.houston-table th {
@apply bg-accent font-semibold;
}
table.houston-table tr {
@apply even:bg-accent;
}
</style>
1 change: 1 addition & 0 deletions houston-common-ui/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as UserSelector } from "./UserSelector.vue";
export { default as GroupSelector } from "./GroupSelector.vue";
export { default as ModeAndPermissionsEditor } from "./ModeAndPermissionsEditor.vue";
export { default as ValidationResultView } from "./ValidationResultView.vue";
export { default as Table } from "./Table.vue";

export * from "./tabs";
export * from "./modals";

0 comments on commit 27d6613

Please sign in to comment.