|
@@ -1,42 +1,64 @@
|
1
|
1
|
// @flow
|
|
2
|
+
|
2
|
3
|
import PropTypes from 'prop-types';
|
3
|
4
|
import React, { Component } from 'react';
|
4
|
5
|
import { connect } from 'react-redux';
|
5
|
6
|
|
6
|
|
-import { ASPECT_RATIO_NARROW } from '../constants';
|
|
7
|
+import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from '../constants';
|
|
8
|
+
|
|
9
|
+/**
|
|
10
|
+ * Checks if given React component decorated in {@link AspectRatioAwareWrapper}
|
|
11
|
+ * has currently the {@link ASPECT_RATIO_NARROW} set in the aspect ratio
|
|
12
|
+ * property.
|
|
13
|
+ *
|
|
14
|
+ * @param {AspectRatioAwareWrapper} component - A
|
|
15
|
+ * {@link AspectRatioAwareWrapper} which has <tt>aspectRation</tt> property.
|
|
16
|
+ * @returns {boolean}
|
|
17
|
+ */
|
|
18
|
+export function isNarrowAspectRatio(component: React$Component<*>) {
|
|
19
|
+ return component.props.aspectRatio === ASPECT_RATIO_NARROW;
|
|
20
|
+}
|
7
|
21
|
|
8
|
22
|
/**
|
9
|
|
- * Decorates given React component class into {@link AspectRatioAwareWrapper}
|
10
|
|
- * which provides the <tt>aspectRatio</tt> property updated on each Redux state
|
11
|
|
- * change.
|
|
23
|
+ * Decorates a specific React {@code Component} class into an
|
|
24
|
+ * {@link AspectRatioAware} which provides the React prop {@code aspectRatio}
|
|
25
|
+ * updated on each redux state change.
|
12
|
26
|
*
|
13
|
|
- * @param {ReactClass} WrapperComponent - A React component class to be wrapped.
|
|
27
|
+ * @param {Class<React$Component>} WrappedComponent - A React {@code Component}
|
|
28
|
+ * class to be wrapped.
|
14
|
29
|
* @returns {AspectRatioAwareWrapper}
|
15
|
30
|
*/
|
16
|
|
-export function AspectRatioAware(
|
17
|
|
- WrapperComponent: ReactClass<*>): ReactClass<*> {
|
18
|
|
- return connect(_mapStateToProps)(
|
19
|
|
- class AspectRatioAwareWrapper extends Component {
|
|
31
|
+export function makeAspectRatioAware(
|
|
32
|
+ WrappedComponent: Class<React$Component<*>>
|
|
33
|
+): Class<React$Component<*>> {
|
|
34
|
+ /**
|
|
35
|
+ * Renders {@code WrappedComponent} with the React prop {@code aspectRatio}.
|
|
36
|
+ */
|
|
37
|
+ class AspectRatioAware extends Component<*> {
|
|
38
|
+ /**
|
|
39
|
+ * Properties of the aspect ratio aware wrapper.
|
|
40
|
+ */
|
|
41
|
+ static propTypes = {
|
20
|
42
|
/**
|
21
|
|
- * Properties of the aspect ratio aware wrapper.
|
|
43
|
+ * Either {@link ASPECT_RATIO_NARROW} or {@link ASPECT_RATIO_WIDE}.
|
22
|
44
|
*/
|
23
|
|
- static propTypes = {
|
24
|
|
- /**
|
25
|
|
- * Either {@link ASPECT_RATIO_NARROW} or
|
26
|
|
- * {@link ASPECT_RATIO_WIDE}.
|
27
|
|
- */
|
28
|
|
- aspectRatio: PropTypes.symbol
|
29
|
|
- }
|
|
45
|
+ aspectRatio: PropTypes.oneOf([
|
|
46
|
+ ASPECT_RATIO_NARROW,
|
|
47
|
+ ASPECT_RATIO_WIDE
|
|
48
|
+ ])
|
|
49
|
+ }
|
30
|
50
|
|
31
|
|
- /**
|
32
|
|
- * Implement's React render method to wrap the nested component.
|
33
|
|
- *
|
34
|
|
- * @returns {XML}
|
35
|
|
- */
|
36
|
|
- render(): React$Element<*> {
|
37
|
|
- return <WrapperComponent { ...this.props } />;
|
38
|
|
- }
|
39
|
|
- });
|
|
51
|
+ /**
|
|
52
|
+ * Implement's React render method to wrap the nested component.
|
|
53
|
+ *
|
|
54
|
+ * @returns {React$Element}
|
|
55
|
+ */
|
|
56
|
+ render(): React$Element<*> {
|
|
57
|
+ return <WrappedComponent { ...this.props } />;
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ return connect(_mapStateToProps)(AspectRatioAware);
|
40
|
62
|
}
|
41
|
63
|
|
42
|
64
|
/**
|
|
@@ -53,16 +75,3 @@ function _mapStateToProps(state) {
|
53
|
75
|
aspectRatio: state['features/base/aspect-ratio'].aspectRatio
|
54
|
76
|
};
|
55
|
77
|
}
|
56
|
|
-
|
57
|
|
-/**
|
58
|
|
- * Checks if given React component decorated in {@link AspectRatioAwareWrapper}
|
59
|
|
- * has currently the {@link ASPECT_RATIO_NARROW} set in the aspect ratio
|
60
|
|
- * property.
|
61
|
|
- *
|
62
|
|
- * @param {AspectRatioAwareWrapper} component - A
|
63
|
|
- * {@link AspectRatioAwareWrapper} which has <tt>aspectRation</tt> property.
|
64
|
|
- * @returns {boolean}
|
65
|
|
- */
|
66
|
|
-export function isNarrowAspectRatio(component: ReactClass<*>) {
|
67
|
|
- return component.props.aspectRatio === ASPECT_RATIO_NARROW;
|
68
|
|
-}
|