Make table responsive and vertically and horizontally scrollable

This commit is contained in:
Andrew Kingston 2021-03-24 18:46:12 +00:00
parent 22fb849ad2
commit bc562ffd6b
1 changed files with 62 additions and 38 deletions

View File

@ -8,6 +8,7 @@
export let dataProvider export let dataProvider
export let columns export let columns
export let showAutoColumns export let showAutoColumns
export let rowCount = 8
const component = getContext("component") const component = getContext("component")
const { styleable } = getContext("sdk") const { styleable } = getContext("sdk")
@ -60,51 +61,71 @@
} }
</script> </script>
<div <div use:styleable={$component.styles}>
lang="en" <div
dir="ltr" lang="en"
use:styleable={$component.styles} dir="ltr"
class={`spectrum ${size || 'spectrum--medium'} ${theme || 'spectrum--light'}`}> class={`spectrum ${size || 'spectrum--medium'} ${theme || 'spectrum--light'}`}
<table class="spectrum-Table"> style={`height: ${rowCount * 55}px;`}>
<thead class="spectrum-Table-head"> <table class="spectrum-Table">
<tr> <thead class="spectrum-Table-head">
{#each fields as field} <tr>
<th
class="spectrum-Table-headCell is-sortable"
class:is-sorted-desc={sortColumn === field && sortOrder === 'Descending'}
class:is-sorted-asc={sortColumn === field && sortOrder === 'Ascending'}
on:click={() => sortBy(field)}>
<div class="spectrum-Table-headCell-content">
{schema[field]?.name}
<svg
class="spectrum-Icon spectrum-UIIcon-ArrowDown100 spectrum-Table-sortedIcon"
class:visible={sortColumn === field}
focusable="false"
aria-hidden="true">
<use xlink:href="#spectrum-css-icon-Arrow100" />
</svg>
</div>
</th>
{/each}
</tr>
</thead>
<tbody class="spectrum-Table-body">
{#each sortedRows as row}
<tr class="spectrum-Table-row">
{#each fields as field} {#each fields as field}
<td class="spectrum-Table-cell" tabindex="0"> <th
<div class="spectrum-Table-cell-content"> class="spectrum-Table-headCell is-sortable"
<CellRenderer schema={schema[field]} value={row[field]} /> class:is-sorted-desc={sortColumn === field && sortOrder === 'Descending'}
class:is-sorted-asc={sortColumn === field && sortOrder === 'Ascending'}
on:click={() => sortBy(field)}>
<div class="spectrum-Table-headCell-content">
{schema[field]?.name}
<svg
class="spectrum-Icon spectrum-UIIcon-ArrowDown100 spectrum-Table-sortedIcon"
class:visible={sortColumn === field}
focusable="false"
aria-hidden="true">
<use xlink:href="#spectrum-css-icon-Arrow100" />
</svg>
</div> </div>
</td> </th>
{/each} {/each}
</tr> </tr>
{/each} </thead>
</tbody> <tbody class="spectrum-Table-body">
</table> {#each sortedRows as row}
<tr class="spectrum-Table-row">
{#each fields as field}
<td class="spectrum-Table-cell" tabindex="0">
<div class="spectrum-Table-cell-content">
<CellRenderer schema={schema[field]} value={row[field]} />
</div>
</td>
{/each}
</tr>
{/each}
</tbody>
</table>
</div>
</div> </div>
<style> <style>
.spectrum {
position: relative;
overflow: auto;
}
table {
width: 100%;
}
tbody {
z-index: 1;
}
th {
position: sticky;
top: 0;
background-color: var(--spectrum-global-color-gray-100);
border-bottom: 1px solid
var(--spectrum-table-border-color, var(--spectrum-alias-border-color-mid));
z-index: 2;
}
.spectrum-Table-headCell-content { .spectrum-Table-headCell-content {
white-space: nowrap; white-space: nowrap;
display: flex; display: flex;
@ -116,6 +137,9 @@
.spectrum-Table-cell { .spectrum-Table-cell {
padding-top: 0; padding-top: 0;
padding-bottom: 0; padding-bottom: 0;
border-bottom: 1px solid
var(--spectrum-table-border-color, var(--spectrum-alias-border-color-mid));
border-top: none !important;
} }
.spectrum-Table-cell-content { .spectrum-Table-cell-content {
height: 55px; height: 55px;