You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
2 years ago
|
import { useExcalidrawSetAppState } from "../App";
|
||
2 years ago
|
import { SidebarTriggerProps } from "./common";
|
||
2 years ago
|
import { useUIAppState } from "../../context/ui-appState";
|
||
|
import clsx from "clsx";
|
||
2 years ago
|
|
||
|
import "./SidebarTrigger.scss";
|
||
|
|
||
|
export const SidebarTrigger = ({
|
||
|
name,
|
||
|
tab,
|
||
|
icon,
|
||
|
title,
|
||
|
children,
|
||
|
onToggle,
|
||
|
className,
|
||
|
style,
|
||
|
}: SidebarTriggerProps) => {
|
||
|
const setAppState = useExcalidrawSetAppState();
|
||
2 years ago
|
const appState = useUIAppState();
|
||
2 years ago
|
|
||
|
return (
|
||
|
<label title={title}>
|
||
|
<input
|
||
|
className="ToolIcon_type_checkbox"
|
||
|
type="checkbox"
|
||
|
onChange={(event) => {
|
||
|
document
|
||
|
.querySelector(".layer-ui__wrapper")
|
||
|
?.classList.remove("animate");
|
||
|
const isOpen = event.target.checked;
|
||
|
setAppState({ openSidebar: isOpen ? { name, tab } : null });
|
||
|
onToggle?.(isOpen);
|
||
|
}}
|
||
|
checked={appState.openSidebar?.name === name}
|
||
|
aria-label={title}
|
||
|
aria-keyshortcuts="0"
|
||
|
/>
|
||
|
<div className={clsx("sidebar-trigger", className)} style={style}>
|
||
|
{icon && <div>{icon}</div>}
|
||
|
{children && <div className="sidebar-trigger__label">{children}</div>}
|
||
|
</div>
|
||
|
</label>
|
||
|
);
|
||
|
};
|
||
|
SidebarTrigger.displayName = "SidebarTrigger";
|