web/SectionHeading: refactor to svelte 5 style

This commit is contained in:
wukko 2025-05-14 22:23:33 +06:00
parent d4ca8ece00
commit 08168f5477
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2

View File

@ -1,26 +1,30 @@
<script lang="ts"> <script lang="ts">
import { page } from "$app/stores"; import { page } from "$app/state";
import { copyURL } from "$lib/download"; import { copyURL } from "$lib/download";
import { t } from "$lib/i18n/translations"; import { t } from "$lib/i18n/translations";
import { hapticConfirm } from "$lib/haptics"; import { hapticConfirm } from "$lib/haptics";
import CopyIcon from "$components/misc/CopyIcon.svelte"; import CopyIcon from "$components/misc/CopyIcon.svelte";
export let title: string; type Props = {
export let sectionId: string; title: string;
export let beta = false; sectionId: string;
export let nolink = false; beta?: boolean;
export let copyData = ""; nolink?: boolean;
copyData?: string;
};
const sectionURL = `${$page.url.origin}${$page.url.pathname}#${sectionId}`; let {
title,
sectionId,
beta = false,
nolink = false,
copyData = "",
}: Props = $props();
let copied = false; const sectionURL = `${page.url.origin}${page.url.pathname}#${sectionId}`;
$: if (copied) { let copied = $state(false);
setTimeout(() => {
copied = false;
}, 1500);
}
</script> </script>
<div class="heading-container"> <div class="heading-container">
@ -40,11 +44,14 @@
aria-label={copied aria-label={copied
? $t("button.copied") ? $t("button.copied")
: $t(`button.copy${copyData ? "" : ".section"}`)} : $t(`button.copy${copyData ? "" : ".section"}`)}
on:click={() => { onclick={() => {
if (!copied) { if (!copied) {
copyURL(copyData || sectionURL); copyURL(copyData || sectionURL);
hapticConfirm(); hapticConfirm();
copied = true; copied = true;
setTimeout(() => {
copied = false;
}, 1500);
} }
}} }}
> >