|
1 | 1 | <script>
|
2 | 2 | import a2s from '@svelement-ui/util-array-2-class-string';
|
| 3 | + import { string as toStyleObject } from 'to-style'; |
3 | 4 |
|
| 5 | + export let vertical = false; |
| 6 | + let button; |
4 | 7 | $: hovering = false;
|
5 | 8 | $: dragging = false;
|
6 | 9 | $: wrapperClass = a2s([
|
7 | 10 | `svel-slider__button-wrapper`,
|
8 | 11 | ['hover', hovering],
|
9 | 12 | ['dragging', dragging],
|
10 | 13 | ]);
|
11 |
| - $: wrapperStyle = null; |
| 14 | + $: wrapperStyle = {}; |
| 15 | + $: wrapperStyleStr = toStyleObject(wrapperStyle); |
12 | 16 | $: buttonClass = a2s([`svel-slider__button`, ['hover', hovering], ['dragging', dragging]]);
|
| 17 | +
|
| 18 | + $: disabled = false; |
| 19 | + $: isClick = false; |
| 20 | + $: isClick = false; |
| 21 | + $: startY = 0; |
| 22 | + $: startX = 0; |
| 23 | + $: startPosition = 0; |
| 24 | + $: currentPosition = 0; |
| 25 | + $: newPosition = 0; |
| 26 | + $: currentY = 0; |
| 27 | + $: currentX = 0; |
| 28 | +
|
| 29 | + function handleMouseEnter() { |
| 30 | + hovering = true; |
| 31 | + // displayTooltip() |
| 32 | + } |
| 33 | +
|
| 34 | + function handleMouseLeave() { |
| 35 | + hovering = false; |
| 36 | + if (!dragging) { |
| 37 | + // hideTooltip() |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + function onButtonDown(event) { |
| 42 | + if (disabled) return; |
| 43 | + // onDragStart(event); |
| 44 | + // window.addEventListener('mousemove', onDragging); |
| 45 | + // window.addEventListener('touchmove', onDragging); |
| 46 | + // window.addEventListener('mouseup', onDragEnd); |
| 47 | + // window.addEventListener('touchend', onDragEnd); |
| 48 | + // window.addEventListener('contextmenu', onDragEnd); |
| 49 | + button.focus(); |
| 50 | + } |
| 51 | +
|
| 52 | + // function onDragStart(event) { |
| 53 | + // dragging = true; |
| 54 | + // isClick = true; |
| 55 | + // const { clientX, clientY } = getClientXY(event); |
| 56 | + // if (vertical) { |
| 57 | + // startY = clientY; |
| 58 | + // } else { |
| 59 | + // startX = clientX; |
| 60 | + // } |
| 61 | + // startPosition = Number.parseFloat(currentPosition.value); |
| 62 | + // newPosition = startPosition; |
| 63 | + // } |
| 64 | + // |
| 65 | + // function onDragging(event) { |
| 66 | + // if (dragging) { |
| 67 | + // isClick = false; |
| 68 | + // displayTooltip(); |
| 69 | + // resetSize(); |
| 70 | + // let diff; |
| 71 | + // const { clientX, clientY } = getClientXY(event); |
| 72 | + // if (vertical) { |
| 73 | + // currentY = clientY; |
| 74 | + // diff = ((startY - currentY) / sliderSize) * 100; |
| 75 | + // } else { |
| 76 | + // currentX = clientX; |
| 77 | + // diff = ((currentX - startX) / sliderSize) * 100; |
| 78 | + // } |
| 79 | + // newPosition = startPosition + diff; |
| 80 | + // setPosition(newPosition); |
| 81 | + // } |
| 82 | + // } |
13 | 83 | </script>
|
14 | 84 |
|
15 |
| -<div class={wrapperClass} style={wrapperStyle}> |
| 85 | +<div |
| 86 | + aria-valuenow="0" |
| 87 | + bind:this={button} |
| 88 | + class={wrapperClass} |
| 89 | + on:blur={handleMouseLeave} |
| 90 | + on:focus={handleMouseEnter} |
| 91 | + on:mousedown|preventDefault={onButtonDown} |
| 92 | + on:mouseenter={handleMouseEnter} |
| 93 | + on:mouseleave={handleMouseLeave} |
| 94 | + on:touchstart|preventDefault={onButtonDown} |
| 95 | + role="slider" |
| 96 | + style={wrapperStyleStr} |
| 97 | + tabindex="0" |
| 98 | +> |
16 | 99 | <div class={buttonClass} />
|
17 | 100 | </div>
|
0 commit comments