Browse Source

feat(toolbox): add disabledStyles to AbstractButton

It allows for specifying an override style collection which is applied when the
button is disabled.
master
Saúl Ibarra Corretgé 7 years ago
parent
commit
83ede66037

+ 41
- 3
react/features/base/toolbox/components/AbstractButton.js View File

@@ -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
     /**

+ 6
- 4
react/features/base/toolbox/components/AbstractToolboxItem.js View File

@@ -2,27 +2,29 @@
2 2
 
3 3
 import { Component } from 'react';
4 4
 
5
+import type { StyleType } from '../../styles';
6
+
5 7
 export type Styles = {
6 8
 
7 9
     /**
8 10
      * Style for the item's icon.
9 11
      */
10
-    iconStyle: Object,
12
+    iconStyle: StyleType,
11 13
 
12 14
     /**
13 15
      * Style for the item's label.
14 16
      */
15
-    labelStyle: Object,
17
+    labelStyle: StyleType,
16 18
 
17 19
     /**
18 20
      * Style for the item itself.
19 21
      */
20
-    style: Object,
22
+    style: StyleType,
21 23
 
22 24
     /**
23 25
      * Color for the item underlay (shows when clicked).
24 26
      */
25
-    underlayColor: string
27
+    underlayColor: ?string
26 28
 };
27 29
 
28 30
 export type Props = {

Loading…
Cancel
Save