diff options
Diffstat (limited to 'packages/excalidraw/components/Sidebar/SidebarTrigger.tsx')
| -rw-r--r-- | packages/excalidraw/components/Sidebar/SidebarTrigger.tsx | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/excalidraw/components/Sidebar/SidebarTrigger.tsx b/packages/excalidraw/components/Sidebar/SidebarTrigger.tsx new file mode 100644 index 0000000..a26e52d --- /dev/null +++ b/packages/excalidraw/components/Sidebar/SidebarTrigger.tsx @@ -0,0 +1,45 @@ +import { useExcalidrawSetAppState } from "../App"; +import type { SidebarTriggerProps } from "./common"; +import { useUIAppState } from "../../context/ui-appState"; +import clsx from "clsx"; + +import "./SidebarTrigger.scss"; + +export const SidebarTrigger = ({ + name, + tab, + icon, + title, + children, + onToggle, + className, + style, +}: SidebarTriggerProps) => { + const setAppState = useExcalidrawSetAppState(); + const appState = useUIAppState(); + + return ( + <label title={title} className="sidebar-trigger__label-element"> + <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"; |
