setting-select.svelte 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script lang="ts">
  2. import { quintOut } from 'svelte/easing';
  3. import { fly } from 'svelte/transition';
  4. export let value: string | number;
  5. export let options: { value: string | number; text: string }[];
  6. export let label = '';
  7. export let desc = '';
  8. export let name = '';
  9. export let isEdited = false;
  10. export let number = false;
  11. export let disabled = false;
  12. const handleChange = (e: Event) => {
  13. value = (e.target as HTMLInputElement).value;
  14. if (number) {
  15. value = parseInt(value);
  16. }
  17. };
  18. </script>
  19. <div class="mb-4 w-full">
  20. <div class={`flex h-[26px] place-items-center gap-1`}>
  21. <label class={`immich-form-label text-sm`} for="{name}-select">{label}</label>
  22. {#if isEdited}
  23. <div
  24. transition:fly={{ x: 10, duration: 200, easing: quintOut }}
  25. class="rounded-full bg-orange-100 px-2 text-[10px] text-orange-900"
  26. >
  27. Unsaved change
  28. </div>
  29. {/if}
  30. </div>
  31. {#if desc}
  32. <p class="immich-form-label pb-2 text-sm" id="{name}-desc">
  33. {desc}
  34. </p>
  35. {/if}
  36. <select
  37. class="immich-form-input w-full pb-2"
  38. {disabled}
  39. aria-describedby={desc ? `${name}-desc` : undefined}
  40. {name}
  41. id="{name}-select"
  42. bind:value
  43. on:change={handleChange}
  44. >
  45. {#each options as option}
  46. <option value={option.value}>{option.text}</option>
  47. {/each}
  48. </select>
  49. </div>