2021-07-05 15:59:09 +05:30
|
|
|
import React from "react";
|
2021-06-11 23:13:05 +02:00
|
|
|
import { t } from "../i18n";
|
|
|
|
import { AppState } from "../types";
|
|
|
|
import { capitalizeString } from "../utils";
|
2022-06-21 20:03:23 +05:00
|
|
|
import { trackEvent } from "../analytics";
|
|
|
|
import { useDevice } from "./App";
|
2022-11-01 17:29:58 +01:00
|
|
|
import "./LibraryButton.scss";
|
|
|
|
import { LibraryIcon } from "./icons";
|
2021-06-11 23:13:05 +02:00
|
|
|
|
|
|
|
export const LibraryButton: React.FC<{
|
|
|
|
appState: AppState;
|
|
|
|
setAppState: React.Component<any, AppState>["setState"];
|
2021-12-15 15:31:44 +01:00
|
|
|
isMobile?: boolean;
|
|
|
|
}> = ({ appState, setAppState, isMobile }) => {
|
2022-06-21 20:03:23 +05:00
|
|
|
const device = useDevice();
|
2022-11-01 17:29:58 +01:00
|
|
|
const showLabel = !isMobile;
|
|
|
|
|
|
|
|
// TODO barnabasmolnar/redesign
|
|
|
|
// not great, toolbar jumps in a jarring manner
|
|
|
|
if (appState.isSidebarDocked && appState.openSidebar === "library") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-11 23:13:05 +02:00
|
|
|
return (
|
2022-11-01 17:29:58 +01:00
|
|
|
<label title={`${capitalizeString(t("toolBar.library"))} — 0`}>
|
2021-06-11 23:13:05 +02:00
|
|
|
<input
|
|
|
|
className="ToolIcon_type_checkbox"
|
|
|
|
type="checkbox"
|
|
|
|
name="editor-library"
|
|
|
|
onChange={(event) => {
|
2022-06-21 20:03:23 +05:00
|
|
|
document
|
|
|
|
.querySelector(".layer-ui__wrapper")
|
|
|
|
?.classList.remove("animate");
|
2022-10-17 12:25:24 +02:00
|
|
|
const isOpen = event.target.checked;
|
|
|
|
setAppState({ openSidebar: isOpen ? "library" : null });
|
2022-06-21 20:03:23 +05:00
|
|
|
// track only openings
|
2022-10-17 12:25:24 +02:00
|
|
|
if (isOpen) {
|
2022-06-21 20:03:23 +05:00
|
|
|
trackEvent(
|
|
|
|
"library",
|
|
|
|
"toggleLibrary (open)",
|
|
|
|
`toolbar (${device.isMobile ? "mobile" : "desktop"})`,
|
|
|
|
);
|
|
|
|
}
|
2021-06-11 23:13:05 +02:00
|
|
|
}}
|
2022-10-17 12:25:24 +02:00
|
|
|
checked={appState.openSidebar === "library"}
|
2021-06-11 23:13:05 +02:00
|
|
|
aria-label={capitalizeString(t("toolBar.library"))}
|
2021-10-21 22:05:48 +02:00
|
|
|
aria-keyshortcuts="0"
|
2021-06-11 23:13:05 +02:00
|
|
|
/>
|
2022-11-01 17:29:58 +01:00
|
|
|
<div className="library-button">
|
|
|
|
<div>{LibraryIcon}</div>
|
|
|
|
{showLabel && (
|
|
|
|
<div className="library-button__label">{t("toolBar.library")}</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-06-11 23:13:05 +02:00
|
|
|
</label>
|
|
|
|
);
|
|
|
|
};
|