2021-04-08 16:57:24 +02:00
|
|
|
<script>
|
|
|
|
export let value
|
|
|
|
|
|
|
|
const displayLimit = 5
|
|
|
|
$: attachments = value?.slice(0, displayLimit) ?? []
|
|
|
|
$: leftover = (value?.length ?? 0) - attachments.length
|
2021-04-09 15:21:27 +02:00
|
|
|
|
|
|
|
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
|
|
|
|
const isImage = extension => {
|
|
|
|
return imageExtensions.includes(extension?.toLowerCase())
|
|
|
|
}
|
2021-04-08 16:57:24 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#each attachments as attachment}
|
2021-04-09 15:21:27 +02:00
|
|
|
{#if isImage(attachment.extension)}
|
2021-04-08 16:57:24 +02:00
|
|
|
<img src={attachment.url} alt={attachment.extension} />
|
|
|
|
{:else}
|
|
|
|
<div class="file">{attachment.extension}</div>
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
{#if leftover}
|
|
|
|
<div>+{leftover} more</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
img {
|
|
|
|
height: 32px;
|
|
|
|
max-width: 64px;
|
|
|
|
}
|
|
|
|
.file {
|
|
|
|
height: 32px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 8px;
|
|
|
|
color: var(--spectrum-global-color-gray-800);
|
|
|
|
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
|
|
border-radius: 2px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 11px;
|
|
|
|
}
|
|
|
|
</style>
|