File size: 992 Bytes
74aacd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react'

type SliderProps = {
  label?: any
  value?: number
  min?: number
  max?: number
  onChange: (value: number) => void
  onClick?: () => void
  width?: number
}

export default function Slider(props: SliderProps) {
  const { value, onChange, onClick, label, min, max, width } = props
  const styles: any = {}
  if (width !== undefined) {
    styles.width = width
  }

  const step = ((max || 100) - (min || 0)) / 100

  const onMouseUp = (e: React.MouseEvent<HTMLDivElement>) => {
    e.currentTarget?.blur()
  }

  return (
    <div className="editor-brush-slider">
      <span>{label}</span>
      <input
        type="range"
        step={step}
        min={min}
        max={max}
        value={value}
        onChange={ev => {
          ev.preventDefault()
          ev.stopPropagation()
          onChange(parseInt(ev.currentTarget.value, 10))
        }}
        onClick={onClick}
        style={styles}
        onMouseUp={onMouseUp}
      />
    </div>
  )
}