-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqr-code.ts
More file actions
33 lines (28 loc) · 1.05 KB
/
qr-code.ts
File metadata and controls
33 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import type { QrCodeCollector } from '@forgerock/davinci-client/types';
export default function (formEl: HTMLFormElement, collector: QrCodeCollector) {
if (collector.error) {
const errorEl = document.createElement('p');
errorEl.innerText = `QR Code error: ${collector.error}`;
formEl.appendChild(errorEl);
return;
}
const container = document.createElement('div');
const img = document.createElement('img');
img.src = collector.output.src;
img.alt = 'QR Code';
img.setAttribute('data-testid', 'qr-code-image');
container.appendChild(img);
if (collector.output.fallbackText) {
const fallback = document.createElement('p');
fallback.innerText = `Manual code: ${collector.output.fallbackText}`;
fallback.setAttribute('data-testid', 'qr-code-fallback');
container.appendChild(fallback);
}
formEl.appendChild(container);
}