Spaces:
Paused

File size: 2,703 Bytes
f942fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script lang="ts">
    import { page } from "$app/state";
    import { copyURL } from "$lib/download";
    import { t } from "$lib/i18n/translations";
    import { hapticConfirm } from "$lib/haptics";

    import CopyIcon from "$components/misc/CopyIcon.svelte";

    type Props = {
        title: string;
        sectionId: string;
        beta?: boolean;
        nolink?: boolean;
        copyData?: string;
    };

    let {
        title,
        sectionId,
        beta = false,
        nolink = false,
        copyData = "",
    }: Props = $props();

    const sectionURL = $derived(`${page.url.origin}${page.url.pathname}#${sectionId}`);

    let copied = $state(false);
</script>

<div class="heading-container">
    <h3 id="{sectionId}-title" class="content-title">
        {title}
    </h3>

    {#if beta}
        <div class="beta-label">
            {$t("general.beta")}
        </div>
    {/if}

    {#if !nolink}
        <button
            class="link-copy"
            aria-label={copied
                ? $t("button.copied")
                : $t(`button.copy${copyData ? "" : ".section"}`)}
            onclick={() => {
                if (!copied) {
                    copyURL(copyData || sectionURL);
                    hapticConfirm();
                    copied = true;
                    setTimeout(() => {
                        copied = false;
                    }, 1500);
                }
            }}
        >
            <CopyIcon check={copied} regularIcon={!!copyData} />
        </button>
    {/if}
</div>

<style>
    .heading-container {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap-reverse;
        gap: 6px;
        justify-content: start;
        align-items: center;
        box-shadow: none;
    }

    .link-copy {
        background: transparent;
        padding: 2px;
        box-shadow: none;
        border-radius: 5px;
        transition: opacity 0.2s;
        opacity: 0.7;
    }

    .link-copy:focus-visible {
        opacity: 1;
        outline-offset: 0;
    }

    .link-copy :global(.copy-animation) {
        width: 17px;
        height: 17px;
    }

    .link-copy :global(.copy-animation *) {
        width: 17px;
        height: 17px;
    }

    .beta-label {
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 5px;
        padding: 0 5px;
        background: var(--secondary);
        color: var(--primary);
        font-size: 11px;
        font-weight: 500;
        line-height: 1.86;
        text-transform: uppercase;
    }

    @media (hover: hover) {
        .heading-container:hover .link-copy {
            opacity: 1;
        }
    }
</style>