Browse Source

feat(toolbar): use AtlasKit tooltip

master
Leonard Kim 7 years ago
parent
commit
c3a4a38414
1 changed files with 77 additions and 23 deletions
  1. 77
    23
      react/features/toolbox/components/ToolbarButton.web.js

+ 77
- 23
react/features/toolbox/components/ToolbarButton.web.js View File

@@ -1,13 +1,11 @@
1 1
 /* @flow */
2 2
 
3
+import { Tooltip } from '@atlaskit/tooltip';
3 4
 import React, { Component } from 'react';
4 5
 
5 6
 import { translate } from '../../base/i18n';
6 7
 
7
-import {
8
-    setTooltip,
9
-    setTooltipText
10
-} from '../../../../modules/UI/util/Tooltip';
8
+import { isButtonEnabled } from '../functions';
11 9
 
12 10
 import StatelessToolbarButton from './StatelessToolbarButton';
13 11
 
@@ -23,6 +21,22 @@ class ToolbarButton extends Component {
23 21
     button: Object;
24 22
     _createRefToButton: Function;
25 23
 
24
+    _onClick: Function;
25
+
26
+    _onMouseOut: Function;
27
+
28
+    _onMouseOver: Function;
29
+
30
+    state: {
31
+
32
+        /**
33
+         * Whether or not the tooltip for the button should be displayed.
34
+         *
35
+         * @type {boolean}
36
+         */
37
+        showTooltip: boolean
38
+    }
39
+
26 40
     /**
27 41
      * Toolbar button component's property types.
28 42
      *
@@ -67,8 +81,15 @@ class ToolbarButton extends Component {
67 81
     constructor(props: Object) {
68 82
         super(props);
69 83
 
84
+        this.state = {
85
+            showTooltip: false
86
+        };
87
+
70 88
         // Bind methods to save the context
71 89
         this._createRefToButton = this._createRefToButton.bind(this);
90
+        this._onClick = this._onClick.bind(this);
91
+        this._onMouseOut = this._onMouseOut.bind(this);
92
+        this._onMouseOver = this._onMouseOver.bind(this);
72 93
     }
73 94
 
74 95
     /**
@@ -79,7 +100,7 @@ class ToolbarButton extends Component {
79 100
      * @returns {void}
80 101
      */
81 102
     componentDidMount(): void {
82
-        this._setShortcutAndTooltip();
103
+        this._setShortcut();
83 104
 
84 105
         if (this.props.onMount) {
85 106
             this.props.onMount();
@@ -105,21 +126,41 @@ class ToolbarButton extends Component {
105 126
      * @returns {ReactElement}
106 127
      */
107 128
     render(): ReactElement<*> {
108
-        const { button } = this.props;
129
+        const { button, t, tooltipPosition } = this.props;
109 130
         const popups = button.popups || [];
110 131
 
111 132
         const props = {
112 133
             ...this.props,
134
+            onClick: this._onClick,
113 135
             createRefToButton: this._createRefToButton
114 136
         };
115 137
 
116 138
         return (
117
-            <StatelessToolbarButton { ...props }>
118
-                { this._renderPopups(popups) }
119
-            </StatelessToolbarButton>
139
+            <Tooltip
140
+                description = { button.tooltipText || t(button.tooltipKey) }
141
+                onMouseOut = { this._onMouseOut }
142
+                onMouseOver = { this._onMouseOver }
143
+                position = { tooltipPosition }
144
+                visible = { this.state.showTooltip }>
145
+                <StatelessToolbarButton { ...props }>
146
+                    { this._renderPopups(popups) }
147
+                </StatelessToolbarButton>
148
+            </Tooltip>
120 149
         );
121 150
     }
122 151
 
152
+    /**
153
+     * Wrapper on on click handler props for current button.
154
+     *
155
+     * @param {Event} event - Click event object.
156
+     * @returns {void}
157
+     * @private
158
+     */
159
+    _onClick(event) {
160
+        this.props.onClick(event);
161
+        this.setState({ showTooltip: false });
162
+    }
163
+
123 164
     /**
124 165
      * Creates reference to current toolbar button.
125 166
      *
@@ -175,26 +216,39 @@ class ToolbarButton extends Component {
175 216
         });
176 217
     }
177 218
 
219
+    /**
220
+     * Hides any displayed tooltip.
221
+     *
222
+     * @private
223
+     * @returns {void}
224
+     */
225
+    _onMouseOut(): void {
226
+        this.setState({ showTooltip: false });
227
+    }
228
+
229
+    /**
230
+     * Hides any displayed tooltip.
231
+     *
232
+     * @private
233
+     * @returns {void}
234
+     */
235
+    _onMouseOver(): void {
236
+        const { button } = this.props;
237
+
238
+        this.setState({
239
+            showTooltip: isButtonEnabled(button.buttonName)
240
+                && !button.unclickable
241
+        });
242
+    }
243
+
178 244
     /**
179 245
      * Sets shortcut and tooltip for current toolbar button.
180 246
      *
181 247
      * @private
182 248
      * @returns {void}
183 249
      */
184
-    _setShortcutAndTooltip(): void {
185
-        const { button, tooltipPosition } = this.props;
186
-
187
-        if (!button.unclickable) {
188
-            if (button.tooltipText) {
189
-                setTooltipText(this.button,
190
-                    button.tooltipText,
191
-                    tooltipPosition);
192
-            } else {
193
-                setTooltip(this.button,
194
-                    button.tooltipKey,
195
-                    tooltipPosition);
196
-            }
197
-        }
250
+    _setShortcut(): void {
251
+        const { button } = this.props;
198 252
 
199 253
         if (button.shortcut && APP && APP.keyboardshortcut) {
200 254
             APP.keyboardshortcut.registerShortcut(

Loading…
Cancel
Save