|
@@ -1,152 +0,0 @@
|
1
|
|
-import InlineDialog from '@atlaskit/inline-dialog';
|
2
|
|
-import PropTypes from 'prop-types';
|
3
|
|
-import React, { Component } from 'react';
|
4
|
|
-import { connect } from 'react-redux';
|
5
|
|
-
|
6
|
|
-import { TOOLTIP_TO_POPUP_POSITION } from '../constants';
|
7
|
|
-import ToolbarButton from './ToolbarButton';
|
8
|
|
-
|
9
|
|
-/**
|
10
|
|
- * React {@code Component} for displaying a button which will open an inline
|
11
|
|
- * dialog.
|
12
|
|
- *
|
13
|
|
- * @extends Component
|
14
|
|
- */
|
15
|
|
-class ToolbarButtonWithDialog extends Component {
|
16
|
|
- /**
|
17
|
|
- * {@code ToolbarButtonWithDialog}'s property types.
|
18
|
|
- *
|
19
|
|
- * @static
|
20
|
|
- */
|
21
|
|
- static propTypes = {
|
22
|
|
- /**
|
23
|
|
- * Whether or not the button is visible, based on the visibility of the
|
24
|
|
- * toolbar. Used to automatically hide {@code InlineDialog} if not
|
25
|
|
- * visible.
|
26
|
|
- */
|
27
|
|
- _visible: PropTypes.bool,
|
28
|
|
-
|
29
|
|
- /**
|
30
|
|
- * A configuration object to describe how {@code ToolbarButton} should
|
31
|
|
- * render.
|
32
|
|
- *
|
33
|
|
- */
|
34
|
|
- button: PropTypes.object,
|
35
|
|
-
|
36
|
|
- /**
|
37
|
|
- * The React Component to show within {@code InlineDialog}.
|
38
|
|
- */
|
39
|
|
- content: PropTypes.func,
|
40
|
|
-
|
41
|
|
- /**
|
42
|
|
- * From which side tooltips should display. Will be re-used for
|
43
|
|
- * displaying the inline dialog for video quality adjustment.
|
44
|
|
- */
|
45
|
|
- tooltipPosition: PropTypes.string
|
46
|
|
- };
|
47
|
|
-
|
48
|
|
- /**
|
49
|
|
- * Initializes new {@code ToolbarButtonWithDialog} instance.
|
50
|
|
- *
|
51
|
|
- * @param {Object} props - The read-only properties with which the new
|
52
|
|
- * instance is to be initialized.
|
53
|
|
- */
|
54
|
|
- constructor(props) {
|
55
|
|
- super(props);
|
56
|
|
-
|
57
|
|
- this.state = {
|
58
|
|
- /**
|
59
|
|
- * Whether or not the inline dialog should be displayed.
|
60
|
|
- */
|
61
|
|
- showDialog: false
|
62
|
|
- };
|
63
|
|
-
|
64
|
|
- // Bind event handlers so they are only bound once for every instance.
|
65
|
|
- this._onDialogClose = this._onDialogClose.bind(this);
|
66
|
|
- this._onDialogToggle = this._onDialogToggle.bind(this);
|
67
|
|
- }
|
68
|
|
-
|
69
|
|
- /**
|
70
|
|
- * Automatically close the inline dialog if the button will not be visible.
|
71
|
|
- *
|
72
|
|
- * @inheritdoc
|
73
|
|
- * @returns {void}
|
74
|
|
- */
|
75
|
|
- componentWillReceiveProps(nextProps) {
|
76
|
|
- if (!nextProps._visible) {
|
77
|
|
- this._onDialogClose();
|
78
|
|
- }
|
79
|
|
- }
|
80
|
|
-
|
81
|
|
- /**
|
82
|
|
- * Implements React's {@link Component#render()}.
|
83
|
|
- *
|
84
|
|
- * @inheritdoc
|
85
|
|
- * @returns {ReactElement}
|
86
|
|
- */
|
87
|
|
- render() {
|
88
|
|
- const { _visible, content, tooltipPosition } = this.props;
|
89
|
|
- const buttonConfiguration = {
|
90
|
|
- ...this.props.button,
|
91
|
|
- classNames: [
|
92
|
|
- ...this.props.button.classNames,
|
93
|
|
- this.state.showDialog ? 'toggled button-active' : ''
|
94
|
|
- ]
|
95
|
|
- };
|
96
|
|
-
|
97
|
|
- const Content = content;
|
98
|
|
-
|
99
|
|
- return (
|
100
|
|
- <InlineDialog
|
101
|
|
- content = { <Content onClose = { this._onDialogClose } /> }
|
102
|
|
- isOpen = { _visible && this.state.showDialog }
|
103
|
|
- onClose = { this._onDialogClose }
|
104
|
|
- position = { TOOLTIP_TO_POPUP_POSITION[tooltipPosition] }>
|
105
|
|
- <ToolbarButton
|
106
|
|
- button = { buttonConfiguration }
|
107
|
|
- onClick = { this._onDialogToggle }
|
108
|
|
- tooltipPosition = { tooltipPosition } />
|
109
|
|
- </InlineDialog>
|
110
|
|
- );
|
111
|
|
- }
|
112
|
|
-
|
113
|
|
- /**
|
114
|
|
- * Hides the attached inline dialog.
|
115
|
|
- *
|
116
|
|
- * @private
|
117
|
|
- * @returns {void}
|
118
|
|
- */
|
119
|
|
- _onDialogClose() {
|
120
|
|
- this.setState({ showDialog: false });
|
121
|
|
- }
|
122
|
|
-
|
123
|
|
- /**
|
124
|
|
- * Toggles the display of the dialog.
|
125
|
|
- *
|
126
|
|
- * @private
|
127
|
|
- * @returns {void}
|
128
|
|
- */
|
129
|
|
- _onDialogToggle() {
|
130
|
|
- this.setState({
|
131
|
|
- showDialog: !this.state.showDialog
|
132
|
|
- });
|
133
|
|
- }
|
134
|
|
-}
|
135
|
|
-
|
136
|
|
-/**
|
137
|
|
- * Maps (parts of) the Redux state to the associated
|
138
|
|
- * {@code ToolbarButtonWithDialog} component's props.
|
139
|
|
- *
|
140
|
|
- * @param {Object} state - The Redux state.
|
141
|
|
- * @private
|
142
|
|
- * @returns {{
|
143
|
|
- * _visible: boolean
|
144
|
|
- * }}
|
145
|
|
- */
|
146
|
|
-function _mapStateToProps(state) {
|
147
|
|
- return {
|
148
|
|
- _visible: state['features/toolbox'].visible
|
149
|
|
- };
|
150
|
|
-}
|
151
|
|
-
|
152
|
|
-export default connect(_mapStateToProps)(ToolbarButtonWithDialog);
|