Переглянути джерело

ref(overflow-menu) Use ContextMenu component (#11282)

refactor overflow menu to use ContextMenu component
refactor toolboxItem to use ContextMenuItem when needed
factor2
Robert Pintilii 3 роки тому
джерело
коміт
ed9b85f287
Аккаунт користувача з таким Email не знайдено

+ 10
- 1
css/_atlaskit_overrides.scss Переглянути файл

@@ -28,7 +28,7 @@
28 28
 /**
29 29
  * Keep overflow menu within screen vertical bounds and make it scrollable.
30 30
  */
31
- .toolbox-button-wth-dialog > div:nth-child(2) {
31
+.toolbox-button-wth-dialog > div:nth-child(2) {
32 32
     background: $menuBG;
33 33
     max-height: calc(100vh - #{$newToolbarSizeWithPadding} - 46px);
34 34
     margin-bottom: 4px;
@@ -36,6 +36,15 @@
36 36
     overflow-y: auto;
37 37
 }
38 38
 
39
+/**
40
+ * Remove background color and box-shadow for the context menu container.
41
+ */
42
+.toolbox-button-wth-dialog.context-menu > div:nth-child(2) {
43
+    background: transparent;
44
+    box-shadow: none;
45
+    overflow-y: initial;
46
+}
47
+
39 48
 .audio-preview > div:nth-child(2),
40 49
 .video-preview > div:nth-child(2),
41 50
 .reactions-menu-popup > div:nth-child(2) {

+ 14
- 0
react/features/base/components/context-menu/ContextMenu.js Переглянути файл

@@ -11,6 +11,11 @@ import participantsPaneTheme from '../themes/participantsPaneTheme.json';
11 11
 
12 12
 type Props = {
13 13
 
14
+    /**
15
+     * Accessibility label for menu container.
16
+     */
17
+    accessibilityLabel?: string,
18
+
14 19
     /**
15 20
      * Children of the context menu.
16 21
      */
@@ -51,6 +56,11 @@ type Props = {
51 56
      */
52 57
     onClick?: Function,
53 58
 
59
+    /**
60
+     * Keydown handler.
61
+     */
62
+    onKeyDown?: Function,
63
+
54 64
     /**
55 65
      * Callback for drawer close.
56 66
      */
@@ -111,6 +121,7 @@ const useStyles = makeStyles(theme => {
111 121
 });
112 122
 
113 123
 const ContextMenu = ({
124
+    accessibilityLabel,
114 125
     children,
115 126
     className,
116 127
     entity,
@@ -119,6 +130,7 @@ const ContextMenu = ({
119 130
     isDrawerOpen,
120 131
     offsetTarget,
121 132
     onClick,
133
+    onKeyDown,
122 134
     onDrawerClose,
123 135
     onMouseEnter,
124 136
     onMouseLeave
@@ -179,12 +191,14 @@ const ContextMenu = ({
179 191
             </Drawer>
180 192
         </JitsiPortal>
181 193
         : <div
194
+            aria-label = { accessibilityLabel }
182 195
             className = { clsx(participantsPaneTheme.ignoredChildClassName,
183 196
                 styles.contextMenu,
184 197
                 isHidden && styles.contextMenuHidden,
185 198
                 className
186 199
             ) }
187 200
             onClick = { onClick }
201
+            onKeyDown = { onKeyDown }
188 202
             onMouseEnter = { onMouseEnter }
189 203
             onMouseLeave = { onMouseLeave }
190 204
             ref = { containerRef }>

+ 16
- 1
react/features/base/components/context-menu/ContextMenuItem.js Переглянути файл

@@ -46,6 +46,16 @@ export type Props = {
46 46
      */
47 47
     onClick?: Function,
48 48
 
49
+    /**
50
+     * Keydown handler.
51
+     */
52
+    onKeyDown?: Function,
53
+
54
+    /**
55
+     * Keypress handler.
56
+     */
57
+    onKeyPress?: Function,
58
+
49 59
     /**
50 60
      * Action text.
51 61
      */
@@ -100,6 +110,8 @@ const ContextMenuItem = ({
100 110
     id,
101 111
     icon,
102 112
     onClick,
113
+    onKeyDown,
114
+    onKeyPress,
103 115
     text,
104 116
     textClassName }: Props) => {
105 117
     const styles = useStyles();
@@ -107,6 +119,7 @@ const ContextMenuItem = ({
107 119
 
108 120
     return (
109 121
         <div
122
+            aria-disabled = { disabled }
110 123
             aria-label = { accessibilityLabel }
111 124
             className = { clsx(styles.contextMenuItem,
112 125
                     _overflowDrawer && styles.contextMenuItemDrawer,
@@ -115,7 +128,9 @@ const ContextMenuItem = ({
115 128
             ) }
116 129
             id = { id }
117 130
             key = { text }
118
-            onClick = { onClick }>
131
+            onClick = { disabled ? undefined : onClick }
132
+            onKeyDown = { disabled ? undefined : onKeyDown }
133
+            onKeyPress = { disabled ? undefined : onKeyPress }>
119 134
             {customIcon ? customIcon
120 135
                 : icon && <Icon
121 136
                     className = { styles.contextMenuItemIcon }

+ 5
- 0
react/features/base/toolbox/components/AbstractButton.js Переглянути файл

@@ -20,6 +20,11 @@ export type Props = {|
20 20
      */
21 21
     buttonKey?: string,
22 22
 
23
+    /**
24
+     * Whether or not the button is displayed in a context menu.
25
+     */
26
+    contextMenu?: boolean,
27
+
23 28
     /**
24 29
      * An extra class name to be added at the end of the element's class name
25 30
      * in order to enable custom styling.

+ 19
- 0
react/features/base/toolbox/components/ToolboxItem.web.js Переглянути файл

@@ -2,6 +2,7 @@
2 2
 
3 3
 import React, { Fragment } from 'react';
4 4
 
5
+import ContextMenuItem from '../../components/context-menu/ContextMenuItem';
5 6
 import { Icon } from '../../icons';
6 7
 import { Tooltip } from '../../tooltip';
7 8
 
@@ -10,6 +11,11 @@ import type { Props as AbstractToolboxItemProps } from './AbstractToolboxItem';
10 11
 
11 12
 type Props = AbstractToolboxItemProps & {
12 13
 
14
+    /**
15
+     * Whether or not the item is displayed in a context menu.
16
+     */
17
+    contextMenu?: boolean,
18
+
13 19
     /**
14 20
     * On key down handler.
15 21
     */
@@ -58,8 +64,10 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
58 64
      */
59 65
     _renderItem() {
60 66
         const {
67
+            contextMenu,
61 68
             disabled,
62 69
             elementAfter,
70
+            icon,
63 71
             onClick,
64 72
             onKeyDown,
65 73
             showLabel,
@@ -81,6 +89,17 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
81 89
 
82 90
         const elementType = showLabel ? 'li' : 'div';
83 91
         const useTooltip = this.tooltip && this.tooltip.length > 0;
92
+
93
+        if (contextMenu) {
94
+            return (<ContextMenuItem
95
+                accessibilityLabel = { this.accessibilityLabel }
96
+                disabled = { disabled }
97
+                icon = { icon }
98
+                onClick = { onClick }
99
+                onKeyDown = { onKeyDown }
100
+                onKeyPress = { this._onKeyPress }
101
+                text = { this.label } />);
102
+        }
84 103
         let children = (
85 104
             <Fragment>
86 105
                 { this._renderIcon() }

+ 23
- 5
react/features/toolbox/components/web/OverflowMenuButton.js Переглянути файл

@@ -1,14 +1,16 @@
1 1
 /* @flow */
2 2
 
3 3
 import InlineDialog from '@atlaskit/inline-dialog';
4
+import { withStyles } from '@material-ui/styles';
4 5
 import React, { Component } from 'react';
5 6
 
6 7
 import { createToolbarEvent, sendAnalytics } from '../../../analytics';
7 8
 import { translate } from '../../../base/i18n';
8 9
 import { connect } from '../../../base/redux';
9 10
 import { ReactionEmoji, ReactionsMenu } from '../../../reactions/components';
10
-import { type ReactionEmojiProps } from '../../../reactions/constants';
11
+import { type ReactionEmojiProps, REACTIONS_MENU_HEIGHT } from '../../../reactions/constants';
11 12
 import { getReactionsQueue } from '../../../reactions/functions.any';
13
+import { DRAWER_MAX_HEIGHT } from '../../constants';
12 14
 
13 15
 import Drawer from './Drawer';
14 16
 import JitsiPortal from './JitsiPortal';
@@ -29,6 +31,11 @@ type Props = {
29 31
      */
30 32
     children: React$Node,
31 33
 
34
+    /**
35
+     * An object containing the CSS classes.
36
+     */
37
+    classes: Object,
38
+
32 39
     /**
33 40
      * Whether or not the OverflowMenu popover should display.
34 41
      */
@@ -60,6 +67,15 @@ type Props = {
60 67
     showMobileReactions: boolean
61 68
 };
62 69
 
70
+const styles = () => {
71
+    return {
72
+        overflowMenuDrawer: {
73
+            overflowY: 'auto',
74
+            height: `calc(${DRAWER_MAX_HEIGHT} - ${REACTIONS_MENU_HEIGHT}px - 16px)`
75
+        }
76
+    };
77
+};
78
+
63 79
 /**
64 80
  * A React {@code Component} for opening or closing the {@code OverflowMenu}.
65 81
  *
@@ -105,10 +121,10 @@ class OverflowMenuButton extends Component<Props> {
105 121
      * @returns {ReactElement}
106 122
      */
107 123
     render() {
108
-        const { children, isOpen, overflowDrawer, reactionsQueue, showMobileReactions } = this.props;
124
+        const { children, classes, isOpen, overflowDrawer, reactionsQueue, showMobileReactions } = this.props;
109 125
 
110 126
         return (
111
-            <div className = 'toolbox-button-wth-dialog'>
127
+            <div className = 'toolbox-button-wth-dialog context-menu'>
112 128
                 {
113 129
                     overflowDrawer ? (
114 130
                         <>
@@ -120,7 +136,9 @@ class OverflowMenuButton extends Component<Props> {
120 136
                                 <Drawer
121 137
                                     isOpen = { isOpen }
122 138
                                     onClose = { this._onCloseDialog }>
123
-                                    {children}
139
+                                    <div className = { classes.overflowMenuDrawer }>
140
+                                        {children}
141
+                                    </div>
124 142
                                     {showMobileReactions && <ReactionsMenu overflowMenu = { true } />}
125 143
                                 </Drawer>
126 144
                                 {showMobileReactions && <div className = 'reactions-animations-container'>
@@ -194,4 +212,4 @@ function mapStateToProps(state) {
194 212
     };
195 213
 }
196 214
 
197
-export default translate(connect(mapStateToProps)(OverflowMenuButton));
215
+export default withStyles(styles)(translate(connect(mapStateToProps)(OverflowMenuButton)));

+ 40
- 35
react/features/toolbox/components/web/Toolbox.js Переглянути файл

@@ -1,8 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { withStyles } from '@material-ui/core/styles';
4
-import clsx from 'clsx';
5
-import React, { Component, Fragment } from 'react';
4
+import React, { Component } from 'react';
6 5
 import { batch } from 'react-redux';
7 6
 
8 7
 import keyboardShortcut from '../../../../../modules/keyboardshortcut/keyboardshortcut';
@@ -12,6 +11,7 @@ import {
12 11
     createToolbarEvent,
13 12
     sendAnalytics
14 13
 } from '../../../analytics';
14
+import { ContextMenu, ContextMenuItemGroup } from '../../../base/components';
15 15
 import { getToolbarButtons } from '../../../base/config';
16 16
 import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
17 17
 import { openDialog, toggleDialog } from '../../../base/dialog';
@@ -46,7 +46,7 @@ import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
46 46
 import { addReactionToBuffer } from '../../../reactions/actions.any';
47 47
 import { toggleReactionsMenuVisibility } from '../../../reactions/actions.web';
48 48
 import { ReactionsMenuButton } from '../../../reactions/components';
49
-import { REACTIONS, REACTIONS_MENU_HEIGHT } from '../../../reactions/constants';
49
+import { REACTIONS } from '../../../reactions/constants';
50 50
 import { isReactionsEnabled } from '../../../reactions/functions.any';
51 51
 import {
52 52
     LiveStreamButton,
@@ -80,7 +80,7 @@ import {
80 80
     setToolbarHovered,
81 81
     showToolbox
82 82
 } from '../../actions';
83
-import { THRESHOLDS, NOT_APPLICABLE, DRAWER_MAX_HEIGHT, NOTIFY_CLICK_MODE } from '../../constants';
83
+import { THRESHOLDS, NOT_APPLICABLE, NOTIFY_CLICK_MODE } from '../../constants';
84 84
 import { isDesktopShareButtonDisabled, isToolboxVisible } from '../../functions';
85 85
 import DownloadButton from '../DownloadButton';
86 86
 import HangupButton from '../HangupButton';
@@ -284,18 +284,13 @@ type Props = {
284 284
 
285 285
 declare var APP: Object;
286 286
 
287
-const styles = theme => {
287
+const styles = () => {
288 288
     return {
289
-        overflowMenu: {
290
-            fontSize: 14,
291
-            listStyleType: 'none',
292
-            padding: '8px 0',
293
-            backgroundColor: theme.palette.ui03
294
-        },
295
-
296
-        overflowMenuDrawer: {
297
-            overflowY: 'auto',
298
-            height: `calc(${DRAWER_MAX_HEIGHT} - ${REACTIONS_MENU_HEIGHT}px - 16px)`
289
+        contextMenu: {
290
+            position: 'relative',
291
+            right: 'auto',
292
+            maxHeight: 'inherit',
293
+            margin: 0
299 294
         }
300 295
     };
301 296
 };
@@ -1337,29 +1332,39 @@ class Toolbox extends Component<Props> {
1337 1332
                                 showMobileReactions = {
1338 1333
                                     _reactionsEnabled && overflowMenuButtons.find(({ key }) => key === 'raisehand')
1339 1334
                                 }>
1340
-                                <ul
1341
-                                    aria-label = { t(toolbarAccLabel) }
1342
-                                    className = { clsx(classes.overflowMenu,
1343
-                                        _overflowDrawer && classes.overflowMenuDrawer)
1344
-                                    }
1345
-                                    id = 'overflow-menu'
1346
-                                    onKeyDown = { this._onEscKey }
1347
-                                    role = 'menu'>
1348
-                                    {overflowMenuButtons.map(({ group, key, Content, ...rest }, index, arr) => {
1349
-                                        const showSeparator = index > 0 && arr[index - 1].group !== group;
1350
-
1351
-                                        return (key !== 'raisehand' || !_reactionsEnabled)
1352
-                                            && <Fragment key = { `f${key}` }>
1353
-                                                {showSeparator && <Separator key = { `hr${group}` } />}
1354
-                                                <Content
1335
+                                <ContextMenu
1336
+                                    accessibilityLabel = { t(toolbarAccLabel) }
1337
+                                    className = { classes.contextMenu }
1338
+                                    hidden = { false }
1339
+                                    inDrawer = { _overflowDrawer }
1340
+                                    onKeyDown = { this._onEscKey }>
1341
+                                    {overflowMenuButtons.reduce((acc, val) => {
1342
+                                        if (acc.length) {
1343
+                                            const prev = acc[acc.length - 1];
1344
+                                            const group = prev[prev.length - 1].group;
1345
+
1346
+                                            if (group === val.group) {
1347
+                                                prev.push(val);
1348
+                                            } else {
1349
+                                                acc.push([ val ]);
1350
+                                            }
1351
+                                        } else {
1352
+                                            acc.push([ val ]);
1353
+                                        }
1354
+
1355
+                                        return acc;
1356
+                                    }, []).map(buttonGroup => (
1357
+                                        <ContextMenuItemGroup key = { `group-${buttonGroup[0].group}` }>
1358
+                                            {buttonGroup.map(({ key, Content, ...rest }) => (
1359
+                                                key !== 'raisehand' || !_reactionsEnabled)
1360
+                                                && <Content
1355 1361
                                                     { ...rest }
1356 1362
                                                     buttonKey = { key }
1363
+                                                    contextMenu = { true }
1357 1364
                                                     key = { key }
1358
-                                                    showLabel = { true } />
1359
-                                            </Fragment>
1360
-                                        ;
1361
-                                    })}
1362
-                                </ul>
1365
+                                                    showLabel = { true } />)}
1366
+                                        </ContextMenuItemGroup>))}
1367
+                                </ContextMenu>
1363 1368
                             </OverflowMenuButton>
1364 1369
                         )}
1365 1370
 

Завантаження…
Відмінити
Зберегти