Suggestions.svelte 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script lang="ts">
  2. import Bolt from '$lib/components/icons/Bolt.svelte';
  3. export let submitPrompt: Function;
  4. export let suggestionPrompts = [];
  5. let prompts = [];
  6. $: prompts = suggestionPrompts
  7. .reduce((acc, current) => [...acc, ...[current]], [])
  8. .sort(() => Math.random() - 0.5);
  9. // suggestionPrompts.length <= 4
  10. // ? suggestionPrompts
  11. // : suggestionPrompts.sort(() => Math.random() - 0.5).slice(0, 4);
  12. </script>
  13. {#if prompts.length > 0}
  14. <div class="mb-2 flex gap-1 text-sm font-medium items-center text-gray-400 dark:text-gray-600">
  15. <Bolt />
  16. Suggested
  17. </div>
  18. {/if}
  19. <div class="w-full">
  20. <div class="relative w-full flex gap-2 snap-x snap-mandatory overflow-x-auto tabs">
  21. {#each prompts as prompt, promptIdx}
  22. <div class="snap-center shrink-0">
  23. <button
  24. class="flex flex-col flex-1 shrink-0 w-64 justify-between h-36 p-5 px-6 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 rounded-3xl transition group"
  25. on:click={() => {
  26. submitPrompt(prompt.content);
  27. }}
  28. >
  29. <div class="flex flex-col text-left">
  30. {#if prompt.title && prompt.title[0] !== ''}
  31. <div
  32. class=" font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition"
  33. >
  34. {prompt.title[0]}
  35. </div>
  36. <div class="text-sm text-gray-600 font-normal line-clamp-2">{prompt.title[1]}</div>
  37. {:else}
  38. <div
  39. class=" self-center text-sm font-medium dark:text-gray-300 dark:group-hover:text-gray-100 transition line-clamp-2"
  40. >
  41. {prompt.content}
  42. </div>
  43. {/if}
  44. </div>
  45. <div class="w-full flex justify-between">
  46. <div
  47. class="text-xs text-gray-400 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-500 transition self-center"
  48. >
  49. Prompt
  50. </div>
  51. <div
  52. class="self-end p-1 rounded-lg text-gray-300 group-hover:text-gray-800 dark:text-gray-700 dark:group-hover:text-gray-100 transition"
  53. >
  54. <svg
  55. xmlns="http://www.w3.org/2000/svg"
  56. viewBox="0 0 16 16"
  57. fill="currentColor"
  58. class="size-4"
  59. >
  60. <path
  61. fill-rule="evenodd"
  62. 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"
  63. clip-rule="evenodd"
  64. />
  65. </svg>
  66. </div>
  67. </div>
  68. </button>
  69. </div>
  70. {/each}
  71. <!-- <div class="snap-center shrink-0">
  72. <img
  73. class="shrink-0 w-80 h-40 rounded-lg shadow-xl bg-white"
  74. 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"
  75. />
  76. </div> -->
  77. </div>
  78. </div>
  79. <style>
  80. .tabs::-webkit-scrollbar {
  81. display: none; /* for Chrome, Safari and Opera */
  82. }
  83. .tabs {
  84. -ms-overflow-style: none; /* IE and Edge */
  85. scrollbar-width: none; /* Firefox */
  86. }
  87. </style>