Plan stuff. Log stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1011 B

  1. <script>
  2. export let headers = [];
  3. export let percentages = [];
  4. let zipped = [];
  5. $: zipped = headers.map((h, i) => ({header: h, pct: percentages[i]}))
  6. $: if (percentages.length !== headers.length) {
  7. throw new Error(`Mismatching headers (${headers.join(",")}) and percentages (${percentages.join(",")})`)
  8. }
  9. </script>
  10. <table>
  11. <thead>
  12. <tr>
  13. {#each zipped as h}
  14. <th style={`width: ${h.pct}%;`}>{h.header}</th>
  15. {/each}
  16. </tr>
  17. </thead>
  18. <tbody>
  19. <slot></slot>
  20. </tbody>
  21. </table>
  22. <style>
  23. table {
  24. width: 100%;
  25. padding: 0.5em 0.75ch;
  26. }
  27. table :global(th), table :global(td) {
  28. box-sizing: border-box;
  29. }
  30. table :global(th) {
  31. text-align: left;
  32. font-size: 0.75em;
  33. }
  34. table :global(td.ellipsis) {
  35. max-width: 1px; /* Don't ask me why this works... */
  36. overflow: hidden;
  37. text-overflow: ellipsis;
  38. white-space: nowrap;
  39. }
  40. table :global(td:last-of-type), table :global(th:last-of-type) {
  41. text-align: right;
  42. }
  43. </style>