Barcode Scanner
Generated from public Vue/TypeScript exports by
pnpm docs:generate. Edit source comments and stories to update this reference. Types describe the declared API; browser/device constraints are covered in the guides. This catalog reflects source commitfc6bfb108634735f1657e533206c3f8702ad357d; match your installed package and typed manifest before using an export. Source review does not establish registry-release availability.
BarcodeScanner
import { BarcodeScanner } from '@gxp-dev/app-ui'
Props
| Name | Type | Required / default | Description |
|---|---|---|---|
instructions | string | undefined | "Position the code in front of the camera" | — |
backText | string | undefined | "Back" | — |
scanButtonText | string | undefined | "Start Scanning" | — |
autoStart | boolean | undefined | false | — |
facingMode | "environment" | "user" | undefined | "environment" | — |
formats | string[] | undefined | — | Restrict decoding to these ZXing BarcodeFormat names (e.g. ['QR_CODE', 'CODE_128']). Omit to decode all supported formats. |
mirror | boolean | undefined | false | Mirror the preview horizontally (typical for the user-facing camera). |
stream | MediaStream | null | undefined | — | Decode a caller-provided MediaStream instead of acquiring a camera — lets the scanner share one camera with useMedia. |
Events
| Name | Type | Required / default | Description |
|---|---|---|---|
error | [error: Error] | — | — |
scan | [code: string] | — | — |
scanner-opened | [] | — | — |
scanner-closed | [] | — | — |
Slots
| Name | Type | Required / default | Description |
|---|---|---|---|
overlay | {} | — | — |
default | {} | — | — |
Exposed methods and values
| Name | Type | Required / default | Description |
|---|---|---|---|
startScanning | () => Promise<void> | — | — |
stopScanning | () => void | — | — |
Examples
These are authored Storybook excerpts, not complete standalone modules. Relative imports refer to the story file; in an app import public components from @gxp-dev/app-ui. Default meta arguments are applied before each story.
Default
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import BarcodeScanner from './BarcodeScanner.vue'
{
args: {},
render: (args) => ({
components: { BarcodeScanner },
setup() {
const handleScan = (code: string) => {
alert(`Scanned: ${code}`)
}
const handleError = (error: Error) => {
console.error('Scanner error:', error)
}
return { args, handleScan, handleError }
},
template: `
<BarcodeScanner
v-bind="args"
@scan="handleScan"
@error="handleError"
/>
`,
}),
}
CustomText
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import BarcodeScanner from './BarcodeScanner.vue'
{
args: {
instructions: 'Please align the barcode within the frame',
backText: 'Cancel',
scanButtonText: 'Scan Barcode',
},
render: (args) => ({
components: { BarcodeScanner },
setup() {
const handleScan = (code: string) => {
alert(`Scanned: ${code}`)
}
const handleError = (error: Error) => {
console.error('Scanner error:', error)
}
return { args, handleScan, handleError }
},
template: `
<BarcodeScanner
v-bind="args"
@scan="handleScan"
@error="handleError"
/>
`,
}),
}
WithSlot
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import BarcodeScanner from './BarcodeScanner.vue'
{
render: (args) => ({
components: { BarcodeScanner },
setup() {
const handleScan = (code: string) => {
alert(`Scanned: ${code}`)
}
const handleError = (error: Error) => {
console.error('Scanner error:', error)
}
return { args, handleScan, handleError }
},
template: `
<BarcodeScanner
v-bind="args"
@scan="handleScan"
@error="handleError"
>
<div class="flex flex-col items-center gap-2 rounded-lg border-2 border-dashed border-primary p-8">
<svg
xmlns="http://www.w3.org/2000/svg"
width="48"
height="48"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="text-primary"
>
<path d="M3 7V5a2 2 0 0 1 2-2h2"/>
<path d="M17 3h2a2 2 0 0 1 2 2v2"/>
<path d="M21 17v2a2 2 0 0 1-2 2h-2"/>
<path d="M7 21H5a2 2 0 0 1-2-2v-2"/>
<path d="M8 7v10"/>
<path d="M12 7v10"/>
<path d="M17 7v10"/>
</svg>
<p class="text-sm font-medium">Click to scan barcode</p>
<p class="text-xs text-muted-foreground">Custom trigger with icon</p>
</div>
</BarcodeScanner>
`,
}),
}