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

47 lines
917 B
Svelte
Raw Normal View History

2020-06-03 00:26:06 +02:00
<script>
import { getContext, onMount } from "svelte"
import { isEmpty } from "lodash/fp"
const { API, styleable, DataProvider } = getContext("sdk")
const component = getContext("component")
console.log($component)
const dataContext = getContext("data")
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 = []
2020-06-03 00:26:06 +02:00
2021-01-11 21:17:56 +01:00
$: datasource && fetchData()
async function fetchData() {
rows = await API.fetchDatasource(datasource, $dataContext)
}
onMount(async () => {
if (!isEmpty(datasource)) {
2021-01-11 21:17:56 +01:00
fetchData()
2020-06-03 00:26:06 +02:00
}
})
</script>
<div use:styleable={$component.styles}>
{#if rows.length > 0}
{#each rows as row}
<DataProvider {row}>
<slot />
</DataProvider>
{/each}
{:else}
<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>