summaryrefslogtreecommitdiff
path: root/src/components/jet/item/LargeBrickItem.svelte
blob: 5ce9974f74296ee34672b6f5da683145e4d70979 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<script lang="ts">
    import type { Brick } from '@jet-app/app-store/api/models';

    import LineClamp from '@amp/web-app-components/src/components/LineClamp/LineClamp.svelte';
    import Artwork from '~/components/Artwork.svelte';
    import GradientOverlay from '~/components/GradientOverlay.svelte';
    import HoverWrapper from '~/components/HoverWrapper.svelte';
    import LinkWrapper from '~/components/LinkWrapper.svelte';
    import { colorAsString } from '~/utils/color';
    import { isRtl } from '~/utils/locale';
    import { sanitizeHtml } from '@amp/web-app-components/src/utils/sanitize-html';

    export let item: Brick;
    const artwork =
        isRtl() && item.rtlArtwork ? item.rtlArtwork : item.artworks?.[0];
    const collectionIcon = item.collectionIcons?.[0];
    let artworkFallbackColor: string | null = null;

    const gradientOverlayColor: string = artwork?.backgroundColor
        ? colorAsString(artwork.backgroundColor)
        : '#000';

    if (!artwork) {
        artworkFallbackColor = collectionIcon?.backgroundColor
            ? colorAsString(collectionIcon.backgroundColor)
            : '#000';
    }
</script>

<LinkWrapper action={item.clickAction}>
    <HoverWrapper>
        {#if artwork}
            <div class="artwork-container">
                <Artwork {artwork} profile="large-brick" />
            </div>
        {:else}
            <div
                class="gradient-container"
                style={`--color: ${artworkFallbackColor};`}
            />
        {/if}

        <div class="text-container">
            <div class="metadata-container">
                {#if item.caption}
                    <LineClamp clamp={1}>
                        <h4>{item.caption}</h4>
                    </LineClamp>
                {/if}

                {#if item.title}
                    <LineClamp clamp={2}>
                        <h3>{@html sanitizeHtml(item.title)}</h3>
                    </LineClamp>
                {/if}

                {#if item.subtitle}
                    <LineClamp clamp={2}>
                        <p>{item.subtitle}</p>
                    </LineClamp>
                {/if}
            </div>
        </div>

        <GradientOverlay --color={gradientOverlayColor} />
    </HoverWrapper>
</LinkWrapper>

<style>
    .artwork-container {
        width: 100%;
    }

    .gradient-container {
        width: 100%;
        aspect-ratio: 16 / 9;
        background-color: var(--color);
    }

    .text-container {
        position: absolute;
        z-index: 2;
        bottom: 0;
        display: flex;
        align-items: center;
        width: 66%;
        padding-inline: 20px;
        padding-bottom: 20px;
        color: var(--systemPrimary-onDark);
    }

    h3 {
        font: var(--title-1-emphasized);
        text-wrap: balance;
    }

    h4 {
        font: var(--callout-emphasized);
        margin-bottom: 3px;
    }

    p {
        font: var(--body-emphasized);
        margin-top: 6px;
    }
</style>