File tree Expand file tree Collapse file tree 3 files changed +57
-18
lines changed Expand file tree Collapse file tree 3 files changed +57
-18
lines changed Original file line number Diff line number Diff line change 4
4
import { onMount } from ' svelte'
5
5
6
6
let fw: Fireworks
7
- let enabled = true
7
+ let mounted = true
8
8
let options: FireworksOptions = {
9
9
opacity: 0.5
10
10
}
26
26
27
27
<main >
28
28
<div class =" buttons" >
29
- <button on:click ={() => (enabled = ! enabled )}>
30
- {enabled ? ' Enabled' : ' Disabled' }
31
- </button >
32
- <button on:click ={() => toggleFireworks ()}>
33
- Toggle
29
+ <button on:click ={() => (mounted = ! mounted )}>
30
+ {mounted ? ' Mounted' : ' Unmounted' }
34
31
</button >
35
32
</div >
36
- {#if enabled }
37
- <Fireworks bind:this ={fw } autostart ={false } {options } class =" fireworks" />
33
+ {#if mounted }
34
+ <Fireworks
35
+ bind:this ={fw }
36
+ {options }
37
+ class =" fireworks"
38
+ />
38
39
{/if }
39
40
</main >
40
41
Original file line number Diff line number Diff line change 1
1
# @fireworks-js/svelte
2
2
3
3
> https://github.com/crashmax-dev/fireworks-js
4
+
5
+ ## Installation
6
+
7
+ ``` sh
8
+ npm install @fireworks-js/svelte
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ #### [ ` fireworks-js ` ] ( https://github.com/crashmax-dev/fireworks-js/tree/master/examples/with-svelte )
14
+
15
+ ``` svelte
16
+ <script lang="ts">
17
+ import { Fireworks } from '@fireworks-js/svelte'
18
+ import type { FireworksOptions } from '@fireworks-js/svelte'
19
+
20
+ let fw: Fireworks
21
+ let options: FireworksOptions = {
22
+ opacity: 0.5
23
+ }
24
+
25
+ function toggleFireworks() {
26
+ const fireworks = fw.fireworksInstance()
27
+ if (fireworks.isRunning) {
28
+ fireworks.waitStop()
29
+ } else {
30
+ fireworks.start()
31
+ }
32
+ }
33
+ </script>
34
+ <Fireworks bind:this={fw} autostart={false} {options} class="fireworks" />
35
+ ```
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
- import { onMount , onDestroy } from ' svelte'
3
2
import { Fireworks } from ' fireworks-js'
4
3
import type { FireworksOptions } from ' fireworks-js'
5
4
9
8
export let style: string = ' '
10
9
export let options: FireworksOptions = {}
11
10
12
- let container: HTMLDivElement
13
11
let fireworks: Fireworks
14
12
15
13
export function fireworksInstance() {
16
14
return fireworks
17
15
}
18
16
19
- onMount (() => {
17
+ function setup( container : HTMLDivElement , options : FireworksOptions ) {
20
18
fireworks = new Fireworks (container , options )
21
19
if (autostart ) {
22
20
fireworks .start ()
23
21
}
24
- })
25
-
26
- onDestroy (() => {
27
- fireworks ?.stop ()
28
- })
22
+ return {
23
+ update(options : FireworksOptions ) {
24
+ fireworks .updateOptions (options )
25
+ },
26
+ destroy() {
27
+ fireworks .stop ()
28
+ }
29
+ }
30
+ }
29
31
</script >
30
32
31
- <div bind:this ={container } class ={className } {style }>
32
- <slot ></slot >
33
+ <div
34
+ use:setup ={options }
35
+ class ={className }
36
+ {style }
37
+ >
38
+ <slot />
33
39
</div >
You can’t perform that action at this time.
0 commit comments