-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathParticles.js
71 lines (71 loc) · 2.81 KB
/
Particles.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
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const default_1 = require("./default");
const tsparticles_1 = require("tsparticles");
class Particles extends React.Component {
constructor() {
super(...arguments);
this.state = {
style: {
position: "absolute",
display: "block",
top: "0",
left: "0",
height: "100%",
width: "100%"
}
};
}
setStateAsync(state) {
return new Promise(resolve => {
this.setState(state, resolve);
});
}
componentDidMount() {
return __awaiter(this, void 0, void 0, function* () {
let id;
if (this.props.id) {
id = "tsparticles-" + this.props.id;
}
else {
console.error("[ERROR] No 'id' prop found in <Particles/> component.");
}
let jsonConfigFile, particlesConfig;
if (this.props.config) {
try {
jsonConfigFile = yield fetch(this.props.config);
particlesConfig = yield jsonConfigFile.json();
}
catch (e) {
console.error("[ERROR] Couldn't load assigned config file; loading default.");
particlesConfig = default_1.default;
}
yield this.setStateAsync({ configuration: particlesConfig });
}
else {
particlesConfig = default_1.default;
}
if (this.props.style) {
yield this.setStateAsync({
style: Object.assign(Object.assign({}, this.state.style), this.props.style)
});
}
tsparticles_1.tsParticles.load(id, particlesConfig);
});
}
render() {
return (React.createElement("div", { id: "tsparticles-" + this.props.id, style: this.state.style, className: this.props.className ? this.props.className : "" }));
}
}
exports.default = Particles;
//# sourceMappingURL=Particles.js.map