Files
web-terminal/public/qr.ts
Yaojia Wang 67b0a43b39 polish(v0.6): replace toolbar emoji with themed line icons + hover tooltips
The glossy emoji (🔍⚙▦🕘🔗📱) clashed with the Amber dark theme. Swap them
for clean lucide line icons (MIT, stroke=currentColor) so they take the theme
colour — muted by default, Amber on hover — and add a styled CSS hover tooltip
(data-tip, right-anchored so it never clips the edge) showing what each does.

- public/icons.ts: 7 line icons (search/settings/dashboard/history/keyboard/
  share/device), script-generated from lucide
- 7 toolbar modules: innerHTML = ICON_* + data-tip + aria-label
- style.css .toolbtn: 18px svg, --text-dim → --accent on hover, [data-tip] tooltip

Frontend-only. web typecheck + build clean; bundle has 0 toolbar emoji; verified
in-browser: line icons in theme colour, amber + tooltip on hover.
2026-06-30 14:36:26 +02:00

66 lines
2.0 KiB
TypeScript

/**
* public/qr.ts — "open on another device" QR modal (M5).
*
* Renders a QR of the current origin (client-side, no server call). When the
* page is opened via the host's LAN IP, the QR is directly shareable to a
* phone/tablet on the same network.
*/
import QRCode from 'qrcode'
import { ICON_DEVICE } from './icons.js'
export function mountQrConnect(toolbar: HTMLElement): void {
const modal = document.createElement('div')
modal.id = 'qrmodal'
modal.style.display = 'none'
const card = document.createElement('div')
card.className = 'qr-card'
const title = document.createElement('div')
title.className = 'qr-title'
title.textContent = 'Open on another device'
const canvas = document.createElement('canvas')
const urlEl = document.createElement('div')
urlEl.className = 'qr-url'
const note = document.createElement('div')
note.className = 'qr-note'
const close = document.createElement('button')
close.className = 'qr-close'
close.textContent = 'Close'
card.append(title, canvas, urlEl, note, close)
modal.appendChild(card)
document.body.appendChild(modal)
const open = (): void => {
const origin = location.origin
urlEl.textContent = origin
void QRCode.toCanvas(canvas, origin, { width: 220, margin: 1 })
const host = location.hostname
note.textContent =
host === 'localhost' || host === '127.0.0.1'
? 'Tip: open this page via your LAN IP (not localhost) for a shareable code.'
: 'Scan on a device on the same network.'
modal.style.display = 'flex'
}
const hide = (): void => {
modal.style.display = 'none'
}
modal.addEventListener('click', (e) => {
if (e.target === modal) hide()
})
close.addEventListener('click', hide)
const toggle = document.createElement('button')
toggle.className = 'toolbtn'
toggle.innerHTML = ICON_DEVICE
toggle.dataset.tip = 'Connect a device'
toggle.setAttribute('aria-label', 'Connect a device')
toggle.setAttribute('aria-label', 'Connect another device')
toggle.addEventListener('click', open)
toolbar.appendChild(toggle)
}