Suggestions.svelte 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <script lang="ts">
  2. import Bolt from '$lib/components/icons/Bolt.svelte';
  3. import { onMount, getContext, createEventDispatcher } from 'svelte';
  4. const i18n = getContext('i18n');
  5. const dispatch = createEventDispatcher();
  6. export let suggestionPrompts = [];
  7. export let className = '';
  8. let prompts = [];
  9. $: prompts = (suggestionPrompts ?? [])
  10. .reduce((acc, current) => [...acc, ...[current]], [])
  11. .sort(() => Math.random() - 0.5);
  12. </script>
  13. {#if prompts.length > 0}
  14. <div class="mb-1 flex gap-1 text-sm font-medium items-center text-gray-400 dark:text-gray-600">
  15. <Bolt />
  16. {$i18n.t('Suggested')}
  17. </div>
  18. {/if}
  19. <div class=" h-40 max-h-full overflow-auto scrollbar-none {className}">
  20. {#each prompts as prompt, promptIdx}
  21. <button
  22. class="flex flex-col flex-1 shrink-0 w-full justify-between px-3 py-2 rounded-xl bg-transparent hover:bg-black/5 dark:hover:bg-white/5 transition group"
  23. on:click={() => {
  24. dispatch('select', prompt.content);
  25. }}
  26. >
  27. <div class="flex flex-col text-left">
  28. {#if prompt.title && prompt.title[0] !== ''}
  29. <div
  30. class=" font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition line-clamp-1"
  31. >
  32. {prompt.title[0]}
  33. </div>
  34. <div class="text-xs text-gray-500 font-normal line-clamp-1">{prompt.title[1]}</div>
  35. {:else}
  36. <div
  37. class=" font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition line-clamp-1"
  38. >
  39. {prompt.content}
  40. </div>
  41. <div class="text-xs text-gray-500 font-normal line-clamp-1">Prompt</div>
  42. {/if}
  43. </div>
  44. </button>
  45. {/each}
  46. </div>