浏览代码

feat(toolbar): use AtlasKit tooltip

master
Leonard Kim 7 年前
父节点
当前提交
c3a4a38414
共有 1 个文件被更改,包括 77 次插入23 次删除
  1. 77
    23
      react/features/toolbox/components/ToolbarButton.web.js

+ 77
- 23
react/features/toolbox/components/ToolbarButton.web.js 查看文件

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+import { Tooltip } from '@atlaskit/tooltip';
3
 import React, { Component } from 'react';
4
 import React, { Component } from 'react';
4
 
5
 
5
 import { translate } from '../../base/i18n';
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
 import StatelessToolbarButton from './StatelessToolbarButton';
10
 import StatelessToolbarButton from './StatelessToolbarButton';
13
 
11
 
23
     button: Object;
21
     button: Object;
24
     _createRefToButton: Function;
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
      * Toolbar button component's property types.
41
      * Toolbar button component's property types.
28
      *
42
      *
67
     constructor(props: Object) {
81
     constructor(props: Object) {
68
         super(props);
82
         super(props);
69
 
83
 
84
+        this.state = {
85
+            showTooltip: false
86
+        };
87
+
70
         // Bind methods to save the context
88
         // Bind methods to save the context
71
         this._createRefToButton = this._createRefToButton.bind(this);
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
      * @returns {void}
100
      * @returns {void}
80
      */
101
      */
81
     componentDidMount(): void {
102
     componentDidMount(): void {
82
-        this._setShortcutAndTooltip();
103
+        this._setShortcut();
83
 
104
 
84
         if (this.props.onMount) {
105
         if (this.props.onMount) {
85
             this.props.onMount();
106
             this.props.onMount();
105
      * @returns {ReactElement}
126
      * @returns {ReactElement}
106
      */
127
      */
107
     render(): ReactElement<*> {
128
     render(): ReactElement<*> {
108
-        const { button } = this.props;
129
+        const { button, t, tooltipPosition } = this.props;
109
         const popups = button.popups || [];
130
         const popups = button.popups || [];
110
 
131
 
111
         const props = {
132
         const props = {
112
             ...this.props,
133
             ...this.props,
134
+            onClick: this._onClick,
113
             createRefToButton: this._createRefToButton
135
             createRefToButton: this._createRefToButton
114
         };
136
         };
115
 
137
 
116
         return (
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
      * Creates reference to current toolbar button.
165
      * Creates reference to current toolbar button.
125
      *
166
      *
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
      * Sets shortcut and tooltip for current toolbar button.
245
      * Sets shortcut and tooltip for current toolbar button.
180
      *
246
      *
181
      * @private
247
      * @private
182
      * @returns {void}
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
         if (button.shortcut && APP && APP.keyboardshortcut) {
253
         if (button.shortcut && APP && APP.keyboardshortcut) {
200
             APP.keyboardshortcut.registerShortcut(
254
             APP.keyboardshortcut.registerShortcut(

正在加载...
取消
保存