<style>
.demo-qr-row { display: flex; flex-wrap: wrap; gap: var(--ray-space-6); align-items: center; }
.demo-qr-share { display: grid; grid-template-columns: auto minmax(0, 18rem); justify-content: start; gap: var(--ray-space-5); align-items: center; }
.demo-qr-share p { margin: 0; font-size: var(--ray-font-size-sm); color: var(--ray-muted-foreground); }
.demo-qr-secret { font-family: var(--ray-font-mono); font-size: var(--ray-font-size-sm); letter-spacing: 0.08em; overflow-wrap: anywhere; }
.demo-qr-sizes { display: flex; flex-wrap: wrap; gap: var(--ray-space-4); align-items: flex-end; }
@media (max-width: 40em) { .demo-qr-share { grid-template-columns: 1fr; } }
</style>
<div class="demo-caption">Open on your phone: type a link, the code follows</div>
<div class="demo-qr-share">
<ray-qr id="demo-qr-link" size="lg" value="https://elements.raylang.dev" label="Scan to open the link on your phone"></ray-qr>
<div class="demo-stack">
<ray-input id="demo-qr-input" label="Link" value="https://elements.raylang.dev"></ray-input>
<p id="demo-qr-info"></p>
<div class="demo-actions">
<ray-button size="xs" variant="default" id="demo-qr-png">Download PNG</ray-button>
<ray-button size="xs" variant="default" id="demo-qr-svg">Download SVG</ray-button>
</div>
</div>
</div>
<div class="demo-caption">Two-step sign-in: the code, and the key as text for who cannot scan</div>
<div class="demo-qr-share">
<ray-qr size="md" quiet-zone="2" value="otpauth://totp/rayvault:ana@example.com?secret=JBSWY3DPEHPK3PXP&issuer=rayvault" label="Scan with your authenticator app"></ray-qr>
<div class="demo-stack">
<p>Scan it with your authenticator app, or type this key:</p>
<span class="demo-qr-secret">JBSW Y3DP EHPK 3PXP</span>
</div>
</div>
<div class="demo-caption">A logo at the middle (the error correction goes up to H), colors, sizes</div>
<div class="demo-qr-sizes">
<ray-qr size="lg" value="https://github.com/ray-language/ray-elements" label="ray-elements on GitHub">
<img alt="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='2' y='2' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3Crect x='13' y='2' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='2' y='13' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='13' y='13' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3C/svg%3E">
</ray-qr>
<ray-qr size="md" color="indigo" value="https://elements.raylang.dev/components/qr.html" label="This page"></ray-qr>
<ray-qr size="sm" value="WIFI:T:WPA;S:Studio;P:correct horse battery staple;;" label="Join the studio's Wi-Fi"></ray-qr>
<ray-qr size="xs" value="https://raylang.dev" label="raylang.dev"></ray-qr>
</div>
<script type="module">
const qr = document.getElementById("demo-qr-link");
const input = document.getElementById("demo-qr-input");
const info = document.getElementById("demo-qr-info");
const describe = () => {
const m = qr.matrix;
info.textContent = m ? `Version ${m.version} (${m.size} Ă— ${m.size} modules), error correction ${m.ecc}.` : "Type something to encode.";
};
input.addEventListener("input", async () => {
qr.value = input.value;
await new Promise(requestAnimationFrame);
describe();
});
qr.addEventListener("ray-error", () => (info.textContent = "Too long for a QR code."));
customElements.whenDefined("ray-qr").then(() => requestAnimationFrame(describe));
const save = (blob, name) => {
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = name;
a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
};
document.getElementById("demo-qr-png").addEventListener("click", async () => save(await qr.toPNG({ size: 512 }), "link.png"));
document.getElementById("demo-qr-svg").addEventListener("click", () => save(new Blob([qr.toSVG({ size: 512 })], { type: "image/svg+xml" }), "link.svg"));
</script>
import { RayQr, RayInput, RayButton } from "@raylang/react";
export function QrExample() {
return (
<>
<div className="demo-caption">Open on your phone: type a link, the code follows</div>
<div className="demo-qr-share">
<RayQr id="demo-qr-link" size="lg" value="https://elements.raylang.dev" label="Scan to open the link on your phone" />
<div className="demo-stack">
<RayInput id="demo-qr-input" label="Link" value="https://elements.raylang.dev" />
<p id="demo-qr-info" />
<div className="demo-actions">
<RayButton size="xs" variant="default" id="demo-qr-png">Download PNG</RayButton>
<RayButton size="xs" variant="default" id="demo-qr-svg">Download SVG</RayButton>
</div>
</div>
</div>
<div className="demo-caption">Two-step sign-in: the code, and the key as text for who cannot scan</div>
<div className="demo-qr-share">
<RayQr size="md" quietZone={2} value="otpauth://totp/rayvault:ana@example.com?secret=JBSWY3DPEHPK3PXP&issuer=rayvault" label="Scan with your authenticator app" />
<div className="demo-stack">
<p>Scan it with your authenticator app, or type this key:</p>
<span className="demo-qr-secret">JBSW Y3DP EHPK 3PXP</span>
</div>
</div>
<div className="demo-caption">A logo at the middle (the error correction goes up to H), colors, sizes</div>
<div className="demo-qr-sizes">
<RayQr size="lg" value="https://github.com/ray-language/ray-elements" label="ray-elements on GitHub">
<img alt="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='2' y='2' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3Crect x='13' y='2' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='2' y='13' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='13' y='13' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3C/svg%3E" />
</RayQr>
<RayQr size="md" color="indigo" value="https://elements.raylang.dev/components/qr.html" label="This page" />
<RayQr size="sm" value="WIFI:T:WPA;S:Studio;P:correct horse battery staple;;" label="Join the studio's Wi-Fi" />
<RayQr size="xs" value="https://raylang.dev" label="raylang.dev" />
</div>
</>
);
}
<template>
<div class="demo-caption">Open on your phone: type a link, the code follows</div>
<div class="demo-qr-share">
<RayQr id="demo-qr-link" size="lg" value="https://elements.raylang.dev" label="Scan to open the link on your phone" />
<div class="demo-stack">
<RayInput id="demo-qr-input" label="Link" value="https://elements.raylang.dev" />
<p id="demo-qr-info"></p>
<div class="demo-actions">
<RayButton size="xs" variant="default" id="demo-qr-png">Download PNG</RayButton>
<RayButton size="xs" variant="default" id="demo-qr-svg">Download SVG</RayButton>
</div>
</div>
</div>
<div class="demo-caption">Two-step sign-in: the code, and the key as text for who cannot scan</div>
<div class="demo-qr-share">
<RayQr size="md" :quiet-zone="2" value="otpauth://totp/rayvault:ana@example.com?secret=JBSWY3DPEHPK3PXP&issuer=rayvault" label="Scan with your authenticator app" />
<div class="demo-stack">
<p>Scan it with your authenticator app, or type this key:</p>
<span class="demo-qr-secret">JBSW Y3DP EHPK 3PXP</span>
</div>
</div>
<div class="demo-caption">A logo at the middle (the error correction goes up to H), colors, sizes</div>
<div class="demo-qr-sizes">
<RayQr size="lg" value="https://github.com/ray-language/ray-elements" label="ray-elements on GitHub">
<img alt="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='2' y='2' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3Crect x='13' y='2' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='2' y='13' width='9' height='9' rx='2' fill='%2374c0fc'/%3E%3Crect x='13' y='13' width='9' height='9' rx='2' fill='%231c7ed6'/%3E%3C/svg%3E">
</RayQr>
<RayQr size="md" color="indigo" value="https://elements.raylang.dev/components/qr.html" label="This page" />
<RayQr size="sm" value="WIFI:T:WPA;S:Studio;P:correct horse battery staple;;" label="Join the studio's Wi-Fi" />
<RayQr size="xs" value="https://raylang.dev" label="raylang.dev" />
</div>
</template>