[ui] table props refactor

feat/vaults
Tomáš Mládek 2021-12-01 15:39:26 +01:00
parent f967c17dda
commit 067eeeb543
2 changed files with 32 additions and 26 deletions

View File

@ -85,7 +85,7 @@
/> />
{/each} {/each}
{:else} {:else}
<Table entity attribute value={false} {attributes} /> <Table columns="entity, attribute" {attributes} />
{/if} {/if}
</section> </section>

View File

@ -6,13 +6,17 @@
import Marquee from "../Marquee.svelte"; import Marquee from "../Marquee.svelte";
import Address from "../Address.svelte"; import Address from "../Address.svelte";
export let entity = false; export let columns = "attribute, value";
export let attribute = true; export let header = true;
export let value = true;
export let attributes: OrderedListing; export let attributes: OrderedListing;
export let editable = false; export let editable = false;
// Display
$: showEntity = columns.includes("entity");
$: showAttribute = columns.includes("attribute");
$: showValue = columns.includes("value");
// Pagination // Pagination
let currentDisplay = 999; let currentDisplay = 999;
const MAX_DISPLAY = 50; const MAX_DISPLAY = 50;
@ -105,31 +109,33 @@
{#if editable} {#if editable}
<col class="attr-action-col" /> <col class="attr-action-col" />
{/if} {/if}
{#if entity} {#if showEntity}
<col class="entity-col" /> <col class="entity-col" />
{/if} {/if}
{#if attribute} {#if showAttribute}
<col class="attr-col" /> <col class="attr-col" />
{/if} {/if}
{#if value} {#if showValue}
<col class="val-col" /> <col class="val-col" />
{/if} {/if}
</colgroup> </colgroup>
<tr> {#if header}
{#if editable} <tr>
<th /> {#if editable}
{/if} <th />
{#if entity} {/if}
<th>Entity</th> {#if showEntity}
{/if} <th>Entity</th>
{#if attribute} {/if}
<th>Attribute</th> {#if showAttribute}
{/if} <th>Attribute</th>
{#if value} {/if}
<th>Value</th> {#if showValue}
{/if} <th>Value</th>
</tr> {/if}
</tr>
{/if}
{#each sortedAttributes as [id, entry] (id)} {#each sortedAttributes as [id, entry] (id)}
<tr> <tr>
@ -139,13 +145,13 @@
</td> </td>
{/if} {/if}
{#if entity} {#if showEntity}
<td> <td>
<Address link address={entry.entity} /> <Address link address={entry.entity} />
</td> </td>
{/if} {/if}
{#if attribute} {#if showAttribute}
<td class:formatted={Boolean(formatAttribute(entry.attribute))}> <td class:formatted={Boolean(formatAttribute(entry.attribute))}>
<Marquee> <Marquee>
{formatAttribute(entry.attribute) || entry.attribute} {formatAttribute(entry.attribute) || entry.attribute}
@ -153,7 +159,7 @@
</td> </td>
{/if} {/if}
{#if value} {#if showValue}
<td class="value"> <td class="value">
<text-input <text-input
{editable} {editable}
@ -204,12 +210,12 @@
<td class="attr-action"> <td class="attr-action">
<sl-icon-button name="plus-circle" on:click={addEntry()} /> <sl-icon-button name="plus-circle" on:click={addEntry()} />
</td> </td>
{#if attribute} {#if showAttribute}
<td> <td>
<sl-input v-sl-model:newEntryAttribute size="small" /> <sl-input v-sl-model:newEntryAttribute size="small" />
</td> </td>
{/if} {/if}
{#if value} {#if showValue}
<td> <td>
<sl-input v-sl-model:newEntryValue size="small" /> <sl-input v-sl-model:newEntryValue size="small" />
</td> </td>