adjust-element.svelte 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <script lang="ts">
  2. import { onMount, createEventDispatcher } from 'svelte';
  3. export let title = 'Free';
  4. export let type = false; // false = range from 0 to 100, true = range from 0 to 200 with default value of 100
  5. export let value = 0;
  6. let dispatch = createEventDispatcher();
  7. let progressBar: HTMLDivElement;
  8. let rangeValue = 0;
  9. $: if (type) {
  10. rangeValue = (value / 2) * 100;
  11. } else {
  12. rangeValue = value * 100;
  13. }
  14. onMount(() => {
  15. renderProgress();
  16. });
  17. const renderProgress = () => {
  18. const progress = rangeValue;
  19. if (type) {
  20. value = (progress * 2) / 100;
  21. } else {
  22. value = Number(progress) / 100;
  23. }
  24. const progressPercent = (progress / 100) * 100;
  25. let progressColor;
  26. if (type) {
  27. if (progress <= 50) {
  28. progressColor = `linear-gradient(90deg, #373737 ${progressPercent}%, #adcbfa ${progressPercent}%, #adcbfa 50%,#373737 50%)`;
  29. } else {
  30. progressColor = `linear-gradient(90deg, #373737 50%, #adcbfa 50%, #adcbfa ${progressPercent}%, #373737 ${progressPercent}%)`;
  31. }
  32. } else {
  33. progressColor = `linear-gradient(90deg, #adcbfa ${progressPercent}%,#373737 ${progressPercent}%)`;
  34. }
  35. progressBar.style.background = '#373737';
  36. progressBar.style.background = progressColor;
  37. //console.log(progressColor);
  38. dispatch('applyFilter');
  39. };
  40. </script>
  41. <div class="flex w-full text-white">
  42. <button
  43. class="{(type && value != 1) || (!type && value != 0)
  44. ? 'active-edit'
  45. : ''} bg-immich-gray/10 hover:bg-immich-gray/20 mr-3 rounded-full p-4 text-2xl"
  46. on:click={() => {
  47. if (type) {
  48. value = 1;
  49. rangeValue = 50;
  50. } else {
  51. value = 0;
  52. rangeValue = 0;
  53. }
  54. renderProgress();
  55. }}
  56. >
  57. <slot />
  58. </button>
  59. <div class="relative grid w-full">
  60. <span>{title}</span>
  61. <input bind:value={rangeValue} type="range" name="" id="" on:input={renderProgress} />
  62. <div
  63. bind:this={progressBar}
  64. class="bg-immich-gray/10 progress-bar pointer-events-none absolute bottom-[22px] h-[3px] w-full rounded-full"
  65. />
  66. </div>
  67. </div>
  68. <style>
  69. .active-edit {
  70. background-color: #adcbfa;
  71. color: rgb(33, 33, 33);
  72. }
  73. .active-edit:hover {
  74. background-color: #adcbfa;
  75. }
  76. input[type='range'] {
  77. font-size: 1.5rem;
  78. }
  79. input[type='range'] {
  80. color: #adcbfa;
  81. --thumb-height: 12px;
  82. --track-height: -1px;
  83. --track-color: rgba(246, 246, 244, 0);
  84. --brightness-hover: 100%;
  85. --brightness-down: 100%;
  86. --clip-edges: 0.125em;
  87. }
  88. /* === range commons === */
  89. input[type='range'] {
  90. position: relative;
  91. background: #fff0;
  92. overflow: hidden;
  93. }
  94. input[type='range']:active {
  95. cursor: grabbing;
  96. }
  97. input[type='range']:disabled {
  98. filter: grayscale(1);
  99. opacity: 0.3;
  100. cursor: not-allowed;
  101. }
  102. /* === WebKit specific styles === */
  103. input[type='range'],
  104. input[type='range']::-webkit-slider-runnable-track,
  105. input[type='range']::-webkit-slider-thumb {
  106. -webkit-appearance: none;
  107. transition: all ease 100ms;
  108. height: var(--thumb-height);
  109. }
  110. input[type='range']::-webkit-slider-runnable-track,
  111. input[type='range']::-webkit-slider-thumb {
  112. position: relative;
  113. }
  114. input[type='range']::-webkit-slider-thumb {
  115. --thumb-radius: calc((var(--thumb-height) * 0.5) - 1px);
  116. --clip-top: calc((var(--thumb-height) - var(--track-height)) * 0.5 - 0.5px);
  117. --clip-bottom: calc(var(--thumb-height) - var(--clip-top));
  118. --clip-further: calc(100% + 1px);
  119. --box-fill: calc(-100vmax - var(--thumb-width, var(--thumb-height))) 0 0 100vmax currentColor;
  120. width: var(--thumb-width, var(--thumb-height));
  121. background: linear-gradient(currentColor 0 0) scroll no-repeat left center / 50% calc(var(--track-height) + 1px);
  122. background-color: currentColor;
  123. box-shadow: var(--box-fill);
  124. border-radius: var(--thumb-width, var(--thumb-height));
  125. filter: brightness(100%);
  126. clip-path: polygon(
  127. 100% -1px,
  128. var(--clip-edges) -1px,
  129. 0 var(--clip-top),
  130. -100vmax var(--clip-top),
  131. -100vmax var(--clip-bottom),
  132. 0 var(--clip-bottom),
  133. var(--clip-edges) 100%,
  134. var(--clip-further) var(--clip-further)
  135. );
  136. }
  137. input[type='range']:hover::-webkit-slider-thumb {
  138. filter: brightness(var(--brightness-hover));
  139. cursor: grab;
  140. }
  141. input[type='range']:active::-webkit-slider-thumb {
  142. filter: brightness(var(--brightness-down));
  143. cursor: grabbing;
  144. }
  145. input[type='range']::-webkit-slider-runnable-track {
  146. background: linear-gradient(var(--track-color) 0 0) scroll no-repeat center / 100% calc(var(--track-height) + 1px);
  147. }
  148. input[type='range']:disabled::-webkit-slider-thumb {
  149. cursor: not-allowed;
  150. }
  151. /* === Firefox specific styles === */
  152. input[type='range'],
  153. input[type='range']::-moz-range-track,
  154. input[type='range']::-moz-range-thumb {
  155. appearance: none;
  156. transition: all ease 100ms;
  157. height: var(--thumb-height);
  158. }
  159. input[type='range']::-moz-range-track,
  160. input[type='range']::-moz-range-thumb,
  161. input[type='range']::-moz-range-progress {
  162. background: #fff0;
  163. }
  164. input[type='range']::-moz-range-thumb {
  165. background: currentColor;
  166. border: 0;
  167. width: var(--thumb-width, var(--thumb-height));
  168. border-radius: var(--thumb-width, var(--thumb-height));
  169. cursor: grab;
  170. }
  171. input[type='range']:active::-moz-range-thumb {
  172. cursor: grabbing;
  173. }
  174. input[type='range']::-moz-range-track {
  175. width: 100%;
  176. background: var(--track-color);
  177. }
  178. input[type='range']::-moz-range-progress {
  179. appearance: none;
  180. background: currentColor;
  181. transition-delay: 30ms;
  182. }
  183. input[type='range']::-moz-range-track,
  184. input[type='range']::-moz-range-progress {
  185. height: calc(var(--track-height) + 1px);
  186. border-radius: var(--track-height);
  187. }
  188. input[type='range']::-moz-range-thumb,
  189. input[type='range']::-moz-range-progress {
  190. filter: brightness(100%);
  191. }
  192. input[type='range']:hover::-moz-range-thumb,
  193. input[type='range']:hover::-moz-range-progress {
  194. filter: brightness(var(--brightness-hover));
  195. }
  196. input[type='range']:active::-moz-range-thumb,
  197. input[type='range']:active::-moz-range-progress {
  198. filter: brightness(var(--brightness-down));
  199. }
  200. input[type='range']:disabled::-moz-range-thumb {
  201. cursor: not-allowed;
  202. }
  203. </style>