|
1 | 1 | <script lang="ts">
|
2 | 2 | import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
|
3 |
| - import CarbonCaretRight from "~icons/carbon/caret-right"; |
4 | 3 |
|
5 |
| - import CarbonCheckmark from "~icons/carbon/checkmark-filled"; |
6 | 4 | import CarbonError from "~icons/carbon/error-filled";
|
7 |
| -
|
8 | 5 | import EosIconsLoading from "~icons/eos-icons/loading";
|
| 6 | + import IconInternet from "./icons/IconInternet.svelte"; |
9 | 7 |
|
10 |
| - export let loading = false; |
11 | 8 | export let classNames = "";
|
12 | 9 | export let webSearchMessages: WebSearchUpdate[] = [];
|
13 | 10 |
|
14 |
| - let detailsOpen: boolean; |
15 |
| - let error: boolean; |
16 |
| - $: error = webSearchMessages[webSearchMessages.length - 1]?.messageType === "error"; |
| 11 | + $: sources = webSearchMessages.find((m) => m.sources)?.sources; |
| 12 | + $: error = webSearchMessages.find((m) => m.messageType === "error"); |
| 13 | + $: loading = !sources && !error; |
17 | 14 | </script>
|
18 | 15 |
|
19 | 16 | <details
|
20 | 17 | class="flex w-fit rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-900 {classNames} max-w-full"
|
21 |
| - bind:open={detailsOpen} |
22 | 18 | >
|
23 |
| - <summary |
24 |
| - class="align-center flex cursor-pointer select-none list-none py-1 pl-2.5 pr-2 align-text-top transition-all" |
25 |
| - > |
26 |
| - {#if error} |
27 |
| - <CarbonError class="my-auto text-red-700 dark:text-red-500" /> |
28 |
| - {:else if loading} |
29 |
| - <EosIconsLoading class="my-auto text-gray-500" /> |
30 |
| - {:else} |
31 |
| - <CarbonCheckmark class="my-auto text-gray-500" /> |
32 |
| - {/if} |
33 |
| - <span class="px-2 font-medium" class:text-red-700={error} class:dark:text-red-500={error}> |
34 |
| - Web search |
35 |
| - </span> |
36 |
| - <div class="my-auto transition-all" class:rotate-90={detailsOpen}> |
37 |
| - <CarbonCaretRight /> |
| 19 | + <summary class="grid min-w-72 select-none grid-cols-[40px,1fr] items-center gap-2.5 p-2"> |
| 20 | + <div |
| 21 | + class="relative grid aspect-square place-content-center overflow-hidden rounded-lg bg-gray-100 dark:bg-gray-800" |
| 22 | + > |
| 23 | + <svg |
| 24 | + class="absolute inset-0 text-gray-300 transition-opacity dark:text-gray-700 {loading |
| 25 | + ? 'opacity-100' |
| 26 | + : 'opacity-0'}" |
| 27 | + width="40" |
| 28 | + height="40" |
| 29 | + viewBox="0 0 38 38" |
| 30 | + fill="none" |
| 31 | + xmlns="http://www.w3.org/2000/svg" |
| 32 | + > |
| 33 | + <path |
| 34 | + class="loading-path" |
| 35 | + d="M8 2.5H30C30 2.5 35.5 2.5 35.5 8V30C35.5 30 35.5 35.5 30 35.5H8C8 35.5 2.5 35.5 2.5 30V8C2.5 8 2.5 2.5 8 2.5Z" |
| 36 | + stroke="currentColor" |
| 37 | + stroke-width="1" |
| 38 | + stroke-linecap="round" |
| 39 | + id="shape" |
| 40 | + /> |
| 41 | + </svg> |
| 42 | + <IconInternet classNames="relative fill-current text-xl" /> |
38 | 43 | </div>
|
| 44 | + <dl class="leading-4"> |
| 45 | + <dd class="text-sm">Web Search</dd> |
| 46 | + <dt class="flex items-center gap-1 truncate whitespace-nowrap text-[.82rem] text-gray-400"> |
| 47 | + {#if error} |
| 48 | + {error.message} |
| 49 | + {:else if sources} |
| 50 | + Completed |
| 51 | + {:else} |
| 52 | + {webSearchMessages[webSearchMessages.length - 1].message} |
| 53 | + {/if} |
| 54 | + </dt> |
| 55 | + </dl> |
39 | 56 | </summary>
|
40 | 57 |
|
41 | 58 | <div class="content px-5 pb-5 pt-4">
|
|
88 | 105 | </details>
|
89 | 106 |
|
90 | 107 | <style>
|
91 |
| - @keyframes grow { |
92 |
| - 0% { |
93 |
| - font-size: 0; |
94 |
| - opacity: 0; |
95 |
| - } |
96 |
| - 30% { |
97 |
| - font-size: 1em; |
98 |
| - opacity: 0; |
99 |
| - } |
100 |
| - 100% { |
101 |
| - opacity: 1; |
102 |
| - } |
| 108 | + details summary::-webkit-details-marker { |
| 109 | + display: none; |
103 | 110 | }
|
104 | 111 |
|
105 |
| - details[open] .content { |
106 |
| - animation-name: grow; |
107 |
| - animation-duration: 300ms; |
108 |
| - animation-delay: 0ms; |
| 112 | + .loading-path { |
| 113 | + stroke-dasharray: 61.45; |
| 114 | + animation: loading 2s linear infinite; |
109 | 115 | }
|
110 | 116 |
|
111 |
| - details summary::-webkit-details-marker { |
112 |
| - display: none; |
| 117 | + @keyframes loading { |
| 118 | + to { |
| 119 | + stroke-dashoffset: 122.9; |
| 120 | + } |
113 | 121 | }
|
114 | 122 | </style>
|
0 commit comments