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

    interface ProductDescriptionShelf extends Shelf {
        items: [ProductDescription];
    }

    export function isProductDescriptionShelf(
        shelf: Shelf,
    ): shelf is ProductDescriptionShelf {
        const { contentType, items } = shelf;

        return contentType === 'productDescription' && Array.isArray(items);
    }
</script>

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

    export let shelf: ProductDescriptionShelf;

    const i18n = getI18n();
    const description = shelf.items[0]?.paragraph.text;
    const handleMoreClick = () => (isOpen = true);
    let isOpen = false;

    function handleLineClampResize(event: CustomEvent) {
        if (!event.detail.truncated) {
            isOpen = true;
        }
    }
</script>

<ShelfWrapper centered>
    <article>
        <p>
            {#if isOpen}
                {@html sanitizeHtml(description)}
            {:else}
                <LineClamp observe clamp={5} on:resize={handleLineClampResize}>
                    {@html sanitizeHtml(description)}
                </LineClamp>
            {/if}

            {#if !isOpen}
                <button on:click={handleMoreClick}>
                    {$i18n.t('ASE.Web.AppStore.More')}
                </button>
            {/if}
        </p>
    </article>
</ShelfWrapper>

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

    p {
        white-space: break-spaces;
        font: var(--body-tall);
        position: relative;
        display: flex;
        flex-direction: column;

        @media (--range-medium-up) {
            width: 66%;
        }
    }

    button {
        --gradient-direction: 270deg;
        display: flex;
        justify-content: end;
        position: absolute;
        bottom: 0;
        inset-inline-end: 0;
        padding-inline-start: 20px;
        color: var(--keyColor);
        background: linear-gradient(
            var(--gradient-direction),
            var(--pageBg) 72%,
            transparent 100%
        );

        @include rtl {
            --gradient-direction: 90deg;
        }
    }
</style>