click on library icon should toggle the LibraryMenu (#2421)

Co-authored-by: David Luzar <luzar.david@gmail.com>
Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
Luo 2020-11-27 03:02:40 +08:00 committed by GitHub
parent 1269b9ab17
commit 6c0296c434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -184,7 +184,7 @@ export const ShapesSwitcher = ({
); );
})} })}
<ToolButton <ToolButton
className="Shape" className="Shape ToolIcon_type_button__library"
type="button" type="button"
icon={LIBRARY_ICON} icon={LIBRARY_ICON}
name="editor-library" name="editor-library"

View File

@ -100,7 +100,6 @@ const LibraryMenuItems = ({
}: { }: {
library: LibraryItems; library: LibraryItems;
pendingElements: LibraryItem; pendingElements: LibraryItem;
onClickOutside: (event: MouseEvent) => void;
onRemoveFromLibrary: (index: number) => void; onRemoveFromLibrary: (index: number) => void;
onInsertShape: (elements: LibraryItem) => void; onInsertShape: (elements: LibraryItem) => void;
onAddToLibrary: (elements: LibraryItem) => void; onAddToLibrary: (elements: LibraryItem) => void;
@ -211,7 +210,13 @@ const LibraryMenu = ({
setAppState: React.Component<any, AppState>["setState"]; setAppState: React.Component<any, AppState>["setState"];
}) => { }) => {
const ref = useRef<HTMLDivElement | null>(null); const ref = useRef<HTMLDivElement | null>(null);
useOnClickOutside(ref, onClickOutside); useOnClickOutside(ref, (event) => {
// If click on the library icon, do nothing.
if ((event.target as Element).closest(".ToolIcon_type_button__library")) {
return;
}
onClickOutside(event);
});
const [libraryItems, setLibraryItems] = useState<LibraryItems>([]); const [libraryItems, setLibraryItems] = useState<LibraryItems>([]);
@ -269,7 +274,6 @@ const LibraryMenu = ({
) : ( ) : (
<LibraryMenuItems <LibraryMenuItems
library={libraryItems} library={libraryItems}
onClickOutside={onClickOutside}
onRemoveFromLibrary={removeFromLibrary} onRemoveFromLibrary={removeFromLibrary}
onAddToLibrary={addToLibrary} onAddToLibrary={addToLibrary}
onInsertShape={onInsertShape} onInsertShape={onInsertShape}