LibraryButton.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from "react";
  2. import clsx from "clsx";
  3. import { t } from "../i18n";
  4. import { AppState } from "../types";
  5. import { capitalizeString } from "../utils";
  6. import { trackEvent } from "../analytics";
  7. import { useDevice } from "./App";
  8. const LIBRARY_ICON = (
  9. <svg viewBox="0 0 576 512">
  10. <path
  11. fill="currentColor"
  12. d="M542.22 32.05c-54.8 3.11-163.72 14.43-230.96 55.59-4.64 2.84-7.27 7.89-7.27 13.17v363.87c0 11.55 12.63 18.85 23.28 13.49 69.18-34.82 169.23-44.32 218.7-46.92 16.89-.89 30.02-14.43 30.02-30.66V62.75c.01-17.71-15.35-31.74-33.77-30.7zM264.73 87.64C197.5 46.48 88.58 35.17 33.78 32.05 15.36 31.01 0 45.04 0 62.75V400.6c0 16.24 13.13 29.78 30.02 30.66 49.49 2.6 149.59 12.11 218.77 46.95 10.62 5.35 23.21-1.94 23.21-13.46V100.63c0-5.29-2.62-10.14-7.27-12.99z"
  13. ></path>
  14. </svg>
  15. );
  16. export const LibraryButton: React.FC<{
  17. appState: AppState;
  18. setAppState: React.Component<any, AppState>["setState"];
  19. isMobile?: boolean;
  20. }> = ({ appState, setAppState, isMobile }) => {
  21. const device = useDevice();
  22. return (
  23. <label
  24. className={clsx(
  25. "ToolIcon ToolIcon_type_floating ToolIcon__library",
  26. `ToolIcon_size_medium`,
  27. {
  28. "is-mobile": isMobile,
  29. },
  30. )}
  31. title={`${capitalizeString(t("toolBar.library"))} — 0`}
  32. >
  33. <input
  34. className="ToolIcon_type_checkbox"
  35. type="checkbox"
  36. name="editor-library"
  37. onChange={(event) => {
  38. document
  39. .querySelector(".layer-ui__wrapper")
  40. ?.classList.remove("animate");
  41. const nextState = event.target.checked;
  42. setAppState({ isLibraryOpen: nextState });
  43. // track only openings
  44. if (nextState) {
  45. trackEvent(
  46. "library",
  47. "toggleLibrary (open)",
  48. `toolbar (${device.isMobile ? "mobile" : "desktop"})`,
  49. );
  50. }
  51. }}
  52. checked={appState.isLibraryOpen}
  53. aria-label={capitalizeString(t("toolBar.library"))}
  54. aria-keyshortcuts="0"
  55. />
  56. <div className="ToolIcon__icon">{LIBRARY_ICON}</div>
  57. </label>
  58. );
  59. };