From 022fadee01919eeac0bc249c4ec6740479775284 Mon Sep 17 00:00:00 2001 From: Peter Zimon Date: Thu, 1 Jun 2023 17:04:20 +0200 Subject: [PATCH] Added interactivity to menu component in AdminX refs. https://github.com/TryGhost/Team/issues/3351 --- .../src/admin-x-ds/global/Menu.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/Menu.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/Menu.tsx index 233467aa0e..423d7d97ee 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/Menu.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/Menu.tsx @@ -1,5 +1,5 @@ import Icon from './Icon'; -import React from 'react'; +import React, {useState} from 'react'; export type MenuItem = { id: string, @@ -16,7 +16,19 @@ interface MenuProps { } const Menu: React.FC = ({items, position, className}) => { - let menuListStyles = 'absolute z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-none'; + const [menuOpen, setMenuOpen] = useState(false); + + let menuListStyles = 'absolute z-40 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-none'; + + const toggleMenu = () => { + setMenuOpen(!menuOpen); + }; + + const handleBackdropClick = (e: React.MouseEvent) => { + if (e.target === e.currentTarget) { + setMenuOpen(false); + } + }; switch (position) { case 'left': @@ -31,12 +43,14 @@ const Menu: React.FC = ({items, position, className}) => { break; } + menuListStyles += menuOpen ? 'block' : 'hidden'; + return ( - /* Menu */
+
{/* Menu Trigger */} -
- @@ -44,7 +58,6 @@ const Menu: React.FC = ({items, position, className}) => { {/* Menu List */}
- {/* Menu Item */} {items.map(item => ( ))}