aboutsummaryrefslogtreecommitdiff
path: root/lib/components/Slider.svelte
blob: da584137cfb765f5026b14f2f5634508714e4593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<script lang="ts">
  interface Props {
    value: number
    min?: number
    max?: number
    step?: number
    label: string
    onChange: (value: number) => void
  }

  let {
    value,
    min = 0,
    max = 1,
    step = 0.01,
    label,
    onChange
  }: Props = $props()

  function handleInput(event: Event): void {
    const target = event.currentTarget as HTMLInputElement
    onChange(Number(target.value))
  }
</script>

<input
  type="range"
  {min}
  {max}
  {step}
  {value}
  aria-label={label}
  class="slider"
  oninput={handleInput}
/>

<style>
  .slider {
    -webkit-appearance: none;
    appearance: none;
    width: 200px;
    height: 2px;
    background: rgba(232, 226, 213, 0.12);
    outline: none;
    border-radius: 1px;
  }

  .slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
    border: none;
    transition: transform var(--transition-fast);
  }

  .slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
    border: none;
    transition: transform var(--transition-fast);
  }

  .slider:hover::-webkit-slider-thumb,
  .slider:focus-visible::-webkit-slider-thumb {
    transform: scale(1.15);
  }

  .slider:hover::-moz-range-thumb,
  .slider:focus-visible::-moz-range-thumb {
    transform: scale(1.15);
  }
</style>