Restore sound-specific rings and refine studio UI
This commit is contained in:
1 parent
02eb8911e8
commit
e7b6c0bb3e
16 files changed
+318
-524
No files matched your search
@@ -1,96 +1 @@
|
||||
import { memo } from 'react';
|
||||
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
|
||||
import { chevronDown } from 'ionicons/icons';
|
||||
import { INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
||||
|
||||
interface CategoryRingSelectorProps {
|
||||
categoryIds: readonly InstrumentCategoryId[];
|
||||
focusedCategoryId: InstrumentCategoryId | null;
|
||||
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||
labelByCategoryId: CategoryLabelOverrides;
|
||||
onSelectCategory: (categoryId: InstrumentCategoryId) => void;
|
||||
}
|
||||
|
||||
export const CategoryRingSelector = memo(function CategoryRingSelector({
|
||||
categoryIds,
|
||||
focusedCategoryId,
|
||||
colorByCategoryId,
|
||||
labelByCategoryId,
|
||||
onSelectCategory,
|
||||
}: CategoryRingSelectorProps) {
|
||||
const popover = usePopoverDisclosure();
|
||||
const focusedCategory = focusedCategoryId
|
||||
? INSTRUMENT_CATEGORY_BY_ID[focusedCategoryId]
|
||||
: undefined;
|
||||
const focusedLabel = focusedCategory
|
||||
? labelByCategoryId[focusedCategory.id] ?? focusedCategory.label
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<>
|
||||
<IonButton
|
||||
id="category-ring-selector-trigger"
|
||||
className="sound-ring-selector-trigger"
|
||||
fill="clear"
|
||||
disabled={categoryIds.length === 0}
|
||||
aria-label={focusedCategory ? `Selected ring: ${focusedLabel}` : 'Select a category ring'}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={popover.isOpen}
|
||||
>
|
||||
<span className="sound-ring-trigger-content">
|
||||
{focusedCategory && (
|
||||
<>
|
||||
<span
|
||||
className="ring-selector-swatch"
|
||||
style={{ backgroundColor: colorByCategoryId[focusedCategory.id] ?? '#b8b4e0' }}
|
||||
/>
|
||||
<span className="category-letter-badge">{focusedCategory.letter}</span>
|
||||
</>
|
||||
)}
|
||||
<span>{focusedLabel ? `${focusedLabel} ring` : 'Category rings'}</span>
|
||||
<IonIcon icon={chevronDown} />
|
||||
</span>
|
||||
</IonButton>
|
||||
|
||||
<IonPopover
|
||||
className="sound-ring-popover"
|
||||
trigger="category-ring-selector-trigger"
|
||||
triggerAction="click"
|
||||
side="bottom"
|
||||
alignment="end"
|
||||
dismissOnSelect
|
||||
onDidPresent={popover.onDidPresent}
|
||||
onDidDismiss={popover.onDidDismiss}
|
||||
>
|
||||
<div className="sound-ring-options" role="group" aria-label="Category rings">
|
||||
{categoryIds.map((categoryId) => {
|
||||
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||
const label = labelByCategoryId[categoryId] ?? category.label;
|
||||
const selected = categoryId === focusedCategoryId;
|
||||
return (
|
||||
<IonButton
|
||||
key={categoryId}
|
||||
className="sound-ring-option"
|
||||
fill={selected ? 'solid' : 'clear'}
|
||||
aria-pressed={selected}
|
||||
onClick={() => onSelectCategory(categoryId)}
|
||||
>
|
||||
<span className="sound-ring-option-content">
|
||||
<span
|
||||
className="ring-selector-swatch"
|
||||
style={{ backgroundColor: colorByCategoryId[categoryId] ?? '#b8b4e0' }}
|
||||
/>
|
||||
<span className="category-letter-badge">{category.letter}</span>
|
||||
<span>{label} ring</span>
|
||||
</span>
|
||||
</IonButton>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</IonPopover>
|
||||
</>
|
||||
);
|
||||
});
|
||||
export { SoundRingSelector as CategoryRingSelector } from './SoundRingSelector';
|
||||
Reference in new issue
Block a user