~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/spaces-bookclub

Book club: a Svelte demo app for atproto spaces (@atproto/lex-space)

0
0
main
43 lines · 1.1 KB Raw History
<script lang="ts">
  import Button from '../atoms/Button.svelte'

  let { value, label }: { value: string; label: string } = $props()

  let copied = $state(false)
  let timer: ReturnType<typeof setTimeout> | undefined

  async function copy() {
    await navigator.clipboard.writeText(value)
    copied = true
    clearTimeout(timer)
    timer = setTimeout(() => (copied = false), 2000)
  }
</script>

<div class="copy-field">
  <code aria-label={label}>{value}</code>
  <Button size="sm" icon={copied ? 'check' : 'copy'} onclick={copy}>
    {copied ? 'Copied' : 'Copy'}
  </Button>
</div>

<style>
  .copy-field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    padding-left: var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-sunken);
  }
  code {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    overflow-wrap: anywhere;
    color: var(--color-text-muted);
  }
</style>