Add a QR code page at /qr for any page on the site
Pick "Main navigation" or a kind of record (events, organizations, teams, awards, people), then the page or record, and for a main page optionally one of its #sections. The code, a copy-link button, and PNG (1024px) and SVG downloads follow. An "NGU dove in the centre" option puts the dove on a white badge over the code and raises error correction to H so it still scans. Codes always point at SITE_ORIGIN (https://nextgenerationofunity.org, in src/lib/site.ts), so one made on localhost works on a poster. Main pages come from navConfig.ts and record URLs from hrefs.ts, the same sources the site links with. GET /api/directory lists every published record with a page, as id, name and (for organizations) kind, each filtered by the same rule as that record's own page: a team also needs its organization published. /api/people only answers for ids it's given, so there was no public list to read. The `qrcode` package does the encoding; QrCode.tsx draws the modules as one SVG path, so the preview and both downloads are one picture. The page is lazy-loaded so the encoder isn't in the main bundle. The page is unlisted: not in navConfig, so not in the header or footer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8c26ec4906
commit
97c1827ca9
11 changed files with 892 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { BrowserRouter, Routes, Route, Outlet, Navigate } from "react-router-dom";
|
||||
import { lazy, Suspense } from "react";
|
||||
/*Components*/
|
||||
import Layout from "./components/Layout.tsx";
|
||||
|
||||
|
|
@ -39,6 +40,9 @@ import Privacy from "./pages/Privacy.tsx";
|
|||
import Terms from "./pages/Terms.tsx";
|
||||
import NotFound from "./pages/NotFound.tsx";
|
||||
|
||||
// Loaded on demand: it brings the QR encoder, which no other page needs.
|
||||
const QrCodes = lazy(() => import("./pages/QrCodes.tsx"));
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
|
|
@ -60,6 +64,7 @@ export default function App() {
|
|||
<Route path="resources" element={<Resources />} />
|
||||
<Route path="history" element={<History />} />
|
||||
<Route path="feedback" element={<Feedback />} />
|
||||
<Route path="qr" element={<Suspense fallback={null}><QrCodes /></Suspense>} />
|
||||
<Route path="give" element={<Giving />} />
|
||||
<Route path="privacy" element={<Privacy />} />
|
||||
<Route path="terms" element={<Terms />} />
|
||||
|
|
|
|||
94
src/components/QrCode.tsx
Normal file
94
src/components/QrCode.tsx
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
QR CODE
|
||||
|
||||
A QR code as an <svg>, sized by its container. With `dove`, the
|
||||
NGU dove sits on a white badge over the centre; the code switches
|
||||
to high error correction so the modules under the badge are
|
||||
recovered when it's scanned (see lib/qr.ts). The badge covers
|
||||
under 6% of the code, well inside what 'H' repairs, and never
|
||||
reaches the three corner finder patterns.
|
||||
|
||||
Everything is drawn in the SVG itself — no CSS, no external
|
||||
references — so the element serialises to a file that looks the
|
||||
same outside the page. `ref` reaches the <svg> for exactly that.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useMemo, type Ref } from 'react'
|
||||
|
||||
import DoveMark from './DoveMark.tsx'
|
||||
import { qrMatrix, qrPath } from '../lib/qr.ts'
|
||||
|
||||
/* The spec's minimum quiet zone, in modules. Less and some
|
||||
scanners can't find the edge of the code. */
|
||||
const MARGIN = 4
|
||||
|
||||
/* Dark enough to scan as black; the site's deep teal. */
|
||||
const INK = '#04262e'
|
||||
const TEAL = '#138ba0'
|
||||
|
||||
/* Badge side as a share of the code's width. */
|
||||
const BADGE = 0.24
|
||||
|
||||
/* DoveMark's own viewBox is 72.87 × 48.57. */
|
||||
const DOVE_ASPECT = 72.867699 / 48.568241
|
||||
|
||||
export default function QrCode({
|
||||
value,
|
||||
dove = false,
|
||||
label,
|
||||
ref,
|
||||
className,
|
||||
}: {
|
||||
value: string
|
||||
dove?: boolean
|
||||
/** Accessible name for the image, e.g. "QR code for /retreats". */
|
||||
label: string
|
||||
ref?: Ref<SVGSVGElement>
|
||||
className?: string
|
||||
}) {
|
||||
const matrix = useMemo(() => qrMatrix(value, dove ? 'H' : 'M'), [value, dove])
|
||||
const path = useMemo(() => qrPath(matrix, MARGIN), [matrix])
|
||||
|
||||
const total = matrix.size + MARGIN * 2
|
||||
const badge = matrix.size * BADGE
|
||||
const badgeAt = (total - badge) / 2
|
||||
const doveWidth = badge * 0.78
|
||||
const doveHeight = doveWidth / DOVE_ASPECT
|
||||
|
||||
return (
|
||||
<svg
|
||||
ref={ref}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox={`0 0 ${total} ${total}`}
|
||||
role="img"
|
||||
aria-label={label}
|
||||
className={className}
|
||||
shapeRendering="crispEdges"
|
||||
>
|
||||
<rect width={total} height={total} fill="#ffffff" />
|
||||
<path d={path} fill={INK} />
|
||||
|
||||
{dove && (
|
||||
<g shapeRendering="auto">
|
||||
<rect
|
||||
x={badgeAt}
|
||||
y={badgeAt}
|
||||
width={badge}
|
||||
height={badge}
|
||||
rx={badge * 0.22}
|
||||
fill="#ffffff"
|
||||
stroke={INK}
|
||||
strokeWidth={0.35}
|
||||
/>
|
||||
<DoveMark
|
||||
x={(total - doveWidth) / 2}
|
||||
y={(total - doveHeight) / 2}
|
||||
width={doveWidth}
|
||||
height={doveHeight}
|
||||
style={{ color: TEAL }}
|
||||
/>
|
||||
</g>
|
||||
)}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
48
src/lib/qr.ts
Normal file
48
src/lib/qr.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
QR CODES
|
||||
|
||||
The encoding comes from the `qrcode` package: which modules are
|
||||
dark, at which error-correction level. Drawing is QrCode.tsx's
|
||||
job, so the on-screen code, the SVG download and the PNG download
|
||||
are one picture rather than three renderers that could disagree.
|
||||
|
||||
Error correction is the share of the code that can be damaged and
|
||||
still scan. A logo over the middle is damage, so a code carrying
|
||||
the dove uses 'H' (about 30% recoverable); a plain one uses 'M',
|
||||
which keeps it less dense and easier to scan from a distance.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { create } from 'qrcode'
|
||||
|
||||
export type QrLevel = 'L' | 'M' | 'Q' | 'H'
|
||||
|
||||
export type QrMatrix = {
|
||||
/** Modules per side, not counting the quiet zone. */
|
||||
size: number
|
||||
dark: (row: number, col: number) => boolean
|
||||
}
|
||||
|
||||
export function qrMatrix(text: string, level: QrLevel): QrMatrix {
|
||||
const { modules } = create(text, { errorCorrectionLevel: level })
|
||||
return { size: modules.size, dark: (row, col) => modules.get(row, col) === 1 }
|
||||
}
|
||||
|
||||
/* The dark modules as one SVG path, a run of horizontal neighbours
|
||||
per subpath, offset by the quiet zone. One element instead of a
|
||||
rect per module keeps the markup (and the SVG download) small. */
|
||||
export function qrPath(matrix: QrMatrix, margin: number): string {
|
||||
const parts: string[] = []
|
||||
for (let row = 0; row < matrix.size; row++) {
|
||||
let col = 0
|
||||
while (col < matrix.size) {
|
||||
if (!matrix.dark(row, col)) {
|
||||
col++
|
||||
continue
|
||||
}
|
||||
const start = col
|
||||
while (col < matrix.size && matrix.dark(row, col)) col++
|
||||
parts.push(`M${start + margin} ${row + margin}h${col - start}v1h-${col - start}z`)
|
||||
}
|
||||
}
|
||||
return parts.join('')
|
||||
}
|
||||
13
src/lib/site.ts
Normal file
13
src/lib/site.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
SITE
|
||||
|
||||
The public address of the live site. Used where a URL has to
|
||||
leave the browser and still work — a printed QR code made on
|
||||
localhost or a preview has to point here, not at wherever it was
|
||||
generated. Everything inside the site links by path, not this.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
export const SITE_ORIGIN = 'https://nextgenerationofunity.org'
|
||||
|
||||
/** A site path as a full URL on the live site. */
|
||||
export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href
|
||||
|
|
@ -336,3 +336,20 @@ export type PersonRecord = {
|
|||
|
||||
export const usePerson = (id?: string): Resource<PersonRecord> =>
|
||||
useRecord<PersonRecord>(detailPath('/people', id), 'person')
|
||||
|
||||
/* ── Directory ─────────────────────────────────────────────────
|
||||
GET /directory: every public record that has a page, one list
|
||||
per kind, each row just enough to build its URL with hrefs.ts. */
|
||||
|
||||
export type DirectoryEntry = { id: string; name: string }
|
||||
|
||||
export type Directory = {
|
||||
events: Array<DirectoryEntry & { starts_on?: string | null }>
|
||||
organizations: Array<DirectoryEntry & { kind: OrganizationRecord['kind'] }>
|
||||
teams: Array<DirectoryEntry & { org_name: string }>
|
||||
awards: DirectoryEntry[]
|
||||
people: DirectoryEntry[]
|
||||
}
|
||||
|
||||
export const useDirectory = (): Resource<Directory> =>
|
||||
useRecord<Directory>('/directory', 'directory')
|
||||
|
|
|
|||
37
src/pages/QrCodes.tsx
Normal file
37
src/pages/QrCodes.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import PageShell from '../components/PageShell.tsx'
|
||||
import QrCodeMaker from './sections/QrCodeMaker.tsx'
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
QR CODES PAGE — /qr
|
||||
|
||||
A QR code for any page on the site, for flyers, slides and
|
||||
signs. Unlisted: not in navConfig, so neither the header nor the
|
||||
footer links here. It lists only published records, so there is
|
||||
nothing on it a visitor couldn't already reach.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const SECTIONS = [
|
||||
{
|
||||
id: 'make',
|
||||
title: 'Make a QR code',
|
||||
blurb:
|
||||
'Pick a page from the main navigation, or any event, organization, team, award or person on the site. The code always points at the live site.',
|
||||
accent: '#138ba0',
|
||||
background: '#eef9fb',
|
||||
content: (
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<QrCodeMaker />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
export default function QrCodes() {
|
||||
return (
|
||||
<PageShell
|
||||
title="QR Codes"
|
||||
intro="Codes for flyers, slides and signs, pointing at any page on the site."
|
||||
sections={SECTIONS}
|
||||
/>
|
||||
)
|
||||
}
|
||||
371
src/pages/sections/QrCodeMaker.tsx
Normal file
371
src/pages/sections/QrCodeMaker.tsx
Normal file
|
|
@ -0,0 +1,371 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
QR CODE MAKER
|
||||
|
||||
Pick a page, get a QR code for it on the live site.
|
||||
|
||||
What main navigation, or one kind of record
|
||||
Which the page or record itself
|
||||
Section for a main page with a subnav, optionally one of
|
||||
its #sections
|
||||
|
||||
The main pages come from navConfig.ts, the same list the header
|
||||
draws; records come from GET /directory, which lists only what's
|
||||
published, and their URLs from hrefs.ts, the same builders the
|
||||
site links with. So a code can only point at a page that exists.
|
||||
|
||||
Codes point at SITE_ORIGIN, never at wherever this page is open,
|
||||
so one made on localhost still works on a poster.
|
||||
|
||||
Downloads are the on-screen <svg> itself: serialised for the SVG,
|
||||
drawn onto a canvas for the PNG. Neither needs a server.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
|
||||
import QrCode from '../../components/QrCode.tsx'
|
||||
import { NAV_ACTIONS, PAGE_LINKS, PAGE_SECTIONS } from '../../navConfig.ts'
|
||||
import { awardHref, eventHref, orgHref, personHref, teamHref } from '../../lib/hrefs.ts'
|
||||
import { siteUrl } from '../../lib/site.ts'
|
||||
import { useDirectory, type Directory } from '../../lib/useContent.ts'
|
||||
|
||||
const TEAL = '#138ba0'
|
||||
const MUTED = '#4a6b72'
|
||||
|
||||
/* PNG download size in pixels. Plenty for print at a few inches;
|
||||
anything bigger should use the SVG. */
|
||||
const PNG_SIZE = 1024
|
||||
|
||||
type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people'
|
||||
|
||||
const KINDS: Array<[Kind, string]> = [
|
||||
['pages', 'Main navigation'],
|
||||
['events', 'Events'],
|
||||
['organizations', 'Organizations'],
|
||||
['teams', 'Teams'],
|
||||
['awards', 'Awards'],
|
||||
['people', 'People'],
|
||||
]
|
||||
|
||||
/* Organizations are grouped by kind in the dropdown, in this order. */
|
||||
const ORG_GROUPS: Array<[string, string]> = [
|
||||
['national', 'NGU'],
|
||||
['region', 'Regions'],
|
||||
['chapter', 'Chapters'],
|
||||
['partner', 'Partner organizations'],
|
||||
]
|
||||
|
||||
type Choice = { path: string; label: string }
|
||||
type Group = { label?: string; choices: Choice[] }
|
||||
|
||||
/* The header's pages, then any nav action that is a page of its own
|
||||
rather than an anchor on one of them (Give, not Contact Us). */
|
||||
function mainPages(): Choice[] {
|
||||
const pages = PAGE_LINKS.map((p) => ({ path: p.path, label: p.label }))
|
||||
const known = new Set(pages.map((p) => p.path))
|
||||
for (const action of NAV_ACTIONS) {
|
||||
const path = action.to.split('#')[0]
|
||||
if (!action.to.includes('#') && !known.has(path)) {
|
||||
pages.push({ path, label: action.label })
|
||||
known.add(path)
|
||||
}
|
||||
}
|
||||
return pages
|
||||
}
|
||||
|
||||
function groupsFor(kind: Kind, directory: Directory | null): Group[] {
|
||||
if (kind === 'pages') return [{ choices: mainPages() }]
|
||||
if (!directory) return []
|
||||
|
||||
switch (kind) {
|
||||
case 'events':
|
||||
return [
|
||||
{
|
||||
choices: directory.events.map((e) => ({
|
||||
path: eventHref(e.id),
|
||||
label: e.starts_on ? `${e.name} (${e.starts_on.slice(0, 4)})` : e.name,
|
||||
})),
|
||||
},
|
||||
]
|
||||
case 'organizations':
|
||||
return ORG_GROUPS.map(([orgKind, label]) => ({
|
||||
label,
|
||||
choices: directory.organizations
|
||||
.filter((o) => o.kind === orgKind)
|
||||
.map((o) => ({ path: orgHref(o.id, o.kind), label: o.name })),
|
||||
})).filter((group) => group.choices.length > 0)
|
||||
case 'teams':
|
||||
return [
|
||||
{
|
||||
choices: directory.teams.map((t) => ({
|
||||
path: teamHref(t.id),
|
||||
label: `${t.name} — ${t.org_name}`,
|
||||
})),
|
||||
},
|
||||
]
|
||||
case 'awards':
|
||||
return [{ choices: directory.awards.map((a) => ({ path: awardHref(a.id), label: a.name })) }]
|
||||
case 'people':
|
||||
return [{ choices: directory.people.map((p) => ({ path: personHref(p.id), label: p.name })) }]
|
||||
}
|
||||
}
|
||||
|
||||
/* "/regions/northwest#events" → "regions-northwest-events". */
|
||||
function fileStem(path: string): string {
|
||||
const stem = path.replace(/^\//, '').replace(/[^a-z0-9]+/gi, '-').replace(/^-|-$/g, '')
|
||||
return `ngu-qr-${stem || 'home'}`
|
||||
}
|
||||
|
||||
function download(href: string, filename: string) {
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = filename
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
}
|
||||
|
||||
function svgMarkup(svg: SVGSVGElement): string {
|
||||
return new XMLSerializer().serializeToString(svg)
|
||||
}
|
||||
|
||||
function downloadSvg(svg: SVGSVGElement, stem: string) {
|
||||
const url = URL.createObjectURL(new Blob([svgMarkup(svg)], { type: 'image/svg+xml' }))
|
||||
download(url, `${stem}.svg`)
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
function downloadPng(svg: SVGSVGElement, stem: string) {
|
||||
const image = new Image()
|
||||
image.onload = () => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = PNG_SIZE
|
||||
canvas.height = PNG_SIZE
|
||||
const context = canvas.getContext('2d')
|
||||
if (!context) return
|
||||
context.imageSmoothingEnabled = false
|
||||
context.drawImage(image, 0, 0, PNG_SIZE, PNG_SIZE)
|
||||
canvas.toBlob((blob) => {
|
||||
if (!blob) return
|
||||
const url = URL.createObjectURL(blob)
|
||||
download(url, `${stem}.png`)
|
||||
URL.revokeObjectURL(url)
|
||||
}, 'image/png')
|
||||
}
|
||||
image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgMarkup(svg))}`
|
||||
}
|
||||
|
||||
export default function QrCodeMaker() {
|
||||
const { data: directory, loading, error } = useDirectory()
|
||||
|
||||
const [kind, setKind] = useState<Kind>('pages')
|
||||
const [path, setPath] = useState('/')
|
||||
const [section, setSection] = useState('')
|
||||
const [dove, setDove] = useState(true)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const svgRef = useRef<SVGSVGElement>(null)
|
||||
|
||||
const groups = useMemo(() => groupsFor(kind, directory), [kind, directory])
|
||||
const choices = useMemo(() => groups.flatMap((group) => group.choices), [groups])
|
||||
|
||||
// A new kind, or the directory arriving, can leave the current
|
||||
// path outside the list; fall back to its first entry.
|
||||
useEffect(() => {
|
||||
if (choices.length > 0 && !choices.some((c) => c.path === path)) {
|
||||
setPath(choices[0].path)
|
||||
setSection('')
|
||||
}
|
||||
}, [choices, path])
|
||||
|
||||
const sections = kind === 'pages' ? (PAGE_SECTIONS[path] ?? []) : []
|
||||
const selected = choices.find((c) => c.path === path) ?? null
|
||||
const target = selected ? `${selected.path}${section}` : null
|
||||
const url = target ? siteUrl(target) : null
|
||||
|
||||
useEffect(() => setCopied(false), [url])
|
||||
|
||||
async function copy() {
|
||||
if (!url) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(url)
|
||||
setCopied(true)
|
||||
} catch {
|
||||
// Clipboard refused (an insecure origin, or a denied
|
||||
// permission). The link is on screen to copy by hand.
|
||||
setCopied(false)
|
||||
}
|
||||
}
|
||||
|
||||
const needsDirectory = kind !== 'pages'
|
||||
|
||||
return (
|
||||
<div className="grid gap-10 lg:grid-cols-2 lg:items-start">
|
||||
<div className="space-y-5">
|
||||
<Select id="qr-kind" label="What to link to" value={kind} onChange={(v) => setKind(v as Kind)}>
|
||||
{KINDS.map(([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
{needsDirectory && loading && !directory ? (
|
||||
<p style={{ color: MUTED }}>Loading the list…</p>
|
||||
) : needsDirectory && error ? (
|
||||
<p className="text-[#b3261e]">Couldn't load the list of pages. {error}</p>
|
||||
) : choices.length === 0 ? (
|
||||
<p style={{ color: MUTED }}>Nothing published here yet.</p>
|
||||
) : (
|
||||
<Select
|
||||
id="qr-target"
|
||||
label={kind === 'pages' ? 'Page' : 'Which one'}
|
||||
value={path}
|
||||
onChange={(v) => {
|
||||
setPath(v)
|
||||
setSection('')
|
||||
}}
|
||||
>
|
||||
{groups.map((group, i) =>
|
||||
group.label ? (
|
||||
<optgroup key={group.label} label={group.label}>
|
||||
{group.choices.map((c) => (
|
||||
<option key={c.path} value={c.path}>
|
||||
{c.label}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
) : (
|
||||
group.choices.map((c) => (
|
||||
<option key={`${i}-${c.path}`} value={c.path}>
|
||||
{c.label}
|
||||
</option>
|
||||
))
|
||||
),
|
||||
)}
|
||||
</Select>
|
||||
)}
|
||||
|
||||
{sections.length > 0 && (
|
||||
<Select id="qr-section" label="Section of that page" value={section} onChange={setSection}>
|
||||
<option value="">The page as a whole</option>
|
||||
{sections.map((s) => (
|
||||
<option key={s.hash} value={s.hash}>
|
||||
{s.label.replace(/^#/, '')}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
)}
|
||||
|
||||
<label className="flex items-center gap-3 text-[#26454c]">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={dove}
|
||||
onChange={(e) => setDove(e.target.checked)}
|
||||
className="h-4 w-4 accent-[#138ba0]"
|
||||
/>
|
||||
NGU dove in the centre
|
||||
</label>
|
||||
|
||||
{url && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-[#26454c]">Links to</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-3">
|
||||
<code className="break-all rounded-lg bg-white px-3 py-2 text-sm text-[#26454c] ring-1 ring-[#4a6b72]/20">
|
||||
{url}
|
||||
</code>
|
||||
<button
|
||||
type="button"
|
||||
onClick={copy}
|
||||
className="rounded-full border px-4 py-2 text-sm font-semibold transition-colors hover:bg-[#138ba0]/10"
|
||||
style={{ borderColor: TEAL, color: TEAL }}
|
||||
>
|
||||
{copied ? 'Copied ✓' : 'Copy link'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center gap-5">
|
||||
{url ? (
|
||||
<>
|
||||
<div className="w-full max-w-sm rounded-3xl bg-white p-6 shadow-lg ring-1 ring-[#4a6b72]/10">
|
||||
<QrCode
|
||||
ref={svgRef}
|
||||
value={url}
|
||||
dove={dove}
|
||||
label={`QR code for ${url}`}
|
||||
className="block h-auto w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-wrap justify-center gap-3">
|
||||
<DownloadButton onClick={() => svgRef.current && downloadPng(svgRef.current, fileStem(target!))}>
|
||||
Download PNG
|
||||
</DownloadButton>
|
||||
<DownloadButton onClick={() => svgRef.current && downloadSvg(svgRef.current, fileStem(target!))}>
|
||||
Download SVG
|
||||
</DownloadButton>
|
||||
</div>
|
||||
<p className="max-w-sm text-center text-sm" style={{ color: MUTED }}>
|
||||
PNG for documents and slides, {PNG_SIZE}px square. SVG for print: it stays sharp at
|
||||
any size.
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<div className="aspect-square w-full max-w-sm rounded-3xl bg-white/60 ring-1 ring-[#4a6b72]/10" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function DownloadButton({ onClick, children }: { onClick: () => void; children: ReactNode }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="rounded-full bg-[#138ba0] px-6 py-3 font-semibold text-white transition-colors hover:bg-[#0f7183] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#138ba0]/40"
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
const selectClass =
|
||||
'w-full appearance-none rounded-xl border border-[#4a6b72]/25 bg-white px-4 py-3 pr-10 text-[#26454c] ' +
|
||||
'outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25'
|
||||
|
||||
function Select({
|
||||
id,
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
children,
|
||||
}: {
|
||||
id: string
|
||||
label: string
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<label htmlFor={id} className="block text-sm font-medium text-[#26454c]">
|
||||
{label}
|
||||
</label>
|
||||
<div className="relative mt-2">
|
||||
<select id={id} value={value} onChange={(e) => onChange(e.target.value)} className={selectClass}>
|
||||
{children}
|
||||
</select>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
className="pointer-events-none absolute right-4 top-1/2 h-4 w-4 -translate-y-1/2"
|
||||
style={{ color: MUTED }}
|
||||
>
|
||||
<path d="M5 8l5 5 5-5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue