aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Slider.svelte
blob: 137c28b4c4457a0a56a7e66b06c03575dd281f94 (plain) (blame)
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
<script lang="ts">
  interface Props {
    value: any;
    handle: any;
    min?: number;
    max?: number;
  }

  let {
    value = $bindable(),
    handle,
    min = 0,
    max = 100
  }: Props = $props();
</script>

<input
  id="slider"
  type="range"
  {min}
  {max}
  bind:value
  class="px-0 py-0 my-5"
  style="--bgPercent: {((value - min) * 100) / (max - min)}%;"
  oninput={handle}
/>

<style>
  #slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: linear-gradient(
      to right,
      black 0%,
      black var(--bgPercent),
      #f5f7fa var(--bgPercent),
      #f5f7fa 100%
    );
    outline: none;
  }

  #slider:active {
    background-color: black;
  }

  #slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: black;
    cursor: pointer;
  }

  #slider::-moz-range-thumb {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: black;
    cursor: pointer;
  }
</style>