Skip to content

Commit fb0cccb

Browse files
committed
build: working on particles component
1 parent 657a4d3 commit fb0cccb

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

components/lit/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"typescript"
1818
],
1919
"dependencies": {
20-
"lit": "^2.5.0"
20+
"lit": "^2.5.0",
21+
"tsparticles-engine": "^2.9.3"
2122
},
2223
"devDependencies": {
2324
"@web/dev-server": "^0.1.32",
@@ -31,4 +32,4 @@
3132
"files": [
3233
"/lib"
3334
]
34-
}
35+
}

components/lit/src/lit-tsparticles.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitElement, html } from "lit";
22
import { property, customElement } from "lit/decorators.js";
3+
import { Container, Engine, tsParticles } from "tsparticles-engine";
34

45
/**
56
* The LitParticles element.
@@ -14,6 +15,44 @@ export class LitParticles extends LitElement {
1415
@property({ type: String })
1516
id = "tsparticles";
1617

18+
/**
19+
* The options
20+
*/
21+
@property({ type: Object })
22+
options = {};
23+
24+
container?: Container;
25+
26+
@property({ type: Function })
27+
particlesInit?: (engine: Engine) => Promise<void>;
28+
29+
@property({ type: Function })
30+
particlesLoaded?: (container?: Container) => Promise<void>;
31+
32+
constructor() {
33+
super();
34+
35+
this.particlesInit?.(tsParticles);
36+
}
37+
38+
connectedCallback() {
39+
super.connectedCallback();
40+
41+
tsParticles.load(this.id, this.options).then(async (container) => {
42+
this.container = container;
43+
44+
await this.particlesLoaded?.(container);
45+
});
46+
}
47+
48+
disconnectedCallback(): void {
49+
if (this.container) {
50+
this.container.destroy();
51+
}
52+
53+
super.disconnectedCallback();
54+
}
55+
1756
render() {
1857
return html`<div id=${this.id}></div>`;
1958
}

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)