AddTextContentModal.svelte 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import dayjs from 'dayjs';
  4. import { onMount, getContext, createEventDispatcher } from 'svelte';
  5. const i18n = getContext('i18n');
  6. const dispatch = createEventDispatcher();
  7. import Modal from '$lib/components/common/Modal.svelte';
  8. import RichTextInput from '$lib/components/common/RichTextInput.svelte';
  9. import XMark from '$lib/components/icons/XMark.svelte';
  10. export let show = false;
  11. let name = 'Untitled';
  12. let content = '';
  13. </script>
  14. <Modal size="full" className="h-full bg-white dark:bg-gray-900" bind:show>
  15. <div class="absolute top-0 right-0 p-5">
  16. <button
  17. class="self-center dark:text-white"
  18. type="button"
  19. on:click={() => {
  20. show = false;
  21. }}
  22. >
  23. <XMark className="size-4" />
  24. </button>
  25. </div>
  26. <div class="flex flex-col md:flex-row w-full h-full md:space-x-4 dark:text-gray-200">
  27. <form
  28. class="flex flex-col w-full h-full"
  29. on:submit|preventDefault={() => {
  30. if (name.trim() === '' || content.trim() === '') {
  31. toast.error($i18n.t('Please fill in all fields.'));
  32. name = name.trim();
  33. content = content.trim();
  34. return;
  35. }
  36. dispatch('submit', {
  37. name,
  38. content
  39. });
  40. show = false;
  41. name = '';
  42. content = '';
  43. }}
  44. >
  45. <div class=" flex-1 w-full h-full flex justify-center overflow-auto px-5 py-4">
  46. <div class=" max-w-3xl py-2 md:py-14 w-full flex flex-col gap-2">
  47. <div class="flex-shrink-0 w-full flex justify-between items-center">
  48. <div class="w-full">
  49. <input
  50. class="w-full text-3xl font-semibold rounded-lg bg-transparent outline-none"
  51. type="text"
  52. bind:value={name}
  53. placeholder={$i18n.t('Title')}
  54. required
  55. />
  56. </div>
  57. </div>
  58. <div class=" flex-1 w-full h-full">
  59. <RichTextInput bind:value={content} placeholder={$i18n.t('Content')} />
  60. </div>
  61. </div>
  62. </div>
  63. <div class="flex justify-end text-sm font-medium flex-shrink-0 mt-1 py-3 px-3">
  64. <button
  65. class=" px-3.5 py-2 bg-black text-white dark:bg-white dark:text-black transition rounded-full"
  66. type="submit"
  67. >
  68. {$i18n.t('Save')}
  69. </button>
  70. </div>
  71. </form>
  72. </div>
  73. </Modal>
  74. <style>
  75. input::-webkit-outer-spin-button,
  76. input::-webkit-inner-spin-button {
  77. /* display: none; <- Crashes Chrome on hover */
  78. -webkit-appearance: none;
  79. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  80. }
  81. .tabs::-webkit-scrollbar {
  82. display: none; /* for Chrome, Safari and Opera */
  83. }
  84. .tabs {
  85. -ms-overflow-style: none; /* IE and Edge */
  86. scrollbar-width: none; /* Firefox */
  87. }
  88. input[type='number'] {
  89. -moz-appearance: textfield; /* Firefox */
  90. }
  91. </style>