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

    const ARTWORK_TYPE: BadgeType = 'artwork';
    const CONTENT_RATING_TYPE: BadgeType = 'contentRating';
    const CONTENT_RATING_KEY = 'contentRating';

    interface ContentRatingBadge extends Badge {
        type: typeof CONTENT_RATING_TYPE;
    }

    export function isContentRatingBadge(
        badge: Badge,
    ): badge is ContentRatingBadge {
        return (
            badge.type === CONTENT_RATING_TYPE ||
            (badge.key === CONTENT_RATING_KEY && badge.type === ARTWORK_TYPE)
        );
    }
</script>

<script lang="ts">
    import SystemImage, {
        isSystemImageArtwork,
    } from '~/components/SystemImage.svelte';

    export let badge: ContentRatingBadge;

    $: ({ artwork, accessibilityTitle } = badge);
</script>

{#if artwork && isSystemImageArtwork(artwork)}
    <div class="pictogram-container" aria-label={accessibilityTitle}>
        <SystemImage {artwork} />
    </div>
{:else}
    <span>
        {badge.content.contentRating}
    </span>
{/if}

<style>
    span {
        height: 25px;
        margin: 4px 0 2px;
        font: var(--title-1-emphasized);
        color: var(--color);
    }

    .pictogram-container {
        height: 25px;
        padding: 2px;
        aspect-ratio: 1/1;
        margin: 4px 0 2px;
    }

    .pictogram-container :global(svg) {
        width: 21px;
        height: 21px;
    }
</style>