Suggestions.svelte 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script lang="ts">
  2. export let submitPrompt: Function;
  3. export let suggestionPrompts = [];
  4. let prompts = [];
  5. $: prompts = suggestionPrompts;
  6. // suggestionPrompts.length <= 4
  7. // ? suggestionPrompts
  8. // : suggestionPrompts.sort(() => Math.random() - 0.5).slice(0, 4);
  9. </script>
  10. <div class="w-full">
  11. <div class="relative w-full flex gap-2 snap-x overflow-x-auto tabs">
  12. {#each prompts as prompt, promptIdx}
  13. <div class="shrink-0">
  14. <button
  15. class="flex flex-1 shrink-0 w-64 justify-between h-full px-5 py-3 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 rounded-3xl transition group"
  16. on:click={() => {
  17. submitPrompt(prompt.content);
  18. }}
  19. >
  20. <div class="flex flex-col text-left self-center">
  21. {#if prompt.title && prompt.title[0] !== ''}
  22. <div class="text-sm font-medium dark:text-gray-300">{prompt.title[0]}</div>
  23. <div class="text-sm text-gray-500 font-normal line-clamp-1">{prompt.title[1]}</div>
  24. {:else}
  25. <div class=" self-center text-sm font-medium dark:text-gray-300 line-clamp-2">
  26. {prompt.content}
  27. </div>
  28. {/if}
  29. </div>
  30. <div
  31. class="self-center p-1 rounded-lg text-gray-50 group-hover:text-gray-800 dark:text-gray-850 dark:group-hover:text-gray-100 transition"
  32. >
  33. <svg
  34. xmlns="http://www.w3.org/2000/svg"
  35. viewBox="0 0 16 16"
  36. fill="currentColor"
  37. class="w-4 h-4"
  38. >
  39. <path
  40. fill-rule="evenodd"
  41. d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z"
  42. clip-rule="evenodd"
  43. />
  44. </svg>
  45. </div>
  46. </button>
  47. </div>
  48. {/each}
  49. <!-- <div class="snap-center shrink-0">
  50. <img
  51. class="shrink-0 w-80 h-40 rounded-lg shadow-xl bg-white"
  52. src="https://images.unsplash.com/photo-1604999565976-8913ad2ddb7c?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=320&amp;h=160&amp;q=80"
  53. />
  54. </div> -->
  55. </div>
  56. </div>
  57. <style>
  58. .tabs::-webkit-scrollbar {
  59. display: none; /* for Chrome, Safari and Opera */
  60. }
  61. .tabs {
  62. -ms-overflow-style: none; /* IE and Edge */
  63. scrollbar-width: none; /* Firefox */
  64. }
  65. </style>