diff --git a/src/components/InstrumentSelector.tsx b/src/components/InstrumentSelector.tsx index ea0594f..e8f0b7b 100644 --- a/src/components/InstrumentSelector.tsx +++ b/src/components/InstrumentSelector.tsx @@ -1,4 +1,5 @@ -import { useMemo, useRef, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; +import type { CSSProperties } from 'react'; import { IonAccordion, IonAccordionGroup, @@ -25,9 +26,28 @@ interface InstrumentSelectorProps { export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorProps) { const [searchQuery, setSearchQuery] = useState(''); const [expandedCategoryIds, setExpandedCategoryIds] = useState([]); + const [viewportHeight, setViewportHeight] = useState( + () => window.visualViewport?.height ?? window.innerHeight, + ); const popoverRef = useRef(null); const popover = usePopoverDisclosure(); + useEffect(() => { + const visualViewport = window.visualViewport; + + function updateViewportHeight(): void { + setViewportHeight(visualViewport?.height ?? window.innerHeight); + } + + window.addEventListener('resize', updateViewportHeight); + visualViewport?.addEventListener('resize', updateViewportHeight); + + return () => { + window.removeEventListener('resize', updateViewportHeight); + visualViewport?.removeEventListener('resize', updateViewportHeight); + }; + }, []); + const filteredCategories = useMemo(() => { const query = searchQuery.trim().toLowerCase(); return INSTRUMENT_CATEGORIES.flatMap((category) => { @@ -110,6 +130,7 @@ export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorPro { const tooSlow = sequencerReducer(initial, { type: 'tempo-changed', tempoBpm: 10 }); const tooFast = sequencerReducer(initial, { type: 'tempo-changed', tempoBpm: 300 }); + expect(MIN_TEMPO_BPM).toBe(30); + expect(MAX_TEMPO_BPM).toBe(260); expect(tooSlow.tempoBpm).toBe(MIN_TEMPO_BPM); expect(tooFast.tempoBpm).toBe(MAX_TEMPO_BPM); }); diff --git a/src/styles.css b/src/styles.css index e01cc3a..01eebfd 100644 --- a/src/styles.css +++ b/src/styles.css @@ -874,6 +874,13 @@ ion-content.app-content-studio { ion-popover.instrument-picker-popover { --width: min(420px, calc(100vw - 24px)); + --picker-menu-height: min(60vh, 420px); + --picker-menu-height: min( + 60dvh, + 420px, + max(120px, calc(var(--picker-viewport-height, 100vh) - 160px)) + ); + --max-height: var(--picker-menu-height); --background: var(--surface); --backdrop-opacity: 0; --box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45); @@ -882,7 +889,8 @@ ion-popover.instrument-picker-popover { .instrument-picker-menu { display: flex; width: 100%; - max-height: min(60vh, 420px); + height: var(--picker-menu-height); + max-height: var(--picker-menu-height); min-height: 0; box-sizing: border-box; flex-direction: column; @@ -1121,31 +1129,36 @@ ion-popover.instrument-picker-popover { .tempo-range-track { position: relative; + display: flex; width: 44px; height: 164px; flex: 0 0 164px; + align-items: center; + justify-content: center; } .tempo-range { - width: 44px; - height: 164px; + position: absolute; + top: 50%; + left: 50%; + width: 164px; + height: 44px; margin: 0; padding: 0; border: 0; appearance: none; -webkit-appearance: none; - writing-mode: vertical-lr; - direction: rtl; + transform: translate(-50%, -50%) rotate(-90deg); background: transparent; touch-action: none; } .tempo-range::-webkit-slider-runnable-track { - width: 3px; - height: 100%; + width: 100%; + height: 3px; border-radius: 999px; background: linear-gradient( - to top, + to right, var(--accent) 0%, var(--accent) var(--tempo-progress), #58537d var(--tempo-progress), @@ -1156,7 +1169,7 @@ ion-popover.instrument-picker-popover { .tempo-range::-webkit-slider-thumb { width: 18px; height: 18px; - margin-top: 0; + margin-top: -7.5px; border: 0; border-radius: 50%; -webkit-appearance: none; @@ -1165,7 +1178,8 @@ ion-popover.instrument-picker-popover { } .tempo-range::-moz-range-track { - width: 3px; + width: 100%; + height: 3px; border-radius: 999px; background: #58537d; }