Files
ianitor/packages/ui/src/Details.svelte
T

33 lines
1.0 KiB
Svelte

<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<script lang="ts">
// Handoff §2.14: the technical text behind "Show details". It never holds a secret.
let { detail, reference }: { detail: string; reference?: string } = $props();
let open = $state(false);
const id = "det-" + Math.random().toString(36).slice(2, 9);
const text = $derived(detail + (reference ? `\nReference: ${reference}` : ""));
</script>
<div class="ia-details">
<button
type="button"
class="domi-btn link"
aria-expanded={open}
aria-controls={id}
onclick={() => (open = !open)}
>
{open ? "Hide details" : "Show details"}
</button>
{#if open}
<div {id}>
<pre>{text}</pre>
<button
type="button"
class="domi-btn small"
onclick={() => navigator.clipboard?.writeText(text)}>Copy details</button
>
</div>
{/if}
</div>