|
|
@@ -0,0 +1,105 @@
|
|
|
+<script>
|
|
|
+ import { createEventDispatcher } from 'svelte';
|
|
|
+
|
|
|
+ // Título do bloco da tabela
|
|
|
+ export let title = 'Lista';
|
|
|
+
|
|
|
+ // Ex: [{ key: "nome", label: "Nome" }, { key: "preco", label: "Preço" }]
|
|
|
+ export let columns = [];
|
|
|
+ // Ex: [{ nome: "Produto 1", preco: 100 }, { nome: "Produto 2", preco: 200 }]
|
|
|
+ export let data = [];
|
|
|
+
|
|
|
+ // Controla exibição da coluna de ações
|
|
|
+ export let showActions = true;
|
|
|
+
|
|
|
+ const dispatch = createEventDispatcher();
|
|
|
+
|
|
|
+ function handleAddTop() {
|
|
|
+ dispatch('addTop');
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleEditRow(row) {
|
|
|
+ dispatch('editRow', { row });
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleDeleteRow(row) {
|
|
|
+ dispatch('deleteRow', { row });
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<div class="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm">
|
|
|
+ <div class="flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-gray-700">
|
|
|
+ <h3 class="text-base font-semibold text-gray-800 dark:text-gray-100">{title}</h3>
|
|
|
+ <button
|
|
|
+ class="inline-flex items-center justify-center rounded-md bg-blue-600 hover:bg-blue-700 text-white w-10 h-10 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
|
+ type="button"
|
|
|
+ title="Adicionar"
|
|
|
+ on:click={handleAddTop}
|
|
|
+ >
|
|
|
+ <img src="/icons/plus-white.svg" alt="Adicionar" class="w-6 h-6" />
|
|
|
+ <span class="sr-only">Adicionar</span>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="overflow-x-auto">
|
|
|
+ <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
|
|
|
+ <thead class="bg-gray-50 dark:bg-gray-700">
|
|
|
+ <tr>
|
|
|
+ {#each columns as col}
|
|
|
+ <th class="px-6 py-3 text-left text-sm font-semibold uppercase tracking-wide text-gray-700 dark:text-gray-200">
|
|
|
+ {col.label}
|
|
|
+ </th>
|
|
|
+ {/each}
|
|
|
+ {#if showActions}
|
|
|
+ <th class="px-6 py-3 text-right text-sm font-semibold uppercase tracking-wide text-gray-700 dark:text-gray-200">Ações</th>
|
|
|
+ {/if}
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody class="divide-y divide-gray-200 dark:divide-gray-700 bg-white dark:bg-gray-800">
|
|
|
+ {#if data.length > 0}
|
|
|
+ {#each data as row}
|
|
|
+ <tr class="hover:bg-gray-50 dark:hover:bg-gray-700/60">
|
|
|
+ {#each columns as col}
|
|
|
+ <td class="px-6 py-3 text-base text-gray-700 dark:text-gray-300">
|
|
|
+ {row[col.key]}
|
|
|
+ </td>
|
|
|
+ {/each}
|
|
|
+ {#if showActions}
|
|
|
+ <td class="px-6 py-3 text-sm text-right whitespace-nowrap">
|
|
|
+ <div class="inline-flex items-center gap-2">
|
|
|
+ <button
|
|
|
+ class="inline-flex items-center justify-center w-9 h-9 rounded-md border border-gray-200 dark:border-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700"
|
|
|
+ type="button"
|
|
|
+ title="Editar"
|
|
|
+ on:click={() => handleEditRow(row)}
|
|
|
+ >
|
|
|
+ <img src="/icons/edit-light.svg" alt="Editar" class="w-5 h-5 block dark:hidden" />
|
|
|
+ <img src="/icons/edit-dark.svg" alt="Editar" class="w-5 h-5 hidden dark:block" />
|
|
|
+ <span class="sr-only">Editar</span>
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ class="inline-flex items-center justify-center w-9 h-9 rounded-md border border-gray-200 dark:border-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700"
|
|
|
+ type="button"
|
|
|
+ title="Excluir"
|
|
|
+ on:click={() => handleDeleteRow(row)}
|
|
|
+ >
|
|
|
+ <img src="/icons/trash-light.svg" alt="Excluir" class="w-5 h-5 block dark:hidden" />
|
|
|
+ <img src="/icons/trash-dark.svg" alt="Excluir" class="w-5 h-5 hidden dark:block" />
|
|
|
+ <span class="sr-only">Excluir</span>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </td>
|
|
|
+ {/if}
|
|
|
+ </tr>
|
|
|
+ {/each}
|
|
|
+ {:else}
|
|
|
+ <tr>
|
|
|
+ <td colspan={columns.length + (showActions ? 1 : 0)} class="px-4 py-6 text-center text-gray-400 dark:text-gray-500">
|
|
|
+ Nenhum dado encontrado
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ {/if}
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+</div>
|