From 7bc01c70f5408d1c8d5ddc8b76ea1f4bd6e23859 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Wed, 22 Sep 2021 12:40:53 +0100 Subject: [PATCH] Add unfocus button --- .../tldraw/src/components/tldraw/tldraw.tsx | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/tldraw/src/components/tldraw/tldraw.tsx b/packages/tldraw/src/components/tldraw/tldraw.tsx index 2c037b55d..17b8f8f08 100644 --- a/packages/tldraw/src/components/tldraw/tldraw.tsx +++ b/packages/tldraw/src/components/tldraw/tldraw.tsx @@ -17,6 +17,8 @@ import { StylePanel } from '~components/style-panel' import { ToolsPanel } from '~components/tools-panel' import { PagePanel } from '~components/page-panel' import { Menu } from '~components/menu' +import { breakpoints, iconButton } from '~components' +import { DotFilledIcon } from '@radix-ui/react-icons' // Selectors const isInSelectSelector = (s: Data) => s.appState.activeTool === 'select' @@ -115,11 +117,9 @@ function InnerTldraw({ }) { const { tlstate, useSelector } = useTLDrawContext() - const rTheme = React.useRef(null) - const rWrapper = React.useRef(null) - useThemeEffect(rTheme) + useThemeEffect(rWrapper) const page = useSelector(pageSelector) @@ -180,9 +180,9 @@ function InnerTldraw({ }, [currentPageId, tlstate]) return ( -
-
- +
+
+ - {!isFocusMode && ( + {isFocusMode ? ( +
+ +
+ ) : ( <>
@@ -259,13 +265,19 @@ function InnerTldraw({ } const OneOff = React.memo( - ({ rWrapper, autofocus }: { autofocus?: boolean; rWrapper: React.RefObject }) => { - useKeyboardShortcuts(rWrapper) + ({ + focusableRef, + autofocus, + }: { + autofocus?: boolean + focusableRef: React.RefObject + }) => { + useKeyboardShortcuts(focusableRef) useCustomFonts() React.useEffect(() => { if (autofocus) { - rWrapper.current?.focus() + focusableRef.current?.focus() } }, [autofocus]) @@ -315,3 +327,17 @@ const menuButtons = css({ display: 'flex', gap: 8, }) + +const unfocusButton = css({ + opacity: 1, + zIndex: 100, + backgroundColor: 'transparent', + + '& svg': { + color: '$muted', + }, + + '&:hover svg': { + color: '$text', + }, +})