diff --git a/pkg/grid/src/nav/Leap.tsx b/pkg/grid/src/nav/Leap.tsx index 3c68bc0824..cfeab6ff13 100644 --- a/pkg/grid/src/nav/Leap.tsx +++ b/pkg/grid/src/nav/Leap.tsx @@ -34,17 +34,18 @@ export function createPreviousPath(current: string): string { type LeapProps = { menu: MenuState; dropdown: string; + showClose: boolean; } & HTMLAttributes; -export const Leap = React.forwardRef(({ menu, dropdown, className }: LeapProps, ref) => { +export const Leap = React.forwardRef(({ menu, dropdown, showClose, className }: LeapProps, ref) => { const { push } = useHistory(); - const match = useRouteMatch<{ query?: string; desk?: string }>( + const match = useRouteMatch<{ menu?: MenuState; query?: string; desk?: string }>( `/leap/${menu}/:query?/(apps)?/:desk?` ); const appsMatch = useRouteMatch(`/leap/${menu}/${match?.params.query}/apps`); const inputRef = useRef(null); useImperativeHandle(ref, () => inputRef.current); - const { rawInput, searchInput, selectedMatch, matches, selection, select } = useLeapStore(); + const { rawInput, selectedMatch, matches, selection, select } = useLeapStore(); const toggleSearch = useCallback(() => { if (selection || menu === 'search') { @@ -54,15 +55,18 @@ export const Leap = React.forwardRef(({ menu, dropdown, className }: LeapProps, push('/leap/search'); }, [selection, menu]); - const onFocus = useCallback((e: FocusEvent) => { - // refocusing tab with input focused is false trigger - const windowFocus = e.nativeEvent.currentTarget === document.body; - if (windowFocus) { - return; - } + const onFocus = useCallback( + (e: FocusEvent) => { + // refocusing tab with input focused is false trigger + const windowFocus = e.nativeEvent.currentTarget === document.body; + if (windowFocus) { + return; + } - toggleSearch(); - }, []); + toggleSearch(); + }, + [toggleSearch] + ); const getMatch = useCallback( (value: string) => { @@ -212,7 +216,7 @@ export const Leap = React.forwardRef(({ menu, dropdown, className }: LeapProps, aria-controls={dropdown} aria-activedescendant={selectedMatch?.display || selectedMatch?.value} /> - {(selection || searchInput) && ( + {showClose && ( = ({ menu = 'closed' }) => { +export const Nav: FunctionComponent = ({ menu }) => { const { push } = useHistory(); const inputRef = useRef(null); const navRef = useRef(null); const dialogNavRef = useRef(null); + const [systemMenuOpen, setSystemMenuOpen] = useState(false); + const [dialogContentOpen, setDialogContentOpen] = useState(false); const { selection, select } = useLeapStore((state) => ({ selectedMatch: state.selectedMatch, selection: state.selection, select: state.select })); - const [systemMenuOpen, setSystemMenuOpen] = useState(false); - const [dialogContentOpen, setDialogContentOpen] = useState(false); - const isOpen = menu !== 'closed'; + const menuState = menu || 'closed'; + const isOpen = menuState !== 'closed'; const eitherOpen = isOpen || systemMenuOpen; + useEffect(() => { + if (!isOpen) { + select(null); + setDialogContentOpen(false); + } else { + inputRef.current?.focus(); + } + }, [selection, isOpen]); + const onOpen = useCallback( (event: Event) => { event.preventDefault(); @@ -81,14 +91,8 @@ export const Nav: FunctionComponent = ({ menu = 'closed' }) => { [menu] ); - useEffect(() => { - inputRef.current?.focus(); - }, [selection]); - const onDialogClose = useCallback((open: boolean) => { if (!open) { - select(null); - setDialogContentOpen(false); push('/'); } }, []); @@ -112,8 +116,9 @@ export const Nav: FunctionComponent = ({ menu = 'closed' }) => { diff --git a/pkg/grid/src/styles/components.css b/pkg/grid/src/styles/components.css index 90caef24b8..7ad7a9e3f8 100644 --- a/pkg/grid/src/styles/components.css +++ b/pkg/grid/src/styles/components.css @@ -3,25 +3,25 @@ } .button { - @apply inline-flex items-center justify-center px-4 py-2 font-semibold text-base tracking-tight rounded-lg cursor-pointer; + @apply inline-flex items-center justify-center px-4 py-2 font-semibold text-base tracking-tight rounded-lg cursor-pointer; } .dialog-container { - @apply fixed z-40 top-1/2 left-1/2 min-w-80 transform -translate-x-1/2 -translate-y-1/2; + @apply fixed z-40 top-1/2 left-1/2 min-w-80 transform -translate-x-1/2 -translate-y-1/2; } .dialog { - @apply relative p-5 sm:p-8 bg-white rounded-3xl; + @apply relative p-5 sm:p-8 bg-white rounded-3xl; } .dialog-inner-container { - @apply h-full p-4 md:p-8 space-y-8 overflow-y-auto; + @apply h-full p-4 md:p-8 space-y-8 overflow-y-auto; } .dropdown { - @apply min-w-52 p-4 space-y-4 rounded-xl; + @apply min-w-52 p-4 rounded-xl; } .spinner { - @apply inline-flex items-center w-6 h-6 animate-spin; -} \ No newline at end of file + @apply inline-flex items-center w-6 h-6 animate-spin; +} diff --git a/pkg/grid/src/tiles/Tile.tsx b/pkg/grid/src/tiles/Tile.tsx index 2ab682141d..ad06013364 100644 --- a/pkg/grid/src/tiles/Tile.tsx +++ b/pkg/grid/src/tiles/Tile.tsx @@ -44,7 +44,7 @@ export const Tile: FunctionComponent = ({ docket, desk }) => { active={active} menuColor={menuColor} lightText={lightText} - className="absolute z-10 top-2.5 right-2.5 sm:top-4 sm:right-4 opacity-0 hover-none:opacity-100 focus:opacity-100 group-hover:opacity-100" + className="absolute z-10 top-2.5 right-2.5 sm:top-4 sm:right-4 opacity-0 hover-none:opacity-100 pointer-coarse:opacity-100 focus:opacity-100 group-hover:opacity-100" />

( {children} @@ -47,6 +47,10 @@ export const TileMenu = ({ desk, active, menuColor, lightText, className }: Tile }); const menuBg = { backgroundColor: menuColor }; + const linkOnSelect = useCallback((e: Event) => { + e.preventDefault(); + setTimeout(() => setOpen(false), 15); + }, []); return ( setOpen(isOpen)}> @@ -71,50 +75,29 @@ export const TileMenu = ({ desk, active, menuColor, lightText, className }: Tile sideOffset={4} onCloseAutoFocus={(e) => e.preventDefault()} className={classNames( - 'dropdown font-semibold', + 'dropdown py-2 font-semibold', lightText ? 'text-gray-100' : 'text-gray-800' )} style={menuBg} > - + {/* TODO: revisit with Liam { e.preventDefault(); setTimeout(() => setOpen(false), 0) }}>App Info */} - { - e.preventDefault(); - setTimeout(() => setOpen(false), 0); - }} - > + App Info - + {active && ( - { - e.preventDefault(); - setTimeout(() => setOpen(false), 0); - }} - > + Suspend App )} {!active && mutate()}>Resume App} - { - e.preventDefault(); - setTimeout(() => setOpen(false), 0); - }} - > + Remove App