File tree 3 files changed +57
-3
lines changed
3 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -93,9 +93,9 @@ We are working continuously on adding support for more and more platforms. If yo
93
93
### Framework support
94
94
The library can be easily used with several other frameworks, I have been adding examples for a few of them and would continue to add more.
95
95
96
- |<img src =" https://scanapp.org/assets/github_assets/html5.png " width =" 30px " />| <img src =" https://scanapp.org/assets/github_assets/vuejs.png " width =" 30px " />|<img src =" https://scanapp.org/assets/github_assets/electron.png " width =" 30px " /> | <img src =" https://scanapp.org/assets/github_assets/react.svg " width =" 30px " /> | <img src =" https://seeklogo.com/images/L/lit-logo-6B43868CDC-seeklogo.com.png " width =" 30px " />
97
- | -------- | -------- | -------- | -------- | -------- |
98
- | [ Html5] ( ./examples/html5 ) | [ VueJs] ( ./examples/vuejs ) | [ ElectronJs] ( ./examples/electron ) | [ React] ( https://github.com/scanapp-org/html5-qrcode-react ) | [ Lit] ( ./examples/lit )
96
+ |<img src =" https://scanapp.org/assets/github_assets/html5.png " width =" 30px " />| <img src =" https://scanapp.org/assets/github_assets/vuejs.png " width =" 30px " />|<img src =" https://scanapp.org/assets/github_assets/electron.png " width =" 30px " /> | <img src =" https://scanapp.org/assets/github_assets/react.svg " width =" 30px " /> | <img src =" https://seeklogo.com/images/L/lit-logo-6B43868CDC-seeklogo.com.png " width =" 30px " /> | < img src = " ./examples/svelte/svelte.png " width = " 30px " />
97
+ | -------- | -------- | -------- | -------- | -------- | -------- |
98
+ | [ Html5] ( ./examples/html5 ) | [ VueJs] ( ./examples/vuejs ) | [ ElectronJs] ( ./examples/electron ) | [ React] ( https://github.com/scanapp-org/html5-qrcode-react ) | [ Lit] ( ./examples/lit ) | [ Svelte ] ( ./examples/svelte )
99
99
100
100
### Supported Code formats
101
101
Code scanning is dependent on [ Zxing-js] ( https://github.com/zxing-js/library ) library. We will be working on top of it to add support for more types of code scanning. If you feel a certain type of code would be helpful to have, please file a feature request.
Original file line number Diff line number Diff line change
1
+ # html5-qrcode with Svelte/SvelteKit
2
+
3
+ ## Creating a ` svelte ` component for ` html5-qrcode `
4
+
5
+ ### Install the library in your project
6
+
7
+ ``` bash
8
+ npm i html5-qrcode
9
+ ```
10
+
11
+ ### Create a ` Scanner.svelte ` component
12
+
13
+ ``` svelte
14
+ // Scanner.svelte
15
+ <script lang="ts">
16
+ import { Html5QrcodeScanner } from 'html5-qrcode';
17
+ import { onMount } from 'svelte';
18
+
19
+ const { onScanSuccess, onScanFail } = $props();
20
+
21
+ // `onMount` indicates to the framework to render this component on the client-side.
22
+ onMount(async () => {
23
+ const scanner = new Html5QrcodeScanner('reader', { fps: 10, qrbox: 350 }, false);
24
+ scanner.render(onScanSuccess, onScanFail);
25
+ })
26
+ </script>
27
+
28
+ <div id="reader"></div>
29
+ ```
30
+
31
+ ### Use the component
32
+
33
+ ``` svelte
34
+ <script lang="ts">
35
+ // Import the Scanner component
36
+ import Scanner from './Scanner.svelte';
37
+
38
+ // Declare some local state
39
+ const data = $state(undefined);
40
+
41
+ // Define the callbacks
42
+ const onScanSuccess = (decodedText, decodedResult) => {
43
+ console.log(`Scan result: ${decodedText}`, decodedResult);
44
+ data = decodedText;
45
+ }
46
+ const onScanFail = (error) => {
47
+ console.warn(`Code scan error = ${error}`);
48
+ }
49
+ </script>
50
+
51
+ <section>
52
+ <Scanner {onScanSuccess} {onScanFail} />
53
+ </section>
54
+ ```
You can’t perform that action at this time.
0 commit comments