|
| 1 | +--- |
| 2 | +/** |
| 3 | + * Wrapper component for Markdown tables that adds no-wrap column support |
| 4 | + * |
| 5 | + * Usage: |
| 6 | + * <TableWrapper nowrap={[0, 2]}> |
| 7 | + * |
| 8 | + * | File | Purpose | Update Frequency | Typical Changes | |
| 9 | + * |------|---------|------------------|-----------------| |
| 10 | + * | `scripts/aem.js` | Core AEM functionality | Very Rare | Core platform improvements | |
| 11 | + * | `scripts/scripts.js` | Page loading... | Very Rare | Performance optimizations | |
| 12 | + * |
| 13 | + * </TableWrapper> |
| 14 | + */ |
| 15 | +
|
| 16 | +interface Props { |
| 17 | + nowrap?: number[]; // Column indices that should not wrap (0-based) |
| 18 | +} |
| 19 | +
|
| 20 | +const { nowrap = [] } = Astro.props; |
| 21 | +--- |
| 22 | + |
| 23 | +<div class="table-wrapper" data-nowrap-columns={nowrap.join(",")}> |
| 24 | + <slot /> |
| 25 | +</div> |
| 26 | + |
| 27 | +<style is:global> |
| 28 | + .table-wrapper { |
| 29 | + overflow-x: auto; |
| 30 | + margin-bottom: 1rem; |
| 31 | + } |
| 32 | + |
| 33 | + .table-wrapper table { |
| 34 | + width: 100%; |
| 35 | + border-collapse: collapse; |
| 36 | + } |
| 37 | + |
| 38 | + /* Apply nowrap to specific columns based on data attribute */ |
| 39 | + .table-wrapper[data-nowrap-columns] th, |
| 40 | + .table-wrapper[data-nowrap-columns] td { |
| 41 | + white-space: normal; /* Default: allow wrapping */ |
| 42 | + } |
| 43 | + |
| 44 | + /* Column 0 - nowrap */ |
| 45 | + .table-wrapper[data-nowrap-columns*="0"] th:nth-child(1), |
| 46 | + .table-wrapper[data-nowrap-columns*="0"] td:nth-child(1) { |
| 47 | + white-space: nowrap; |
| 48 | + } |
| 49 | + |
| 50 | + /* Column 1 - nowrap */ |
| 51 | + .table-wrapper[data-nowrap-columns*="1"] th:nth-child(2), |
| 52 | + .table-wrapper[data-nowrap-columns*="1"] td:nth-child(2) { |
| 53 | + white-space: nowrap; |
| 54 | + } |
| 55 | + |
| 56 | + /* Column 2 - nowrap */ |
| 57 | + .table-wrapper[data-nowrap-columns*="2"] th:nth-child(3), |
| 58 | + .table-wrapper[data-nowrap-columns*="2"] td:nth-child(3) { |
| 59 | + white-space: nowrap; |
| 60 | + } |
| 61 | + |
| 62 | + /* Column 3 - nowrap */ |
| 63 | + .table-wrapper[data-nowrap-columns*="3"] th:nth-child(4), |
| 64 | + .table-wrapper[data-nowrap-columns*="3"] td:nth-child(4) { |
| 65 | + white-space: nowrap; |
| 66 | + } |
| 67 | + |
| 68 | + /* Column 4 - nowrap */ |
| 69 | + .table-wrapper[data-nowrap-columns*="4"] th:nth-child(5), |
| 70 | + .table-wrapper[data-nowrap-columns*="4"] td:nth-child(5) { |
| 71 | + white-space: nowrap; |
| 72 | + } |
| 73 | + |
| 74 | + /* Column 5 - nowrap */ |
| 75 | + .table-wrapper[data-nowrap-columns*="5"] th:nth-child(6), |
| 76 | + .table-wrapper[data-nowrap-columns*="5"] td:nth-child(6) { |
| 77 | + white-space: nowrap; |
| 78 | + } |
| 79 | + |
| 80 | + /* Column 6 - nowrap */ |
| 81 | + .table-wrapper[data-nowrap-columns*="6"] th:nth-child(7), |
| 82 | + .table-wrapper[data-nowrap-columns*="6"] td:nth-child(7) { |
| 83 | + white-space: nowrap; |
| 84 | + } |
| 85 | + |
| 86 | + /* Column 7 - nowrap */ |
| 87 | + .table-wrapper[data-nowrap-columns*="7"] th:nth-child(8), |
| 88 | + .table-wrapper[data-nowrap-columns*="7"] td:nth-child(8) { |
| 89 | + white-space: nowrap; |
| 90 | + } |
| 91 | + |
| 92 | + /* Column 8 - nowrap */ |
| 93 | + .table-wrapper[data-nowrap-columns*="8"] th:nth-child(9), |
| 94 | + .table-wrapper[data-nowrap-columns*="8"] td:nth-child(9) { |
| 95 | + white-space: nowrap; |
| 96 | + } |
| 97 | + |
| 98 | + /* Column 9 - nowrap */ |
| 99 | + .table-wrapper[data-nowrap-columns*="9"] th:nth-child(10), |
| 100 | + .table-wrapper[data-nowrap-columns*="9"] td:nth-child(10) { |
| 101 | + white-space: nowrap; |
| 102 | + } |
| 103 | +</style> |
0 commit comments