|
@@ -1,9 +1,18 @@
|
|
1
|
+import InlineDialog from '@atlaskit/inline-dialog';
|
|
2
|
+import PropTypes from 'prop-types';
|
1
|
3
|
import React, { Component } from 'react';
|
|
4
|
+import { connect } from 'react-redux';
|
2
|
5
|
|
3
|
|
-import { ToolbarButtonWithDialog } from '../../toolbox';
|
|
6
|
+import { ToolbarButton, TOOLTIP_TO_POPUP_POSITION } from '../../toolbox';
|
|
7
|
+
|
|
8
|
+import { setInfoDialogVisibility } from '../actions';
|
4
|
9
|
|
5
|
10
|
import InfoDialog from './InfoDialog';
|
6
|
11
|
|
|
12
|
+declare var interfaceConfig: Object;
|
|
13
|
+
|
|
14
|
+const { INITIAL_TOOLBAR_TIMEOUT } = interfaceConfig;
|
|
15
|
+
|
7
|
16
|
/**
|
8
|
17
|
* A configuration object to describe how {@code ToolbarButton} should render
|
9
|
18
|
* the button.
|
|
@@ -25,6 +34,103 @@ const DEFAULT_BUTTON_CONFIGURATION = {
|
25
|
34
|
* @extends Component
|
26
|
35
|
*/
|
27
|
36
|
class InfoDialogButton extends Component {
|
|
37
|
+ /**
|
|
38
|
+ * {@code InfoDialogButton} component's property types.
|
|
39
|
+ *
|
|
40
|
+ * @static
|
|
41
|
+ */
|
|
42
|
+ static propTypes = {
|
|
43
|
+ /**
|
|
44
|
+ * Whether or not {@code InfoDialog} should be displayed.
|
|
45
|
+ */
|
|
46
|
+ _showDialog: PropTypes.bool,
|
|
47
|
+
|
|
48
|
+ /**
|
|
49
|
+ * Whether or not the toolbox, in which this component exists, are
|
|
50
|
+ * visible.
|
|
51
|
+ */
|
|
52
|
+ _toolboxVisible: PropTypes.bool,
|
|
53
|
+
|
|
54
|
+ /**
|
|
55
|
+ * Invoked to toggle display of the info dialog
|
|
56
|
+ */
|
|
57
|
+ dispatch: PropTypes.func,
|
|
58
|
+
|
|
59
|
+ /**
|
|
60
|
+ * From which side tooltips should display. Will be re-used for
|
|
61
|
+ * displaying the inline dialog for video quality adjustment.
|
|
62
|
+ */
|
|
63
|
+ tooltipPosition: PropTypes.string
|
|
64
|
+ };
|
|
65
|
+
|
|
66
|
+ /**
|
|
67
|
+ * Initializes new {@code ToolbarButtonWithDialog} instance.
|
|
68
|
+ *
|
|
69
|
+ * @param {Object} props - The read-only properties with which the new
|
|
70
|
+ * instance is to be initialized.
|
|
71
|
+ */
|
|
72
|
+ constructor(props) {
|
|
73
|
+ super(props);
|
|
74
|
+
|
|
75
|
+ /**
|
|
76
|
+ * The timeout to automatically hide the {@code InfoDialog} if it has
|
|
77
|
+ * not been interacted with.
|
|
78
|
+ *
|
|
79
|
+ * @type {timeoutID}
|
|
80
|
+ */
|
|
81
|
+ this._autoHideDialogTimeout = null;
|
|
82
|
+
|
|
83
|
+ this.state = {
|
|
84
|
+ /**
|
|
85
|
+ * Whether or not the dialog has been interacted with somehow, such
|
|
86
|
+ * as clicking or toggle display. A value of true will prevent the
|
|
87
|
+ * dialog from being automatically hidden.
|
|
88
|
+ */
|
|
89
|
+ hasInteractedWithDialog: false
|
|
90
|
+ };
|
|
91
|
+
|
|
92
|
+ // Bind event handlers so they are only bound once for every instance.
|
|
93
|
+ this._onDialogClose = this._onDialogClose.bind(this);
|
|
94
|
+ this._onDialogMouseOver = this._onDialogMouseOver.bind(this);
|
|
95
|
+ this._onDialogToggle = this._onDialogToggle.bind(this);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ /**
|
|
99
|
+ * Set a timeout to automatically hide the {@code InfoDialog}.
|
|
100
|
+ *
|
|
101
|
+ * @inheritdoc
|
|
102
|
+ */
|
|
103
|
+ componentDidMount() {
|
|
104
|
+ this._autoHideDialogTimeout = setTimeout(() => {
|
|
105
|
+ this._maybeHideDialog();
|
|
106
|
+ }, INITIAL_TOOLBAR_TIMEOUT);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ /**
|
|
110
|
+ * Update the state when the {@code InfoDialog} visibility has been updated.
|
|
111
|
+ *
|
|
112
|
+ * @inheritdoc
|
|
113
|
+ */
|
|
114
|
+ componentWillReceiveProps(nextProps) {
|
|
115
|
+ if (!this.state.hasInteractedWithDialog
|
|
116
|
+ && (nextProps._showDialog !== this.props._showDialog)) {
|
|
117
|
+ this.setState({ hasInteractedWithDialog: true });
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ if (!nextProps._toolboxVisible && this.props._toolboxVisible) {
|
|
121
|
+ this._onDialogClose();
|
|
122
|
+ }
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ /**
|
|
126
|
+ * Clear the timeout to automatically show the {@code InfoDialog}.
|
|
127
|
+ *
|
|
128
|
+ * @inheritdoc
|
|
129
|
+ */
|
|
130
|
+ componentWillUnmount() {
|
|
131
|
+ clearTimeout(this._autoHideDialogTimeout);
|
|
132
|
+ }
|
|
133
|
+
|
28
|
134
|
/**
|
29
|
135
|
* Implements React's {@link Component#render()}.
|
30
|
136
|
*
|
|
@@ -32,13 +138,96 @@ class InfoDialogButton extends Component {
|
32
|
138
|
* @returns {ReactElement}
|
33
|
139
|
*/
|
34
|
140
|
render() {
|
|
141
|
+ const { _showDialog, _toolboxVisible, tooltipPosition } = this.props;
|
|
142
|
+ const buttonConfiguration = {
|
|
143
|
+ ...DEFAULT_BUTTON_CONFIGURATION,
|
|
144
|
+ classNames: [
|
|
145
|
+ ...DEFAULT_BUTTON_CONFIGURATION.classNames,
|
|
146
|
+ _showDialog ? 'toggled button-active' : ''
|
|
147
|
+ ]
|
|
148
|
+ };
|
|
149
|
+
|
35
|
150
|
return (
|
36
|
|
- <ToolbarButtonWithDialog
|
37
|
|
- { ...this.props }
|
38
|
|
- button = { DEFAULT_BUTTON_CONFIGURATION }
|
39
|
|
- content = { InfoDialog } />
|
|
151
|
+ <InlineDialog
|
|
152
|
+ content = { <InfoDialog
|
|
153
|
+ onClose = { this._onDialogClose }
|
|
154
|
+ onMouseOver = { this._onDialogMouseOver } /> }
|
|
155
|
+ isOpen = { _toolboxVisible && _showDialog }
|
|
156
|
+ onClose = { this._onDialogClose }
|
|
157
|
+ onContentClick = { this._onDialogInteract }
|
|
158
|
+ position = { TOOLTIP_TO_POPUP_POSITION[tooltipPosition] }>
|
|
159
|
+ <ToolbarButton
|
|
160
|
+ button = { buttonConfiguration }
|
|
161
|
+ onClick = { this._onDialogToggle }
|
|
162
|
+ tooltipPosition = { tooltipPosition } />
|
|
163
|
+ </InlineDialog>
|
40
|
164
|
);
|
41
|
165
|
}
|
|
166
|
+
|
|
167
|
+ /**
|
|
168
|
+ * Callback invoked after a timeout to trigger hiding of the
|
|
169
|
+ * {@code InfoDialog} if there has been no interaction with the dialog
|
|
170
|
+ * and the dialog is currently showing.
|
|
171
|
+ *
|
|
172
|
+ * @private
|
|
173
|
+ * @returns {void}
|
|
174
|
+ */
|
|
175
|
+ _maybeHideDialog() {
|
|
176
|
+ if (!this.state.hasInteractedWithDialog && this.props._showDialog) {
|
|
177
|
+ this._onDialogToggle();
|
|
178
|
+ }
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ /**
|
|
182
|
+ * Hides {@code InfoDialog}.
|
|
183
|
+ *
|
|
184
|
+ * @private
|
|
185
|
+ * @returns {void}
|
|
186
|
+ */
|
|
187
|
+ _onDialogClose() {
|
|
188
|
+ this.props.dispatch(setInfoDialogVisibility(false));
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ /**
|
|
192
|
+ * Updates the internal state to mark the {@code InfoDialog} as having been
|
|
193
|
+ * interacted with.
|
|
194
|
+ *
|
|
195
|
+ * @private
|
|
196
|
+ * @returns {void}
|
|
197
|
+ */
|
|
198
|
+ _onDialogMouseOver() {
|
|
199
|
+ if (!this.state.hasInteractedWithDialog) {
|
|
200
|
+ this.setState({ hasInteractedWithDialog: true });
|
|
201
|
+ }
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ /**
|
|
205
|
+ * Toggles the display of {@code InfoDialog}.
|
|
206
|
+ *
|
|
207
|
+ * @private
|
|
208
|
+ * @returns {void}
|
|
209
|
+ */
|
|
210
|
+ _onDialogToggle() {
|
|
211
|
+ this.props.dispatch(setInfoDialogVisibility(!this.props._showDialog));
|
|
212
|
+ }
|
|
213
|
+}
|
|
214
|
+
|
|
215
|
+/**
|
|
216
|
+ * Maps (parts of) the Redux state to the associated {@code InfoDialogButton}
|
|
217
|
+ * component's props.
|
|
218
|
+ *
|
|
219
|
+ * @param {Object} state - The Redux state.
|
|
220
|
+ * @private
|
|
221
|
+ * @returns {{
|
|
222
|
+ * _showDialog: boolean,
|
|
223
|
+ * _toolboxVisible: boolean
|
|
224
|
+ * }}
|
|
225
|
+ */
|
|
226
|
+function _mapStateToProps(state) {
|
|
227
|
+ return {
|
|
228
|
+ _showDialog: state['features/invite'].infoDialogVisible,
|
|
229
|
+ _toolboxVisible: state['features/toolbox'].visible
|
|
230
|
+ };
|
42
|
231
|
}
|
43
|
232
|
|
44
|
|
-export default InfoDialogButton;
|
|
233
|
+export default connect(_mapStateToProps)(InfoDialogButton);
|