From 8e4a8788a20add3f8bcdc990fc8e65cddf99862f Mon Sep 17 00:00:00 2001 From: Sultan Iman Date: Tue, 8 Apr 2025 17:48:43 +0200 Subject: [PATCH] feat: add option to hide library in the sidebar --- .../excalidraw/components/DefaultSidebar.tsx | 17 +++++++++++------ packages/excalidraw/components/LayerUI.tsx | 5 +++-- .../excalidraw/components/Sidebar/common.ts | 4 ++++ packages/excalidraw/types.ts | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/excalidraw/components/DefaultSidebar.tsx b/packages/excalidraw/components/DefaultSidebar.tsx index 4f1aa91e8..447a2d3c2 100644 --- a/packages/excalidraw/components/DefaultSidebar.tsx +++ b/packages/excalidraw/components/DefaultSidebar.tsx @@ -61,6 +61,7 @@ export const DefaultSidebar = Object.assign( className, onDock, docked, + libraryEnabled, ...rest }: Merge< MarkOptional, "children">, @@ -102,15 +103,19 @@ export const DefaultSidebar = Object.assign( {searchIcon} - - {LibraryIcon} - + {libraryEnabled && ( + + {LibraryIcon} + + )} - - - + {libraryEnabled && ( + + + + )} diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx index b5491dedd..f38c14d00 100644 --- a/packages/excalidraw/components/LayerUI.tsx +++ b/packages/excalidraw/components/LayerUI.tsx @@ -156,7 +156,8 @@ const LayerUI = ({ }: LayerUIProps) => { const device = useDevice(); const tunnels = useInitializeTunnels(); - + const showLibrary = + UIOptions.libraryEnabled === undefined ? true : UIOptions.libraryEnabled; const TunnelsJotaiProvider = tunnels.tunnelsJotai.Provider; const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom); @@ -375,11 +376,11 @@ const LayerUI = ({ ); }; - const renderSidebars = () => { return ( { trackEvent( "sidebar", diff --git a/packages/excalidraw/components/Sidebar/common.ts b/packages/excalidraw/components/Sidebar/common.ts index 239b16fc9..cd3ba2c3b 100644 --- a/packages/excalidraw/components/Sidebar/common.ts +++ b/packages/excalidraw/components/Sidebar/common.ts @@ -25,6 +25,10 @@ export type SidebarProps

= { * supply alongside `docked` prop in order to make the Sidebar user-dockable */ onDock?: (docked: boolean) => void; + /** + * Allow hiding library button, default: true + */ + libraryEnabled?: boolean; docked?: boolean; className?: string; // NOTE sidebars we use internally inside the editor must have this flag set. diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts index 717993b43..bee88c006 100644 --- a/packages/excalidraw/types.ts +++ b/packages/excalidraw/types.ts @@ -645,6 +645,7 @@ export type UIOptions = Partial<{ tools: { image: boolean; }; + libraryEnabled?: boolean; /** @deprecated does nothing. Will be removed in 0.15 */ welcomeScreen?: boolean; }>;