Table.svelte 987 B

123456789101112131415161718192021222324252627282930313233343536
  1. <script lang="ts">
  2. import type { BaseComponentProps } from "@json-render/svelte";
  3. import type { ShadcnProps } from "./catalog.js";
  4. import * as Table from "./ui/table/index.js";
  5. interface Props extends BaseComponentProps<ShadcnProps<"Table">> {}
  6. let { props }: Props = $props();
  7. const columns = $derived(props.columns ?? []);
  8. const rows = $derived((props.rows ?? []).map((row) => row.map((cell) => String(cell))));
  9. </script>
  10. <div class="rounded-md border overflow-hidden">
  11. <Table.Root>
  12. {#if props.caption}
  13. <Table.Caption>{props.caption}</Table.Caption>
  14. {/if}
  15. <Table.Header>
  16. <Table.Row>
  17. {#each columns as col}
  18. <Table.Head>{col}</Table.Head>
  19. {/each}
  20. </Table.Row>
  21. </Table.Header>
  22. <Table.Body>
  23. {#each rows as row}
  24. <Table.Row>
  25. {#each row as cell}
  26. <Table.Cell>{cell}</Table.Cell>
  27. {/each}
  28. </Table.Row>
  29. {/each}
  30. </Table.Body>
  31. </Table.Root>
  32. </div>