Improve table cell rendering and pass down table slot

This commit is contained in:
Andrew Kingston 2021-04-12 15:24:33 +01:00
parent 7ca7769482
commit 4703c87991
3 changed files with 19 additions and 15 deletions

View File

@ -11,22 +11,23 @@
export let customRenderers = [] export let customRenderers = []
const plainTypes = ["string", "options", "number", "longform"] const plainTypes = ["string", "options", "number", "longform"]
const typeMap = {
boolean: BooleanRenderer,
datetime: DateTimeRenderer,
link: RelationshipRenderer,
attachment: AttachmentRenderer,
string: StringRenderer,
options: StringRenderer,
number: StringRenderer,
longform: StringRenderer,
}
$: type = schema?.type ?? "string" $: type = schema?.type ?? "string"
$: customRenderer = customRenderers?.find(x => x.column === schema?.name) $: customRenderer = customRenderers?.find(x => x.column === schema?.name)
$: renderer = customRenderer?.component ?? typeMap[type]
</script> </script>
{#if value != null && value !== ''} {#if renderer && value != null && value !== ''}
{#if customRenderer} <svelte:component this={renderer} {row} {schema} {value} on:clickrelationship>
<svelte:component this={customRenderer.component} {schema} {value} /> <slot />
{:else if plainTypes.includes(type)} </svelte:component>
<StringRenderer {value} />
{:else if type === 'boolean'}
<BooleanRenderer {value} />
{:else if type === 'datetime'}
<DateTimeRenderer {value} />
{:else if type === 'link'}
<RelationshipRenderer {row} {schema} {value} on:clickrelationship />
{:else if type === 'attachment'}
<AttachmentRenderer {value} />
{/if}
{/if} {/if}

View File

@ -3,6 +3,7 @@
</script> </script>
<div>{value}</div> <div>{value}</div>
<slot />
<style> <style>
div { div {

View File

@ -232,7 +232,9 @@
{row} {row}
schema={schema[field]} schema={schema[field]}
value={row[field]} value={row[field]}
on:clickrelationship /> on:clickrelationship>
<slot />
</CellRenderer>
</div> </div>
</td> </td>
{/each} {/each}