CustomFooter.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from "react";
  2. import type * as TExcalidraw from "@excalidraw/excalidraw";
  3. import type { ExcalidrawImperativeAPI } from "@excalidraw/excalidraw/types";
  4. const COMMENT_SVG = (
  5. <svg
  6. xmlns="http://www.w3.org/2000/svg"
  7. width="24"
  8. height="24"
  9. viewBox="0 0 24 24"
  10. fill="none"
  11. stroke="currentColor"
  12. strokeWidth="2"
  13. strokeLinecap="round"
  14. strokeLinejoin="round"
  15. className="feather feather-message-circle"
  16. >
  17. <path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"></path>
  18. </svg>
  19. );
  20. const CustomFooter = ({
  21. excalidrawAPI,
  22. excalidrawLib,
  23. }: {
  24. excalidrawAPI: ExcalidrawImperativeAPI;
  25. excalidrawLib: typeof TExcalidraw;
  26. }) => {
  27. const { Button, MIME_TYPES } = excalidrawLib;
  28. return (
  29. <>
  30. <Button
  31. onSelect={() => alert("General Kenobi!")}
  32. style={{ marginLeft: "1rem", width: "auto" }}
  33. title="Hello there!"
  34. >
  35. Hit me
  36. </Button>
  37. <Button
  38. className="custom-element"
  39. onSelect={() => {
  40. excalidrawAPI?.setActiveTool({
  41. type: "custom",
  42. customType: "comment",
  43. });
  44. const url = `data:${MIME_TYPES.svg},${encodeURIComponent(
  45. `<svg
  46. xmlns="http://www.w3.org/2000/svg"
  47. width="24"
  48. height="24"
  49. viewBox="0 0 24 24"
  50. fill="none"
  51. stroke="currentColor"
  52. stroke-width="2"
  53. stroke-linecap="round"
  54. stroke-linejoin="round"
  55. class="feather feather-message-circle"
  56. >
  57. <path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"></path>
  58. </svg>`,
  59. )}`;
  60. excalidrawAPI?.setCursor(`url(${url}), auto`);
  61. }}
  62. title="Comments!"
  63. >
  64. {COMMENT_SVG}
  65. </Button>
  66. </>
  67. );
  68. };
  69. export default CustomFooter;