summaryrefslogtreecommitdiff
path: root/src/components/jet/shelf/FramedArtworkShelf.svelte
blob: 16f7c481faadfc93e71b9791b9b96d206dbc3ef5 (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
<script lang="ts" context="module">
    import type { FramedArtwork, Shelf } from '@jet-app/app-store/api/models';

    interface FramedArtworkShelf extends Shelf {
        contentType: 'framedArtwork';
        items: [FramedArtwork];
    }

    export function isFramedArtworkShelf(
        shelf: Shelf,
    ): shelf is FramedArtworkShelf {
        return (
            shelf.contentType === 'framedArtwork' && Array.isArray(shelf.items)
        );
    }
</script>

<script lang="ts">
    import { sanitizeHtml } from '@amp/web-app-components/src/utils/sanitize-html';
    import Artwork, { getNaturalProfile } from '~/components/Artwork.svelte';
    import ShelfWrapper from '~/components/Shelf/Wrapper.svelte';

    export let shelf: FramedArtworkShelf;

    $: item = shelf.items[0];
    $: ({ artwork, caption, hasRoundedCorners } = item);
    $: profile = getNaturalProfile(artwork, [1275, 1185, 825, 500, 690]);
    $: aspectRatio = artwork.width / artwork.height;
    $: isPortrait = aspectRatio < 1;
</script>

<ShelfWrapper {shelf} withBottomPadding={false}>
    <figure
        class="framed-artwork-item"
        class:has-rounded-corners={hasRoundedCorners}
        class:is-portrait={isPortrait}
    >
        <div
            class="artwork-container"
            style:--aspect-ratio={artwork.width / artwork.height}
        >
            <Artwork {artwork} {profile} forceFullWidth={!isPortrait} />
        </div>

        {#if caption}
            <figcaption class="caption">
                {@html sanitizeHtml(caption)}
            </figcaption>
        {/if}
    </figure>
</ShelfWrapper>

<style lang="scss">
    @use '@amp/web-shared-styles/app/core/globalvars' as *;

    .framed-artwork-item {
        border-radius: var(--framed-artwork-border-radius);
        padding: 0 20px;
        overflow: hidden;

        @media (--sidebar-visible) {
            padding: 0 20px;
        }

        @media (--range-small-only) {
            padding: 0 var(--bodyGutter);
        }
    }

    .framed-artwork-item.has-rounded-corners {
        --framed-artwork-border-radius: var(--global-border-radius-medium);
    }

    .artwork-container {
        border-radius: inherit;
    }

    .caption {
        border-bottom-left-radius: var(--framed-artwork-border-radius);
        border-bottom-right-radius: var(--framed-artwork-border-radius);
        color: var(--systemSecondary);
        padding: 8px var(--article-page-padding) 0;
    }

    .framed-artwork-item.is-portrait {
        --artwork-override-max-height: 560px;
        --artwork-override-max-width: 100%;
        --artwork-override-width: auto;
    }

    .framed-artwork-item.framed-artwork-item.is-portrait .artwork-container {
        display: flex;
        justify-content: center;
        width: 100%;
        max-height: var(--artwork-override-max-height);
        aspect-ratio: var(--aspect-ratio);
    }
</style>