-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.js
187 lines (165 loc) · 4.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* eslint-disable react/no-unused-prop-types */
import { Component } from 'react';
import PropTypes from 'prop-types';
import { CHANNEL } from '@material-ui/core/styles/themeListener';
import { getMessage } from '@kuveytturk/boa-utils';
import { ComponentSize, DeviceSize } from '../enums';
import { shallowEqual } from '../helpers';
export default class ComponentBase extends Component {
static propTypes = {
/**
* Defines size of the component. The ComponentSize constant is exported from enums.
* @ignore
*/
componentSize: PropTypes.oneOf([
ComponentSize.LARGE,
ComponentSize.MEDIUM,
ComponentSize.SMALL,
ComponentSize.XSMALL,
]),
/**
* Defines application requirements such as localization, theme, platform.
*/
context: PropTypes.object,
/**
* If true, all component functionalities are disabled.
*/
disabled: PropTypes.bool,
/**
* All components must have an id prop.
*/
id: PropTypes.string,
/**
* @deprecated
* @ignore
* In the ComponentComposer, we change the visibility of the component with this prop.
*/
isVisible: PropTypes.bool,
/**
* As described in componentSize prop, if one of the components takes part in the new line
* on a card we are using this prop.
* @ignore
*/
newLine: PropTypes.bool,
/**
* The snapKey property is used to manage snapshots of the child components.
* @ignore
*/
snapKey: PropTypes.string,
/**
* In our SPA, we want to keep the state of each component when a page unmounts.
* And when the same page mounts again, the component mounts with the snapshot prop and
* it gets the previous state.
* @ignore
*/
snapshot: PropTypes.object,
/**
* All components must have a style prop.
*/
style: PropTypes.object,
/**
* The valueConstraint is used for validations on components like limit, required, etc.
*/
valueConstraint: PropTypes.object,
/**
* In the ComponentComposer, we change the visibility of the component with this prop.
*/
visible: PropTypes.bool,
};
static defaultProps = {
disabled: false,
componentSize: ComponentSize.LARGE,
newLine: false,
visible: true,
};
static contextTypes = {
[CHANNEL]: PropTypes.object,
};
constructor(props, context) {
super(props, context);
if (this.props.context && context && context[CHANNEL]) {
this.props.context.theme = context[CHANNEL].getState();
}
}
componentWillMount() {
if (this.props.snapshot) {
this.setSnapshot(this.props.snapshot);
}
}
componentDidMount() { }
componentWillReceiveProps(nextProps) {
if (nextProps.snapshot) {
this.setSnapshot(nextProps.snapshot);
}
}
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
// eslint-disable-next-line no-unused-vars
componentWillUpdate(nextProps, nextState) { }
// eslint-disable-next-line no-unused-vars
componentDidUpdate(prevProps, prevState) { }
componentWillUnmount() { }
/**
* @returns {this}
*/
getInstance() {
return this;
}
/**
*
* @param {string} groupName
* @param {string} propertyName
* @returns {string}
*/
getMessage(groupName, propertyName) {
return getMessage(groupName, propertyName, this.props.context.language).Description;
}
/**
*
* @param {string} groupName
* @param {string} propertyName
*/
getMessageCode(groupName, propertyName) {
return getMessage(groupName, propertyName, this.props.context.language).Code;
}
/**
*
* @param {string} childSnapKey
* @returns {string}
*/
getSnapKey(childSnapKey) {
return this.props.snapKey ? `${this.props.snapKey}_${childSnapKey}` : childSnapKey;
}
getSnapshot() {
return this.state;
}
setSnapshot(snapshot) {
this.setState({ ...snapshot });
}
/**
* @return {bool}
*/
isMobile() {
return this.props.context.deviceSize <= DeviceSize.SMALL;
}
/**
* @returns {bool}
*/
isMobileOrTablet() {
return this.props.context.deviceSize <= DeviceSize.MEDIUM;
}
/**
* @returns {bool}
*/
// eslint-disable-next-line class-methods-use-this
validateConstraint() {
return true;
}
/* eslint-disable */
render() {
/* istanbul ignore next */
return;
}
/* eslint-enable */
}