forked from canpolatoral/boa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.js
66 lines (55 loc) · 1.98 KB
/
container.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
import React, { Component } from 'react';
import { AppProvider, ComponentBase, setLocalization, getTheme } from '@kuveytturk/boa-base';
import { Localization, Language } from '@kuveytturk/boa-utils';
import { context } from '@kuveytturk/boa-test/utils';
import detectSize from './utils/detectSize';
import Messages from './messages';
export default class Container extends ComponentBase {
constructor(props) {
super(props);
this.onThemeChange = this.onThemeChange.bind(this);
this.onLanguageChange = this.onLanguageChange.bind(this);
this.onResize = this.onResize.bind(this);
context.language = Language.EN;
setLocalization({
url: 'http://boaonedev',
path: '/messaging/',
versionPath: 'MessagingVersions.json',
fileNameFormat: 'BOA.Messaging.{0}.json',
timeout: 3000,
languageId: context.language,
localMessages: Messages,
});
context.deviceSize = detectSize();
window.addEventListener('resize', this.onResize);
this.state = { context };
}
onResize() {
const deviceSize = detectSize();
this.setState({ context: Object.assign({}, this.state.context, { deviceSize }) });
}
onThemeChange(themeName) {
const theme = getTheme({ themeName: themeName });
if (theme) {
this.setState({ context: Object.assign({}, this.state.context, { theme }) });
}
}
onLanguageChange(value) {
const localization = { isRightToLeft: value === 5 ? true : false };
Localization.staticConstructor(value);
this.setState({
context: Object.assign({}, this.state.context, {
language: value,
localization: localization,
messagingContext: {},
}),
});
}
render() {
const { story, context } = this.props;
context.props = { context: this.state.context };
context.props.onThemeChange = this.onThemeChange;
context.props.onLanguageChange = this.onLanguageChange;
return <AppProvider theme={this.state.context.theme}>{story(context)}</AppProvider>;
}
}