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 44 import { onMount } from ' svelte'
55
66 let fw: Fireworks
7- let enabled = true
7+ let mounted = true
88 let options: FireworksOptions = {
99 opacity: 0.5
1010 }
2626
2727<main >
2828 <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' }
3431 </button >
3532 </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+ />
3839 {/if }
3940</main >
4041
Original file line number Diff line number Diff line change 11# @fireworks-js/svelte
22
33> 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 11<script lang =" ts" >
2- import { onMount , onDestroy } from ' svelte'
32 import { Fireworks } from ' fireworks-js'
43 import type { FireworksOptions } from ' fireworks-js'
54
98 export let style: string = ' '
109 export let options: FireworksOptions = {}
1110
12- let container: HTMLDivElement
1311 let fireworks: Fireworks
1412
1513 export function fireworksInstance() {
1614 return fireworks
1715 }
1816
19- onMount (() => {
17+ function setup( container : HTMLDivElement , options : FireworksOptions ) {
2018 fireworks = new Fireworks (container , options )
2119 if (autostart ) {
2220 fireworks .start ()
2321 }
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+ }
2931 </script >
3032
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 />
3339</div >
You can’t perform that action at this time.
0 commit comments