SensitiveInput.svelte 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script lang="ts">
  2. export let value: string = '';
  3. export let placeholder = '';
  4. export let required = true;
  5. export let readOnly = false;
  6. export let outerClassName = 'flex flex-1';
  7. export let inputClassName =
  8. 'w-full rounded-l-lg py-2 pl-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none';
  9. export let showButtonClassName = 'px-2 transition rounded-r-lg bg-gray-50 dark:bg-gray-850';
  10. let show = false;
  11. </script>
  12. <div class={outerClassName}>
  13. <input
  14. class={inputClassName}
  15. class:dot={!show}
  16. {placeholder}
  17. bind:value
  18. required={required && !readOnly}
  19. disabled={readOnly}
  20. autocomplete="off"
  21. type="text"
  22. />
  23. <button
  24. class={showButtonClassName}
  25. on:click={(e) => {
  26. e.preventDefault();
  27. show = !show;
  28. }}
  29. >
  30. {#if show}
  31. <svg
  32. xmlns="http://www.w3.org/2000/svg"
  33. viewBox="0 0 16 16"
  34. fill="currentColor"
  35. class="w-4 h-4"
  36. >
  37. <path
  38. fill-rule="evenodd"
  39. d="M3.28 2.22a.75.75 0 0 0-1.06 1.06l10.5 10.5a.75.75 0 1 0 1.06-1.06l-1.322-1.323a7.012 7.012 0 0 0 2.16-3.11.87.87 0 0 0 0-.567A7.003 7.003 0 0 0 4.82 3.76l-1.54-1.54Zm3.196 3.195 1.135 1.136A1.502 1.502 0 0 1 9.45 8.389l1.136 1.135a3 3 0 0 0-4.109-4.109Z"
  40. clip-rule="evenodd"
  41. />
  42. <path
  43. d="m7.812 10.994 1.816 1.816A7.003 7.003 0 0 1 1.38 8.28a.87.87 0 0 1 0-.566 6.985 6.985 0 0 1 1.113-2.039l2.513 2.513a3 3 0 0 0 2.806 2.806Z"
  44. />
  45. </svg>
  46. {:else}
  47. <svg
  48. xmlns="http://www.w3.org/2000/svg"
  49. viewBox="0 0 16 16"
  50. fill="currentColor"
  51. class="w-4 h-4"
  52. >
  53. <path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z" />
  54. <path
  55. fill-rule="evenodd"
  56. d="M1.38 8.28a.87.87 0 0 1 0-.566 7.003 7.003 0 0 1 13.238.006.87.87 0 0 1 0 .566A7.003 7.003 0 0 1 1.379 8.28ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
  57. clip-rule="evenodd"
  58. />
  59. </svg>
  60. {/if}
  61. </button>
  62. </div>
  63. <style>
  64. .dot {
  65. -webkit-text-security: disc;
  66. }
  67. </style>