-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathNftImageOrIconBox.svelte
68 lines (64 loc) · 2 KB
/
NftImageOrIconBox.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script lang="ts">
import { INft, ParentMimeType } from '@core/nfts'
import { MediaPlaceholder, NftMedia } from 'shared/components'
import { NftSize } from 'shared/components/enums'
export let nft: INft | null = null
export let size: NftSize = NftSize.Medium
export let useCaching: boolean = true
$: nftType = nft?.parsedMetadata?.type
$: parentType = nftType?.split('/')?.[0]
</script>
<nft-image-or-icon-box
class:bg-gray-500={!nft?.downloadMetadata?.isLoaded}
class:small={size === NftSize.Small}
class:medium={size === NftSize.Medium}
class:large={size === NftSize.Large}
>
{#if (parentType === ParentMimeType.Image && nft) || (parentType === ParentMimeType.Text && nft)}
<NftMedia {nft} {useCaching}>
<placeholder-wrapper
slot="placeholder"
class:small={size === NftSize.Small}
class:medium={size === NftSize.Medium}
class:large={size === NftSize.Large}
>
<MediaPlaceholder type={nftType} iconOnly />
</placeholder-wrapper>
</NftMedia>
{:else}
<placeholder-wrapper
class:small={size === NftSize.Small}
class:medium={size === NftSize.Medium}
class:large={size === NftSize.Large}
>
<MediaPlaceholder type={nftType} iconOnly />
</placeholder-wrapper>
{/if}
</nft-image-or-icon-box>
<style lang="scss">
nft-image-or-icon-box {
@apply flex items-center justify-center;
@apply overflow-hidden;
@apply shrink-0;
@apply rounded-md;
&.small {
@apply w-6 h-6;
}
&.medium {
@apply w-8 h-8;
}
&.large {
@apply w-10 h-10;
}
placeholder-wrapper {
@apply w-full h-full;
&.small {
@apply p-1;
}
&.medium,
&.large {
@apply p-2;
}
}
}
</style>