+
{text}
@@ -30,8 +30,8 @@
);
}
-const MemoizedThreadMenuItem: React.ComponentType
= React.memo(
- ThreadMenuItem,
+const MemoizedMenuItem: React.ComponentType = React.memo(
+ MenuItem,
);
-export default MemoizedThreadMenuItem;
+export default MemoizedMenuItem;
diff --git a/web/chat/thread-menu.css b/web/components/menu.css
copy from web/chat/thread-menu.css
copy to web/components/menu.css
--- a/web/chat/thread-menu.css
+++ b/web/components/menu.css
@@ -1,28 +1,28 @@
-button.topBarMenuButton {
+button.menuButton {
background-color: transparent;
border: none;
cursor: pointer;
color: var(--thread-top-bar-menu-color);
}
-div.topBarMenuActionList {
+div.menuActionList {
position: absolute;
right: 10px;
top: 55px;
z-index: 1;
display: flex;
flex-direction: column;
- background-color: var(--thread-menu-bg);
+ background-color: var(--menu-bg);
border-radius: 4px;
padding: 4px 0;
}
-button.topBarMenuAction {
+button.menuAction {
z-index: 1;
background-color: transparent;
padding: 12px 16px;
- color: var(--thread-menu-color);
- background-color: var(--thread-menu-bg);
+ color: var(--menu-color);
+ background-color: var(--menu-bg);
font-size: var(--m-font-16);
line-height: 1.5;
border: none;
@@ -31,11 +31,11 @@
align-items: center;
}
-button.topBarMenuAction:hover {
- color: var(--thread-menu-color-hover);
+button.menuAction:hover {
+ color: var(--menu-color-hover);
}
-div.topBarMenuActionIcon {
+div.menuActionIcon {
font-size: var(--l-font-18);
display: flex;
justify-content: center;
@@ -43,16 +43,16 @@
width: 20px;
}
-button.topBarMenuActionDangerous {
- color: var(--thread-menu-color-dangerous);
+button.menuActionDangerous {
+ color: var(--menu-color-dangerous);
}
-button.topBarMenuActionDangerous:hover {
- color: var(--thread-menu-color-dangerous-hover);
+button.menuActionDangerous:hover {
+ color: var(--menu-color-dangerous-hover);
}
hr.separator {
height: 1px;
- background: var(--thread-menu-separator-color);
+ background: var(--menu-separator-color);
margin: 10px 16px;
max-width: 130px;
border: none;
diff --git a/web/components/menu.react.js b/web/components/menu.react.js
new file mode 100644
--- /dev/null
+++ b/web/components/menu.react.js
@@ -0,0 +1,55 @@
+// @flow
+
+import * as React from 'react';
+
+import css from './menu.css';
+
+type MenuProps = {
+ +icon: React.Node,
+ +children?: React.Node,
+};
+
+function Menu(props: MenuProps): React.Node {
+ const [isOpen, setIsOpen] = React.useState(false);
+
+ const { icon, children } = props;
+
+ const closeMenuCallback = React.useCallback(() => {
+ document.removeEventListener('click', closeMenuCallback);
+ if (isOpen) {
+ setIsOpen(false);
+ }
+ }, [isOpen]);
+
+ React.useEffect(() => {
+ if (!document || !isOpen) {
+ return undefined;
+ }
+ document.addEventListener('click', closeMenuCallback);
+ return () => document.removeEventListener('click', closeMenuCallback);
+ }, [closeMenuCallback, isOpen]);
+
+ const switchMenuCallback = React.useCallback(() => {
+ setIsOpen(isMenuOpen => !isMenuOpen);
+ }, []);
+
+ if (React.Children.count === 0) {
+ return null;
+ }
+
+ let menuActionList = null;
+ if (isOpen) {
+ menuActionList = {children}
;
+ }
+
+ return (
+
+
+ {menuActionList}
+
+ );
+}
+
+export default Menu;
diff --git a/web/theme.css b/web/theme.css
--- a/web/theme.css
+++ b/web/theme.css
@@ -102,12 +102,12 @@
--thread-ancestor-separator-color: var(--shades-white-60);
--text-message-default-background: var(--shades-black-80);
--message-action-tooltip-bg: var(--shades-black-90);
- --thread-menu-bg: var(--shades-black-90);
- --thread-menu-separator-color: var(--shades-black-80);
- --thread-menu-color: var(--shades-black-60);
- --thread-menu-color-hover: var(--shades-white-100);
- --thread-menu-color-dangerous: var(--error-primary);
- --thread-menu-color-dangerous-hover: var(--error-light-50);
+ --menu-bg: var(--shades-black-90);
+ --menu-separator-color: var(--shades-black-80);
+ --menu-color: var(--shades-black-60);
+ --menu-color-hover: var(--shades-white-100);
+ --menu-color-dangerous: var(--error-primary);
+ --menu-color-dangerous-hover: var(--error-light-50);
--app-list-icon-read-only-color: var(--shades-black-60);
--app-list-icon-enabled-color: var(--success-primary);
--app-list-icon-disabled-color: var(--shades-white-80);