summaryrefslogtreecommitdiff
path: root/ui/lib/components/Message.svelte
blob: ea6e30456eb230423c3acee4ba07713f21bfb80f (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
<script>
  import { marked } from 'marked';
  import DOMPurify from 'dompurify';

  function scroll(message) {
    message.scrollIntoView();
  }

  let { at, body } = $props();
  let renderedBody = $derived(DOMPurify.sanitize(marked.parse(body, { breaks: true })));
</script>

<div class="message relative">
  <span class="timestamp chip variant-soft absolute top-0 right-0">{at}</span>
  <section use:scroll class="py-1 message-body">
    <!-- eslint-disable-next-line svelte/no-at-html-tags -->
    {@html renderedBody}
  </section>
</div>

<style>
  .message .timestamp {
    display: none;
  }
  .message:hover .timestamp {
    display: flex;
  }
  .message-body {
      overflow: auto;
      max-width: 80vw;
      @media (width > 640px) {
          /* 21rem is width of the nav bar in full-screen mode. */
          max-width: calc(90vw - 21rem);
      }
  }
  .message-body:empty:after {
    content: '.';
    visibility: hidden;
  }
</style>