ABCNotation.jsx 711 B

12345678910111213141516171819202122232425262728
  1. import React, { useEffect, useRef } from 'react';
  2. import abcjs from 'abcjs';
  3. export default function ABCNotation({
  4. notation,
  5. responsive = true,
  6. width = 600,
  7. options = {}
  8. }) {
  9. const divRef = useRef(null);
  10. useEffect(() => {
  11. if (divRef.current && notation) {
  12. // Clear previous rendering
  13. divRef.current.innerHTML = '';
  14. // Render ABC notation
  15. abcjs.renderAbc(divRef.current, notation, {
  16. responsive: responsive ? 'resize' : undefined,
  17. add_classes: true,
  18. staffwidth: responsive ? undefined : width,
  19. ...options
  20. });
  21. }
  22. }, [notation, responsive, width, options]);
  23. return <div ref={divRef} className="abcjs-container" />;
  24. }