import styled from '@emotion/styled'; import type { AxisUnit } from '@zakodium/nmrium-core'; import { assert } from '@zakodium/utils'; import type { ReactNode } from 'react'; import type { ContextMenuItem } from '../../elements/ContextMenuBluePrint.tsx'; import { ContextMenu } from '../../elements/ContextMenuBluePrint.tsx'; import { axisUnitToLabel } from '../../hooks/use_axis_unit.ts'; interface AxisUnitPickerProps { unit: AxisUnit; allowedUnits: AxisUnit[]; onChange: (unit: AxisUnit) => void; children: ReactNode; } export function AxisUnitPicker(props: AxisUnitPickerProps) { const { unit, allowedUnits, onChange, children } = props; const options: ContextMenuItem[] = allowedUnits.map((allowedUnit) => ({ key: allowedUnit, roleStructure: 'listoption', text: axisUnitToLabel[allowedUnit], selected: allowedUnit === unit, data: { unit: allowedUnit } satisfies Data, })); function onSelect(data?: object) { assert(data); const { unit } = data as Data; onChange(unit); } return ( {children} ); } const ContextMenuStyled = styled(ContextMenu)` pointer-events: auto; cursor: context-menu; `; interface Data { unit: AxisUnit; }