summaryrefslogtreecommitdiff
path: root/src/components/jet/item/SmallStoryCardWithArtworkItem.svelte
blob: bcd733335e00a75cf454d7a92921ac698259895f (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<script lang="ts" context="module">
    import type {
        Artwork as ArtworkModel,
        TodayCard,
    } from '@jet-app/app-store/api/models';

    export interface SmallStoryCardWithArtwork extends TodayCard {
        artwork: ArtworkModel;
        badge: any;
    }

    export function isSmallStoryCardWithArtworkItem(
        item: TodayCard,
    ): item is SmallStoryCardWithArtwork {
        return !('media' in item) && 'artwork' in item;
    }
</script>

<script lang="ts">
    import Artwork from '~/components/Artwork.svelte';
    import HoverWrapper from '~/components/HoverWrapper.svelte';
    import LinkWrapper from '~/components/LinkWrapper.svelte';
    import GradientOverlay from '~/components/GradientOverlay.svelte';
    import { colorAsString } from '~/utils/color';
    import { sanitizeHtml } from '@amp/web-app-components/src/utils/sanitize-html';

    export let item: SmallStoryCardWithArtwork;

    $: artwork = item.heroMedia?.artworks?.[0] || item.artwork;

    $: gradientColor = artwork.backgroundColor
        ? colorAsString(artwork.backgroundColor)
        : 'rgb(0 0 0 / 62%)';
</script>

<article>
    <LinkWrapper action={item.clickAction}>
        <HoverWrapper element="div">
            <Artwork {artwork} profile="small-story-card-portrait" />

            <GradientOverlay --color={gradientColor} />

            <div class="text-container">
                {#if item.badge?.title}
                    <h4>{item.badge.title}</h4>
                {/if}

                {#if item.title}
                    <h3>{@html sanitizeHtml(item.title)}</h3>
                {/if}
            </div>
        </HoverWrapper>
    </LinkWrapper>
</article>

<style>
    article {
        aspect-ratio: 3/4;
    }

    .text-container {
        position: absolute;
        display: flex;
        flex-direction: column;
        justify-content: end;
        height: 100%;
        margin-top: 8px;
        padding: 16px;
        color: var(--systemPrimary);
    }

    h3 {
        z-index: 1;
        text-wrap: pretty;
        font: var(--body-bold);
        color: var(--systemPrimary-onDark);
    }

    h4 {
        position: relative;
        z-index: 1;
        margin-bottom: 2px;
        font: var(--caption-2-emphasized);
        color: var(--systemSecondary-onDark);
        mix-blend-mode: plus-lighter;
    }
</style>