Skip to content

Commit 3d7435d

Browse files
committed
react: add staccato toggle
1 parent af0d789 commit 3d7435d

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

packages/react/src/components/editor/EditorControls.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accidental, Rhythm } from "@abc-editor/core";
1+
import { Accidental, Decoration, Rhythm } from "@abc-editor/core";
22
import clsx from "clsx";
33
import { useEditorContext } from "../../context/EditorContext";
44
import EditorControlIcon from "./EditorControlIcon";
@@ -14,6 +14,7 @@ export default function EditorControls() {
1414
onNewLine,
1515
onChangeAccidental,
1616
onToggleBeaming,
17+
onToggleDecoration,
1718
onToggleTie,
1819
history,
1920
onUndo,
@@ -279,6 +280,22 @@ export default function EditorControls() {
279280
>
280281
<EditorControlIcon icon="natural" size={iconSize} />
281282
</button>
283+
<button
284+
role="switch"
285+
title="Toggle staccato"
286+
aria-checked={selectedNote?.data?.decorations?.includes(
287+
Decoration.Staccato,
288+
)}
289+
className={clsx(styles.iconButton, {
290+
[styles.selected]: selectedNote?.data?.decorations?.includes(
291+
Decoration.Staccato,
292+
),
293+
})}
294+
disabled={!selectedNote?.data || selectedNote.data.rest}
295+
onClick={() => onToggleDecoration(Decoration.Staccato)}
296+
>
297+
<EditorControlIcon icon="dot" size={iconSize} />
298+
</button>
282299
<button
283300
title="Toggle tied note"
284301
role="switch"

packages/react/src/context/EditorContext.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import {
2-
Accidental,
3-
EditorCommandState,
4-
EditorState,
5-
Rhythm,
6-
type SelectionState,
7-
editorCommandReducer,
8-
setupKeyboardListener,
9-
setupMIDIListener,
10-
setupStaffMouseListeners,
2+
Accidental,
3+
Decoration,
4+
EditorCommandState,
5+
EditorState,
6+
Rhythm,
7+
type SelectionState,
8+
editorCommandReducer,
9+
setupKeyboardListener,
10+
setupMIDIListener,
11+
setupStaffMouseListeners,
1112
} from "@abc-editor/core";
1213
import type { AbcVisualParams, TuneObject } from "abcjs";
1314
import { renderAbc } from "abcjs";
1415
import { createProvider } from "puro";
1516
import {
16-
useCallback,
17-
useContext,
18-
useEffect,
19-
useReducer,
20-
useRef,
21-
useState,
17+
useCallback,
18+
useContext,
19+
useEffect,
20+
useReducer,
21+
useRef,
22+
useState,
2223
} from "react";
2324
import { EditorProps } from "../components/editor/Editor";
2425

@@ -215,6 +216,11 @@ const useEditor = ({
215216
setAbc(editorState.current.abc);
216217
}, []);
217218

219+
const onToggleDecoration = useCallback((decoration: Decoration) => {
220+
editorState.current.toggleDecoration(decoration);
221+
setAbc(editorState.current.abc);
222+
}, []);
223+
218224
const onToggleTie = useCallback(() => {
219225
editorState.current.toggleTie();
220226
setAbc(editorState.current.abc);
@@ -318,6 +324,7 @@ const useEditor = ({
318324
onNewLine,
319325
onChangeAccidental,
320326
onToggleBeaming,
327+
onToggleDecoration,
321328
onToggleTie,
322329
onUndo,
323330
onRedo,

0 commit comments

Comments
 (0)