Skip to content

Commit 9f1c6da

Browse files
committed
chore: Clean up docs
1 parent dbd3dc0 commit 9f1c6da

File tree

8 files changed

+142
-10
lines changed

8 files changed

+142
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Run lightweight, heavily customizable particle simulations in your Nuxt project
99

1010
- [📖  Documentation](https://nuxt-particles.joeypereira.dev)
1111
- [ Release Notes](/CHANGELOG.md)
12-
- [🏀 Online playground](https://stackblitz.com/github/your-org/nuxt-particles?file=playground%2Fapp.vue)
12+
- [🏀 Online playground](https://stackblitz.com/github/Joepocalyptic/nuxt-particles?file=playground%2Fapp.vue)
1313

1414
## Features
1515

docs/content/1.getting-started/1.setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ export default defineNuxtConfig({
5151
Learn more about the available options in the [Configuration](/getting-started/configuration) section.
5252

5353
::alert{type="success"}
54-
✨ You're all set! Start using the [<NuxtParticles>](/) component in your application.
54+
✨ You're all set! Start using the [<NuxtParticles>](/components/nuxt-particles) component in your application.
5555
::
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
icon: ph:star-duotone
1+
title: Getting Started
2+
icon: material-symbols:bolt-rounded
23
navigation.redirect: /getting-started/setup
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# `<NuxtParticles>`
2+
3+
The `<NuxtParticles>` component renders a [tsParticles](https://particles.js.org) instance inside of a `<div>` element
4+
with the chosen `id`.
5+
6+
## Example
7+
8+
```vue
9+
10+
<template>
11+
<NuxtParticles
12+
id="tsparticles"
13+
:options="options"
14+
@load="onLoad"
15+
>
16+
17+
</NuxtParticles>
18+
19+
<!-- or -->
20+
21+
<NuxtParticles
22+
id="tsparticles2"
23+
url="/path/to/particle-options.json"
24+
@load="onLoad"
25+
>
26+
27+
</NuxtParticles>
28+
</template>
29+
30+
<script setup lang="ts">
31+
import type { Container } from 'tsparticles-engine'
32+
33+
// See tsParticles documentation for all available options
34+
const options = {
35+
fullScreen: {
36+
enable: true,
37+
zIndex: -1
38+
},
39+
background: {
40+
color: {
41+
value: '#fff'
42+
}
43+
},
44+
particles: {
45+
color: {
46+
value: "#000"
47+
},
48+
links: {
49+
color: "#000",
50+
enable: true
51+
},
52+
move: {
53+
enable: true
54+
},
55+
number: {
56+
value: 100
57+
}
58+
}
59+
}
60+
61+
const onLoad = (container: Container) => {
62+
// Do something with the container
63+
container.pause()
64+
setTimeout(() => container.play(), 2000)
65+
}
66+
</script>
67+
```
68+
69+
## Props
70+
71+
### `id`
72+
73+
- Type: `string`
74+
- Required: `true`
75+
76+
Used by tsParticles to differentiate between multiple instances on the same page. Must be unique.
77+
78+
### `options`
79+
80+
- Type: `IOptions` (see [tsParticles docs](https://particles.js.org/docs/interfaces/tsParticles_Engine.Options_Interfaces_IOptions.IOptions.html))
81+
- Required: `false`
82+
83+
The options object to pass to tsParticles. May be used in place of the `url` prop to directly pass a JSON object instead
84+
of loading a configuration file.
85+
86+
### `url`
87+
88+
- Type: `string`
89+
- Required: `false`
90+
91+
The URL of the JSON file containing the particle configuration. May be used in place of the `options` prop to
92+
load a configuration file instead of directly passing a JSON object.
93+
94+
## Events
95+
96+
### `load`
97+
98+
- Type: `(container: Container) => void` (see [tsParticles docs](https://particles.js.org/docs/classes/tsParticles_Engine.Core_Container.Container.html))
99+
100+
Called when tsParticles has successfully loaded its canvas. Provides a `container` object that can be used to interact
101+
with the instance. Some useful methods include:
102+
103+
```ts
104+
// Pause the animation
105+
container.pause()
106+
// Play the animation
107+
container.play()
108+
// Refresh the instance
109+
container.refresh()
110+
// Destroy the instance
111+
container.destroy()
112+
```
113+
114+
## Usage notes
115+
116+
This component automatically lazy-loads the tsParticles library if the `particles.lazy` option is set to `true` in
117+
your Nuxt configuration. Otherwise, the library is loaded immediately before your entire application is rendered.
118+
119+
Using multiple instances of this component on the same page is safe as long as each instance has a unique `id`. This
120+
may have performance implications, however, as each instance will be rendering its own canvas. Use one instance with
121+
multiple particle emitters whenever possible.
122+
123+
If you are using a custom bundle, you must [manually initialize the library](/getting-started/configuration#custom-mode)
124+
in your application.

docs/content/2.components/_dir.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: Components
2+
icon: material-symbols:grid-view-rounded
3+
navigation.redirect: /components/nuxt-particles

playground/app.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
</div>
1818
</template>
1919

20-
<script setup>
21-
import { ref } from '#imports'
20+
<script setup lang="ts">
21+
import { ref, useRuntimeConfig } from '#imports'
22+
import {loadFull} from 'tsparticles'
23+
import {tsParticles} from 'tsparticles-engine'
24+
25+
const { mode } = useRuntimeConfig().public.particles
2226
2327
const show = ref(false)
2428
29+
if(process.client && mode === 'custom') {
30+
await loadFull(tsParticles)
31+
}
32+
2533
const options = {
2634
fullScreen: {
2735
enable: true,

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default defineNuxtModule<ModuleOptions>({
2222
setup (options, nuxt) {
2323
const resolver = createResolver(import.meta.url)
2424

25-
if(!options.lazy) {
25+
if(!options.lazy && options.mode !== 'custom') {
2626
addPlugin(resolver.resolve('./runtime/plugins/particle-loader.client'))
2727
}
2828

src/runtime/plugins/particle-loader.client.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ export default defineNuxtPlugin(async (nuxtApp) => {
88
const runtimeConfig = useRuntimeConfig()
99
const { mode } = runtimeConfig.public.particles
1010

11-
if (mode === 'custom') {
12-
return
13-
}
14-
1511
await loadParticles(tsParticles, mode)
1612
})

0 commit comments

Comments
 (0)