feat: show calculator status messages as overlay bar

This commit is contained in:
2026-05-15 20:56:05 +02:00
parent 6444357444
commit ef0e0c8dd2
4 changed files with 53 additions and 11 deletions
+1 -1
View File
@@ -5,5 +5,5 @@
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants` - Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands` - Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e` - Commands: arithmetic, stack, trigonometry, constants `pi` and `e`
- Demo actions: paste now parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty - Demo actions: paste now parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty; operation errors are shown as an overlay bar on top of the calculator with a shorter timeout and darker red
- Exports: browser `window.RpnCalculator`, CommonJS `module.exports` - Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
+33 -6
View File
@@ -65,6 +65,8 @@ body {
"buttons functions" "buttons functions"
"keypad functions" "keypad functions"
"keypad trigo"; "keypad trigo";
} }
.display-panel, .display-panel,
@@ -81,6 +83,7 @@ body {
.display-panel { .display-panel {
grid-area: display; grid-area: display;
position: relative;
padding: clamp(12px, 1.5vw, 16px); padding: clamp(12px, 1.5vw, 16px);
background: linear-gradient(180deg, var(--display), var(--display2)); background: linear-gradient(180deg, var(--display), var(--display2));
color: var(--displayText); color: var(--displayText);
@@ -203,14 +206,38 @@ body {
padding-top: 10px; padding-top: 10px;
} }
.status-line { .status-bar {
grid-area: status; position: absolute;
padding: 10px 14px; top: 0;
left: 0;
right: 0;
z-index: 2;
padding: 8px 12px;
min-height: 30px;
display: flex; display: flex;
align-items: center; align-items: center;
min-height: 42px; justify-content: center;
font-size: 14px; font-size: 13px;
color: rgba(255, 255, 255, 0.85); font-weight: 700;
letter-spacing: 0.02em;
color: rgba(31, 42, 18, 0.96);
background: rgba(255, 246, 170, 0.92);
border-bottom: 1px solid rgba(31, 42, 18, 0.2);
transform: translateY(-100%);
opacity: 0;
transition: transform 180ms ease, opacity 180ms ease;
pointer-events: none;
}
.status-bar.is-visible {
transform: translateY(0);
opacity: 1;
}
.status-bar.is-error {
color: #fff;
background: rgba(72, 14, 14, 0.98);
border-bottom-color: rgba(255, 255, 255, 0.12);
} }
.keypad-grid, .keypad-grid,
+1
View File
@@ -10,6 +10,7 @@
<main class="app-shell"> <main class="app-shell">
<section class="calculator calculator-portrait" aria-label="HP48GX style RPN calculator"> <section class="calculator calculator-portrait" aria-label="HP48GX style RPN calculator">
<div class="display-panel"> <div class="display-panel">
<div class="status-bar" id="statusLine" aria-live="polite"></div>
<div class="display-frame"> <div class="display-frame">
<div class="display-grid"> <div class="display-grid">
<div class="stack-cell"><span class="stack-label">T:</span><span id="stackT" class="stack-value"></span></div> <div class="stack-cell"><span class="stack-label">T:</span><span id="stackT" class="stack-value"></span></div>
+18 -4
View File
@@ -20,6 +20,7 @@ const keypadGrid = document.getElementById('keypadGrid');
const functionsGrid = document.getElementById('functionsGrid'); const functionsGrid = document.getElementById('functionsGrid');
const trigoGrid = document.getElementById('trigoGrid'); const trigoGrid = document.getElementById('trigoGrid');
const calculatorEl = document.querySelector('.calculator'); const calculatorEl = document.querySelector('.calculator');
const statusLine = document.getElementById('statusLine');
const keypadKeys = [ const keypadKeys = [
{ label: '±', action: 'neg', className: 'key-default' }, { label: '±', action: 'neg', className: 'key-default' },
@@ -75,8 +76,20 @@ function focusInput() {
hiddenInput.focus(); hiddenInput.focus();
} }
function setStatus(message) { let statusTimer = null;
console.log(message);
function setStatus(message, isError = false, timeoutMs = 1400) {
if (!statusLine) return;
clearTimeout(statusTimer);
statusLine.textContent = message;
statusLine.classList.toggle('is-error', isError);
statusLine.classList.toggle('is-visible', Boolean(message));
if (!message || timeoutMs <= 0) return;
statusTimer = window.setTimeout(() => {
statusLine.textContent = '';
statusLine.classList.remove('is-visible');
statusLine.classList.remove('is-error');
}, timeoutMs);
} }
function normalizeStack() { function normalizeStack() {
@@ -191,7 +204,7 @@ function execute(name) {
} }
render(); render();
} catch (error) { } catch (error) {
console.error(error); setStatus(error?.message || 'Operation error', true);
} }
} }
@@ -311,7 +324,7 @@ pasteButton.addEventListener('click', async () => {
const text = await navigator.clipboard.readText(); const text = await navigator.clipboard.readText();
pasteTextIntoStack(text); pasteTextIntoStack(text);
} catch (error) { } catch (error) {
setStatus('Paste unavailable'); setStatus('Paste unavailable', true);
} }
}); });
@@ -356,6 +369,7 @@ function openConstMenu() {
pushEditingValueIfNeeded(); pushEditingValueIfNeeded();
calc.push(constant.value); calc.push(constant.value);
render(); render();
setStatus(`Inserted ${constant.label}`);
closeConstMenu(); closeConstMenu();
focusInput(); focusInput();
}); });