1
0
Fork 0
mirror of synced 2024-07-02 04:50:44 +12:00
budibase/packages/standard-components/src/List.svelte

46 lines
902 B
Svelte
Raw Normal View History

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