|
|
@@ -2,6 +2,8 @@
|
|
2
|
2
|
|
|
3
|
3
|
import React, { Component } from 'react';
|
|
4
|
4
|
|
|
|
5
|
+import { combineStyles } from '../../styles';
|
|
|
6
|
+
|
|
5
|
7
|
import type { Styles } from './AbstractToolboxItem';
|
|
6
|
8
|
import ToolboxItem from './ToolboxItem';
|
|
7
|
9
|
|
|
|
@@ -12,6 +14,12 @@ export type Props = {
|
|
12
|
14
|
*/
|
|
13
|
15
|
afterClick: ?Function,
|
|
14
|
16
|
|
|
|
17
|
+ /**
|
|
|
18
|
+ * Extra styles which will be applied in conjunction with `styles` or
|
|
|
19
|
+ * `toggledStyles` when the button is disabled;
|
|
|
20
|
+ */
|
|
|
21
|
+ disabledStyles: ?Styles,
|
|
|
22
|
+
|
|
15
|
23
|
/**
|
|
16
|
24
|
* Whether to show the label or not.
|
|
17
|
25
|
*/
|
|
|
@@ -38,12 +46,27 @@ export type Props = {
|
|
38
|
46
|
visible: boolean
|
|
39
|
47
|
};
|
|
40
|
48
|
|
|
|
49
|
+/**
|
|
|
50
|
+ * Default style for disabled buttons.
|
|
|
51
|
+ */
|
|
|
52
|
+export const defaultDisabledButtonStyles = {
|
|
|
53
|
+ iconStyle: {
|
|
|
54
|
+ opacity: 0.5
|
|
|
55
|
+ },
|
|
|
56
|
+ labelStyle: {
|
|
|
57
|
+ opacity: 0.5
|
|
|
58
|
+ },
|
|
|
59
|
+ style: undefined,
|
|
|
60
|
+ underlayColor: undefined
|
|
|
61
|
+};
|
|
|
62
|
+
|
|
41
|
63
|
/**
|
|
42
|
64
|
* An abstract implementation of a button.
|
|
43
|
65
|
*/
|
|
44
|
66
|
export default class AbstractButton<P: Props, S: *> extends Component<P, S> {
|
|
45
|
67
|
static defaultProps = {
|
|
46
|
68
|
afterClick: undefined,
|
|
|
69
|
+ disabledStyles: defaultDisabledButtonStyles,
|
|
47
|
70
|
showLabel: false,
|
|
48
|
71
|
styles: undefined,
|
|
49
|
72
|
toggledStyles: undefined,
|
|
|
@@ -151,10 +174,25 @@ export default class AbstractButton<P: Props, S: *> extends Component<P, S> {
|
|
151
|
174
|
* @private
|
|
152
|
175
|
* @returns {?Styles}
|
|
153
|
176
|
*/
|
|
154
|
|
- _getStyles() {
|
|
155
|
|
- const { styles, toggledStyles } = this.props;
|
|
|
177
|
+ _getStyles(): ?Styles {
|
|
|
178
|
+ const { disabledStyles, styles, toggledStyles } = this.props;
|
|
|
179
|
+ const buttonStyles
|
|
|
180
|
+ = (this._isToggled() ? toggledStyles : styles) || styles;
|
|
|
181
|
+
|
|
|
182
|
+ if (this._isDisabled() && buttonStyles && disabledStyles) {
|
|
|
183
|
+ return {
|
|
|
184
|
+ iconStyle: combineStyles(
|
|
|
185
|
+ buttonStyles.iconStyle, disabledStyles.iconStyle),
|
|
|
186
|
+ labelStyle: combineStyles(
|
|
|
187
|
+ buttonStyles.labelStyle, disabledStyles.labelStyle),
|
|
|
188
|
+ style: combineStyles(
|
|
|
189
|
+ buttonStyles.style, disabledStyles.style),
|
|
|
190
|
+ underlayColor:
|
|
|
191
|
+ disabledStyles.underlayColor || buttonStyles.underlayColor
|
|
|
192
|
+ };
|
|
|
193
|
+ }
|
|
156
|
194
|
|
|
157
|
|
- return (this._isToggled() ? toggledStyles : styles) || styles;
|
|
|
195
|
+ return buttonStyles;
|
|
158
|
196
|
}
|
|
159
|
197
|
|
|
160
|
198
|
/**
|