| 1 | import { Play } from "lucide-react"; |
| 2 | import { SettingsSelect } from "./SettingsSelect"; |
| 3 | import { useT } from "../lib/i18n"; |
| 4 | import type { DictKey } from "../lib/i18n"; |
| 5 | import type { SoundWavPref } from "../lib/sound"; |
| 6 | |
| 7 | type SoundOption = { |
| 8 | value: SoundWavPref; |
| 9 | labelKey: DictKey; |
| 10 | }; |
| 11 | |
| 12 | const OPTIONS: SoundOption[] = [ |
| 13 | { value: "off", labelKey: "settings.notificationSound.off" }, |
| 14 | { value: "synth", labelKey: "settings.notificationSound.synth" }, |
| 15 | { value: "positive", labelKey: "settings.notificationSound.positive" }, |
| 16 | { value: "correct", labelKey: "settings.notificationSound.correct" }, |
| 17 | { value: "start", labelKey: "settings.notificationSound.start" }, |
| 18 | { value: "back", labelKey: "settings.notificationSound.back" }, |
| 19 | ]; |
| 20 | |
| 21 | export function SoundSelect({ |
| 22 | value, |
| 23 | onChange, |
| 24 | onPreview, |
| 25 | previewDisabled, |
| 26 | }: { |
| 27 | value: SoundWavPref; |
| 28 | onChange: (v: SoundWavPref) => void; |
| 29 | onPreview: () => void; |
| 30 | previewDisabled?: boolean; |
| 31 | }) { |
| 32 | const t = useT(); |
| 33 | return ( |
| 34 | <div className="sound-select"> |
| 35 | <SettingsSelect value={value} onValueChange={next => onChange(next as SoundWavPref)} |
| 36 | aria-label={t("settings.notificationSound")} |
| 37 | options={OPTIONS.map(option => ({ value: option.value, label: t(option.labelKey) }))} /> |
| 38 | {!previewDisabled && ( |
| 39 | <button className="chip chip--icon" type="button" title={t("settings.notificationSoundPreview")} aria-label={t("settings.notificationSoundPreview")} onClick={onPreview}> |
| 40 | <Play size={13} aria-hidden="true" /> |
| 41 | </button> |
| 42 | )} |
| 43 | |
| 44 | </div> |
| 45 | ); |
| 46 | } |
| 47 |