Fix tempo slider dragging and width
This commit is contained in:
1 parent
8ef90b5898
commit
ec2792736d
2 files changed
+72
-23
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { memo } from 'react';
|
||||
import { IonButton, IonIcon, IonPopover, IonRange } from '@ionic/react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
|
||||
import { chevronDown } from 'ionicons/icons';
|
||||
import { MAX_TEMPO_BPM, MIN_TEMPO_BPM } from '../domain/sequencer';
|
||||
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
||||
@@ -11,6 +12,7 @@ interface TempoControlProps {
|
||||
|
||||
export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange }: TempoControlProps) {
|
||||
const popover = usePopoverDisclosure();
|
||||
const tempoProgress = ((tempoBpm - MIN_TEMPO_BPM) / (MAX_TEMPO_BPM - MIN_TEMPO_BPM)) * 100;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -40,16 +42,16 @@ export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange
|
||||
<div className="tempo-popover-content">
|
||||
<output className="tempo-value" aria-live="polite">{tempoBpm} BPM</output>
|
||||
<div className="tempo-range-track">
|
||||
<IonRange
|
||||
<input
|
||||
className="tempo-range"
|
||||
type="range"
|
||||
aria-label="Tempo in beats per minute"
|
||||
min={MIN_TEMPO_BPM}
|
||||
max={MAX_TEMPO_BPM}
|
||||
step={1}
|
||||
value={tempoBpm}
|
||||
onIonInput={(event) => {
|
||||
if (typeof event.detail.value === 'number') onTempoChange(event.detail.value);
|
||||
}}
|
||||
style={{ '--tempo-progress': `${tempoProgress}%` } as CSSProperties}
|
||||
onChange={(event) => onTempoChange(event.currentTarget.valueAsNumber)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+65
-18
@@ -41,6 +41,7 @@
|
||||
--accent: #ff8a3d;
|
||||
--accent-hover: #ff9b5c;
|
||||
--accent-pressed: #e07936;
|
||||
--tempo-control-width: 94px;
|
||||
--primary-rgb: 244, 241, 237;
|
||||
--accent-rgb: 255, 138, 61;
|
||||
--mono: 'DM Mono', monospace;
|
||||
@@ -1040,6 +1041,8 @@ ion-popover.instrument-picker-popover {
|
||||
}
|
||||
|
||||
.tempo-trigger {
|
||||
width: var(--tempo-control-width);
|
||||
flex: 0 0 var(--tempo-control-width);
|
||||
--color: var(--ink);
|
||||
--background: var(--surface-raised);
|
||||
--background-hover: #33323b;
|
||||
@@ -1096,6 +1099,7 @@ ion-popover.instrument-picker-popover {
|
||||
}
|
||||
|
||||
.tempo-value {
|
||||
align-self: center;
|
||||
color: var(--ink);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
@@ -1105,7 +1109,7 @@ ion-popover.instrument-picker-popover {
|
||||
|
||||
/* Popover contents */
|
||||
.tempo-popover {
|
||||
--width: 94px;
|
||||
--width: var(--tempo-control-width);
|
||||
--height: 226px;
|
||||
--background: var(--surface);
|
||||
--backdrop-opacity: 0;
|
||||
@@ -1125,29 +1129,72 @@ ion-popover.instrument-picker-popover {
|
||||
|
||||
.tempo-range-track {
|
||||
position: relative;
|
||||
width: 28px;
|
||||
width: 44px;
|
||||
height: 164px;
|
||||
flex: 0 0 164px;
|
||||
}
|
||||
|
||||
.tempo-range {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 164px;
|
||||
height: 28px;
|
||||
width: 44px;
|
||||
height: 164px;
|
||||
margin: 0;
|
||||
transform: translate(-50%, -50%) rotate(-90deg);
|
||||
--bar-background: #58537d;
|
||||
--bar-background-active: var(--accent);
|
||||
--bar-height: 3px;
|
||||
--height: 28px;
|
||||
--knob-background: var(--accent);
|
||||
--knob-size: 12px;
|
||||
--padding-top: 2px;
|
||||
--padding-bottom: 2px;
|
||||
--padding-start: 2px;
|
||||
--padding-end: 2px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
writing-mode: vertical-lr;
|
||||
direction: rtl;
|
||||
background: transparent;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.tempo-range::-webkit-slider-runnable-track {
|
||||
width: 3px;
|
||||
height: 100%;
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
var(--accent) 0%,
|
||||
var(--accent) var(--tempo-progress),
|
||||
#58537d var(--tempo-progress),
|
||||
#58537d 100%
|
||||
);
|
||||
}
|
||||
|
||||
.tempo-range::-webkit-slider-thumb {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-top: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
-webkit-appearance: none;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-track {
|
||||
width: 3px;
|
||||
border-radius: 999px;
|
||||
background: #58537d;
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-progress {
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.tempo-range::-moz-range-thumb {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
|
||||
}
|
||||
|
||||
.tempo-range:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
|
||||
.meter-popover {
|
||||
|
||||
Reference in new issue
Block a user