Improve table cell rendering and pass down table slot
This commit is contained in:
parent
3b2ef3a5e9
commit
d7cb604151
|
@ -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}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>{value}</div>
|
<div>{value}</div>
|
||||||
|
<slot />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
div {
|
div {
|
||||||
|
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue