budibase/packages/standard-components/src/List.svelte

48 lines
1003 B
Svelte
Raw Normal View History

2020-06-03 00:26:06 +02:00
<script>
import { getContext } from "svelte"
import { isEmpty } from "lodash/fp"
const { API, styleable, Provider, builderStore } = getContext("sdk")
const component = getContext("component")
2020-06-03 00:26:06 +02:00
export let datasource = []
2020-06-03 00:26:06 +02:00
2020-11-18 12:24:01 +01:00
let rows = []
let loaded = false
2020-06-03 00:26:06 +02:00
$: fetchData(datasource)
2021-01-11 21:17:56 +01:00
async function fetchData(datasource) {
if (!isEmpty(datasource)) {
rows = await API.fetchDatasource(datasource)
2020-06-03 00:26:06 +02:00
}
loaded = true
}
2020-06-03 00:26:06 +02:00
</script>
<div use:styleable={$component.styles}>
{#if rows.length > 0}
{#if $component.children === 0 && $builderStore.inBuilder}
<p>Add some components too</p>
{:else}
{#each rows as row}
<Provider data={row}>
<slot />
</Provider>
{/each}
{/if}
{:else if loaded && $builderStore.inBuilder}
<p>Feed me some data</p>
{/if}
2020-11-18 12:24:01 +01:00
</div>
<style>
p {
display: grid;
place-items: center;
background: #f5f5f5;
border: #ccc 1px solid;
padding: var(--spacing-m);
}
</style>