Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

refactor(settings): adopt wave-bar WakeSlider with its own stylesheet

Deepender250196d8b145b4
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
index e5f8674..23c58c2 100644
--- a/src/components/Settings.tsx
+++ b/src/components/Settings.tsx
@@ -1443,9 +1443,9 @@ export function Settings({
min={1}
max={7}
step={1}
- bars={14}
- height={26}
- restHeight={7}
+ bars={28}
+ height={28}
+ restHeight={8}
gap={3}
value={settings.hotZoneWidth ?? 3}
onStart={() => {
@@ -2221,9 +2221,9 @@ export function Settings({
min={1}
max={7}
step={1}
- bars={14}
+ bars={28}
height={28}
- restHeight={7}
+ restHeight={8}
gap={3}
value={settings.hotZoneWidth ?? 3}
onStart={() => {
diff --git a/src/components/WakeSlider.css b/src/components/WakeSlider.css
new file mode 100644
index 0000000..c0299f9
--- /dev/null
+++ b/src/components/WakeSlider.css
@@ -0,0 +1,100 @@
+.wake-slider {
+ --ws-fill: #f5f5f5;
+ --ws-track: #27272a;
+ --ws-crest: #f5f5f5;
+ --ws-height: 56px;
+ --ws-gap: 4px;
+ --ws-rest: 0.214;
+
+ display: inline-flex;
+ align-items: center;
+ gap: 12px;
+ width: 100%;
+ color: inherit;
+}
+
+.wake-slider[aria-disabled='true'] {
+ opacity: 0.5;
+ pointer-events: none;
+}
+
+.wake-slider__track {
+ position: relative;
+ display: flex;
+ flex: 1 1 auto;
+ align-items: center;
+ gap: var(--ws-gap);
+ height: var(--ws-height);
+ min-height: 44px;
+ touch-action: none;
+ user-select: none;
+ -webkit-user-select: none;
+ -webkit-touch-callout: none;
+ -webkit-tap-highlight-color: transparent;
+}
+
+@media (hover: hover) and (pointer: fine) {
+ .wake-slider__track {
+ cursor: grab;
+ }
+
+ .wake-slider__track:active {
+ cursor: grabbing;
+ }
+}
+
+.wake-slider__bar {
+ position: relative;
+ flex: 1 1 0;
+ min-width: 0;
+ height: var(--ws-height);
+ border-radius: 9999px;
+ background: var(--ws-track);
+ transform: scaleY(var(--ws-rest));
+ transform-origin: 50% 50%;
+ transition: background-color 120ms ease;
+}
+
+.wake-slider__bar[data-on='true'] {
+ background: var(--ws-fill);
+}
+
+.wake-slider[data-instant='true'] .wake-slider__bar {
+ transition-duration: 0ms;
+}
+
+.wake-slider__crest {
+ position: absolute;
+ inset: 0;
+ border-radius: inherit;
+ background: var(--ws-crest);
+ opacity: 0;
+}
+
+.wake-slider__handle {
+ position: absolute;
+ inset: 0;
+ margin: 0;
+ padding: 0;
+ border: 0;
+ border-radius: 12px;
+ background: transparent;
+ outline: none;
+ cursor: inherit;
+ touch-action: none;
+ -webkit-tap-highlight-color: transparent;
+}
+
+.wake-slider__value {
+ min-width: 3ch;
+ font-size: 13px;
+ font-variant-numeric: tabular-nums;
+ text-align: right;
+ opacity: 0.6;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .wake-slider__bar {
+ transform: scaleY(var(--ws-rest)) !important;
+ }
+}
diff --git a/src/components/WakeSlider.tsx b/src/components/WakeSlider.tsx
index b616ab6..430c63d 100644
--- a/src/components/WakeSlider.tsx
+++ b/src/components/WakeSlider.tsx
@@ -1,7 +1,9 @@
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
-import { useMotionValue, useMotionValueEvent, useReducedMotion, useSpring, useVelocity } from 'framer-motion'
+import { frameSteps, useMotionValue, useMotionValueEvent, useReducedMotion, useSpring, useVelocity } from 'framer-motion'
import { playDialTickSound } from '../lib/soundEffects'
+import './WakeSlider.css'
+
const SETTLE = 9.23
const FULL_SPEED = 320
const MIN_REACH = 1.5
@@ -55,13 +57,13 @@ export function WakeSlider({
min = 0,
max = 100,
step = 1,
- bars = 28,
- height = 28,
- restHeight = 8,
- gap = 3,
- fillColor = '#ffffff',
- trackColor = 'rgba(255, 255, 255, 0.12)',
- crestColor = '#ffffff',
+ bars = 32,
+ height = 56,
+ restHeight = 12,
+ gap = 4,
+ fillColor = '#f5f5f5',
+ trackColor = '#27272a',
+ crestColor = '',
sensitivity = 1,
reach = 6,
skew = 0.6,
@@ -126,31 +128,15 @@ export function WakeSlider({
}
lastAmp.current = amp
}
-
const paintRef = useRef(paint)
paintRef.current = paint
-
- const rafId = useRef<number | null>(null)
- const schedule = useCallback(() => {
- if (rafId.current !== null) return
- rafId.current = requestAnimationFrame(() => {
- rafId.current = null
- paintRef.current()
- })
- }, [])
-
- useEffect(() => {
- return () => {
- if (rafId.current !== null) {
- cancelAnimationFrame(rafId.current)
- rafId.current = null
- }
- }
- }, [])
-
+ const run = useCallback(() => paintRef.current(), [])
+ // NOTE: the reference implementation targets `motion` v12 (`frame.render(...)`).
+ // This repo runs framer-motion v11, where the same render-step scheduler lives at
+ // `frameSteps.render.schedule(callback, keepAlive, immediate)`.
+ const schedule = useCallback(() => frameSteps.render.schedule(run, false, true), [run])
useMotionValueEvent(head, 'change', schedule)
useMotionValueEvent(speed, 'change', schedule)
-
useLayoutEffect(() => {
paintRef.current(true)
})
@@ -163,7 +149,6 @@ export function WakeSlider({
playDialTickSound()
onChange?.(clean)
}
-
const commitFromX = (x: number) => {
const track = trackRef.current
if (!track) return
@@ -173,7 +158,6 @@ export function WakeSlider({
if (getComputedStyle(track).direction === 'rtl') ratio = 1 - ratio
commit(min + ratio * (max - min))
}
-
const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (disabled || pointerId.current !== null) return
pointerId.current = e.pointerId
@@ -185,11 +169,9 @@ export function WakeSlider({
onStart?.()
commitFromX(e.clientX)
}
-
const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerId === pointerId.current) commitFromX(e.clientX)
}
-
const endDrag = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerId !== pointerId.current) return
try {
@@ -198,7 +180,6 @@ export function WakeSlider({
pointerId.current = null
onRelease?.(latest.current)
}
-
const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
if (disabled) return
const jumps: Record<string, number> = {
@@ -295,3 +276,5 @@ export function WakeSlider({
</div>
)
}
+
+export default WakeSlider