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