summaryrefslogtreecommitdiff
path: root/src/components/jet/shelf/RibbonBarShelf.svelte
blob: 44a8ae9204246c223c8320c975794d19c8025359 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<script lang="ts" context="module">
    import type { Shelf, RibbonBarItem } from '@jet-app/app-store/api/models';

    interface RibbonBarShelf extends Shelf {
        items: RibbonBarItem[];
    }

    export function isRibbonBarShelf(shelf: Shelf): shelf is RibbonBarShelf {
        return shelf.contentType === 'ribbonBar' && Array.isArray(shelf.items);
    }
</script>

<script lang="ts">
    import Artwork, { getNaturalProfile } from '~/components/Artwork.svelte';
    import LinkWrapper from '~/components/LinkWrapper.svelte';
    import ShelfWrapper from '~/components/Shelf/Wrapper.svelte';
    import SystemImage, {
        isSystemImageArtwork,
    } from '~/components/SystemImage.svelte';

    export let shelf: RibbonBarShelf;
</script>

<ShelfWrapper {shelf} withBottomPadding={false} withPaddingTop={false}>
    <div class="scroll">
        <ul>
            {#each shelf.items as ribbonBarItem}
                {@const action = ribbonBarItem.clickAction}
                {@const artwork = ribbonBarItem.artwork}
                {@const title = ribbonBarItem.title}
                <li>
                    <LinkWrapper {action}>
                        {#if artwork}
                            <div
                                class="artwork-container"
                                style:--aspect-ratio={artwork.width /
                                    artwork.height}
                            >
                                {#if isSystemImageArtwork(artwork)}
                                    <SystemImage {artwork} />
                                {:else}
                                    <Artwork
                                        {artwork}
                                        profile={getNaturalProfile(artwork, [
                                            17,
                                        ])}
                                        hasTransparentBackground
                                    />
                                {/if}
                            </div>
                        {/if}
                        {title}
                    </LinkWrapper>
                </li>
            {/each}
        </ul>
    </div>
</ShelfWrapper>

<style lang="scss">
    @use '@amp/web-shared-styles/sasskit-stylekit/ac-sasskit-config';
    @use 'ac-sasskit/core/helpers' as *;
    @use 'ac-sasskit/core/locale' as *;

    .scroll {
        --gradient-direction: 90deg;
        overflow-x: auto;
        scrollbar-width: none;
        padding-inline-start: var(--bodyGutter);
        margin-inline-end: var(--bodyGutter);
        // A small gradient that fades out the ribbon, to indicate that there is more
        mask-image: linear-gradient(
            var(--gradient-direction),
            black calc(100% - 8px),
            transparent 100%
        );

        @include rtl {
            --gradient-direction: -90deg;
        }
    }

    ul {
        font: var(--body-emphasized);
        display: flex;
        gap: 4px;
        padding-bottom: 16px;
        padding-top: 13px;
    }

    li {
        display: flex;
        margin-inline-end: 8px;
        flex-shrink: 0;
    }

    li:last-of-type {
        padding-inline-end: 8px;
    }

    li :global(a) {
        position: relative;
        display: flex;
        align-items: center;
        gap: 4px;
        flex-shrink: 0;
        background: var(--pageBG);
        border-radius: var(--global-border-radius-small);
        padding: 6px 10px;

        &::after {
            content: '';
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: var(--global-border-radius-small);
            box-shadow: var(--shadow-small);
            z-index: calc(var(--z-default) - 1);
        }

        @media (prefers-color-scheme: dark) {
            background: var(--systemGray5-default_IC);
        }
    }

    .artwork-container {
        --artwork-override-height: 17px;
        flex-shrink: 0;
        aspect-ratio: var(--aspect-ratio);
        height: 17px;
    }
</style>