/
onboarding.components.jsx
106 lines (88 loc) · 2.42 KB
/
onboarding.components.jsx
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
import React from 'react';
import Classnames from 'classnames';
import Tether from 'tether';
import LocalClient from '../stores/local-client.stores.jsx';
export class OnBoarding extends React.Component {
constructor(props) {
super(props);
this.state = {
reset: (new Date()).getTime(),
};
}
createTether() {
if (this.tether) {
this.tether.destroy();
}
const target = this.step ? document.getElementById(this.step.props.target) : undefined;
if (this.step && this.step.props.target && target) {
this.tether = new Tether({
target,
element: this.refs.onboarding,
attachment: this.step.props.elementAlign || 'middle left',
targetAttachment: this.step.props.targetAlign || 'middle right',
offset: this.step.props.offset || '-10px -50px',
});
}
else if (this.tether) {
this.setState({
reset: (new Date()).getTime(),
});
this.tether = undefined;
}
}
componentDidMount() {
this.createTether();
}
componentDidUpdate() {
this.createTether();
}
render() {
const step = this.step = _.find(this.props.children, (child) => {
return child.props.name === this.props.step;
});
const classes = Classnames({
onboarding: true,
'full-modal-container': step && (step.props.type === 'fullModal'),
'indicator': step && (step.props.type === 'indicator'),
'is-inverse': step && (step.props.inverseArrow),
'is-top': step && (step.props.arrowPos),
});
const styles = {
top: 0,
left: 0,
position: 'absolute',
transform: 'none',
};
if (this.step && this.step.props.width) {
styles.width = this.step.props.width;
}
return (
<div className={classes} ref="onboarding" key={this.state.reset} style={styles}>
{step}
</div>
);
}
}
export class OnBoardingStep extends React.Component {
componentWillMount() {
this.client = LocalClient.instance();
// function binding
this.endPrematurely = this.endPrematurely.bind(this);
}
endPrematurely() {
this.client.dispatchAction('/store-value', {uiOnboardstep: 'premature-end'});
this.client.dispatchAction('/change-tab-sidebar', {name: 'sliders'});
}
render() {
const close = this.props.type !== 'fullModal' && !this.props.noclose ? (
<div className="onboarding-step-close" onClick={this.endPrematurely}><img src="assets/images/close-icon.svg"></img></div>
)
: false;
return (
<div className="onboarding-step" id={this.props.name}>
{close}
{this.props.children}
</div>
);
}
}