From 5226f6c9f1fd99a48680ee9fd1a12c0e1fc4f634 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Wed, 2 Dec 2026 14:17:02 -0800 Subject: [PATCH 1/7] Announce v5.0 sloped sides in a floating banner A birch strip, its left end cut on a slope with a burnt edge, floats out from under the header. A side view of a box is traced, then the sloped front glows. "Try it" switches the generator to a sloped front. - Shows once per release: dismissing or trying it is kept in localStorage under makeabox:announce:. - Hidden in the HTML until the controller shows it, so it never flashes. - Sits under the header and the panels; holds still under reduced motion. - Request spec for the markup; Cypress spec for show, try and dismiss. --- app/assets/stylesheets/announce.css | 86 +++++++++++++++++++ .../controllers/announce_controller.js | 44 ++++++++++ app/views/layouts/application.html.haml | 1 + app/views/shared/_announcement.html.haml | 18 ++++ app/views/shared/_head.html.haml | 2 +- cypress/e2e/announce.cy.js | 32 +++++++ spec/requests/home_spec.rb | 7 ++ 7 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/announce.css create mode 100644 app/javascript/controllers/announce_controller.js create mode 100644 app/views/shared/_announcement.html.haml create mode 100644 cypress/e2e/announce.cy.js diff --git a/app/assets/stylesheets/announce.css b/app/assets/stylesheets/announce.css new file mode 100644 index 0000000..1a56114 --- /dev/null +++ b/app/assets/stylesheets/announce.css @@ -0,0 +1,86 @@ +/* The release banner: a strip of birch plywood that floats out from under the + header. Its left end is cut on a slope, like the front of the box it announces. */ +.announce { + --slope: 26px; + position: fixed; z-index: 2; /* under the header, which it slides out of, and under the panels */ + top: calc(var(--header) + 12px); left: 50%; + display: flex; align-items: center; gap: 14px; + max-width: min(640px, calc(100vw - 2 * var(--gutter))); + padding: 10px 12px 10px calc(var(--slope) + 10px); + color: var(--char); + background: + repeating-linear-gradient(97deg, rgb(255 255 255 / 0.07) 0 2px, transparent 2px 9px), + linear-gradient(180deg, var(--birch-light), var(--birch) 60%, var(--birch-dark)); + clip-path: polygon(var(--slope) 0, 100% 0, 100% 100%, 0 100%); + filter: drop-shadow(0 10px 18px rgb(0 0 0 / 0.45)); + opacity: 0; + transform: translate(-50%, -28px); + transition: opacity 0.5s ease-out, transform 0.7s cubic-bezier(0.2, 1.4, 0.4, 1); +} +.announce[hidden] { display: none; } +.announce.in { opacity: 1; transform: translate(-50%, 0); transition-delay: 0.6s; } +.announce.out { opacity: 0; transform: translate(-50%, -28px); transition-duration: 0.3s; transition-delay: 0s; } + +/* Once it has landed it keeps bobbing gently, as if it hung in the air. */ +.announce.in { animation: bob 4.2s ease-in-out 1.4s infinite; } +@keyframes bob { + 0%, 100% { translate: 0 0; } + 50% { translate: 0 -5px; } +} + +/* The burnt edge along the slope, where the laser cut it. */ +.announce::before { + content: ""; position: absolute; inset: 0; + clip-path: polygon(var(--slope) 0, calc(var(--slope) + 3px) 0, 3px 100%, 0 100%); + background: var(--char); opacity: 0.85; +} + +/* The little side view is drawn by the beam, then the sloped front glows. */ +.announce .sketch { flex: none; overflow: visible; } +.announce .trace { + fill: none; stroke: var(--char); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; + stroke-dasharray: 100; stroke-dashoffset: 100; +} +.announce.in .trace { animation: trace 1.1s ease-in-out 1s forwards; } +.announce.in .slope { stroke: var(--beam); animation: trace 0.5s ease-out 2.1s forwards, glow 2.4s ease-in-out 2.6s infinite; } +@keyframes trace { to { stroke-dashoffset: 0; } } +@keyframes glow { + 0%, 100% { filter: drop-shadow(0 0 1px var(--beam)); } + 50% { filter: drop-shadow(0 0 4px var(--amber)); } +} + +.announce .words { display: flex; align-items: baseline; gap: 10px; min-width: 0; } +.announce .release { + flex: none; font: 600 24px/1 "Barlow Condensed", "Archivo", sans-serif; letter-spacing: 0.02em; + color: var(--beam); text-shadow: 0 1px 0 rgb(255 255 255 / 0.35); +} +.announce .release .v { font-size: 0.7em; margin-right: 1px; } +.announce .line { font-size: 15px; line-height: 1.3; } +.announce .line b { font-weight: 750; } + +.announce button { flex: none; cursor: pointer; border: 0; } +.announce .try { + padding: 7px 14px; border-radius: 3px; + font: 600 16px/1 "Barlow Condensed", "Archivo", sans-serif; letter-spacing: 0.04em; text-transform: uppercase; + color: var(--ink); background: var(--char); +} +.announce .try:hover { background: var(--beam); } +.announce .close { + width: 28px; height: 28px; padding: 0; border-radius: 50%; + font-size: 22px; line-height: 1; color: var(--char); background: transparent; +} +.announce .close:hover { background: rgb(61 38 20 / 0.12); } +.announce :focus-visible { outline-color: var(--char); } + +@media (max-width: 640px) { + .announce { --slope: 18px; gap: 10px; width: calc(100vw - 2 * var(--gutter)); } + .announce .sketch { display: none; } + .announce .words { flex-direction: column; gap: 2px; } + .announce .line { font-size: 14px; } +} + +@media (prefers-reduced-motion: reduce) { + .announce, .announce.in, .announce.out { transition: opacity 0.2s; transform: translate(-50%, 0); animation: none; } + .announce .trace { stroke-dashoffset: 0; animation: none !important; } + .announce .slope { stroke: var(--beam); } +} diff --git a/app/javascript/controllers/announce_controller.js b/app/javascript/controllers/announce_controller.js new file mode 100644 index 0000000..ca48105 --- /dev/null +++ b/app/javascript/controllers/announce_controller.js @@ -0,0 +1,44 @@ +import { Controller } from "@hotwired/stimulus" + +// The release banner under the header. It drifts in once per release and stays +// gone after it is dismissed or tried; the choice is kept in localStorage under +// a key that names the release, so the next release announces itself afresh. +export default class extends Controller { + static values = { key: String } + + connect() { + if (this.seen) return + this.element.hidden = false + // One frame later, so the slide-in transition has a starting point. + requestAnimationFrame(() => requestAnimationFrame(() => this.element.classList.add("in"))) + } + + // Switches the generator to a sloped front, the way choosing it by hand would. + try() { + const shape = document.querySelector('[data-generator-target="shape"]') + if (shape) { + shape.value = "sloped" + shape.dispatchEvent(new Event("change", { bubbles: true })) + shape.focus({ preventScroll: true }) + shape.scrollIntoView({ behavior: "smooth", block: "center" }) + } + this.dismiss() + } + + dismiss() { + this.seen = true + this.element.classList.remove("in") + this.element.classList.add("out") + const hide = () => { this.element.hidden = true } + this.element.addEventListener("transitionend", hide, { once: true }) + setTimeout(hide, 600) // reduced motion has no transition to end + } + + get seen() { + try { return localStorage.getItem(this.keyValue) === "1" } catch { return false } + } + + set seen(value) { + try { localStorage.setItem(this.keyValue, value ? "1" : "") } catch { /* private mode: show it again next time */ } + } +} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index dd0046d..9a284f3 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -17,5 +17,6 @@ %a{href: '#discussion', data: {action: 'panels#open menu#close', panels_name_param: 'discussion'}} Discussion %a{href: 'https://github.com/kigster/laser-cutter', target: "_blank", data: {action: 'menu#close'}} GitHub %a{href: '#support', data: {action: 'panels#open menu#close', panels_name_param: 'support'}} Donate + = render 'shared/announcement' = yield = render 'shared/footer' diff --git a/app/views/shared/_announcement.html.haml b/app/views/shared/_announcement.html.haml new file mode 100644 index 0000000..620f676 --- /dev/null +++ b/app/views/shared/_announcement.html.haml @@ -0,0 +1,18 @@ +-# Floats out from under the header to announce what the release brought. Hidden +-# until announce_controller.js shows it, so it never flashes for someone who closed it. +- release = Makeabox::VERSION.split('.').first(2).join('.') +%aside.announce{hidden: true, 'aria-label': "New in version #{release}", + data: {controller: 'announce', announce_key_value: "makeabox:announce:#{release}"}} + %svg.sketch{viewBox: '0 0 48 40', width: 48, height: 40, 'aria-hidden': 'true'} + -# A box seen from the side: upright back, front rising part-way, then leaning back to the top. + %path.trace{d: 'M22 6 H42 V36 H6 V22', pathLength: 100} + %path.trace.slope{d: 'M6 22 L22 6', pathLength: 100} + .words + %strong.release + %span.v v + = release + %span.line + %b Sloped sides. + The front of a box can now lean back at any angle. + %button.try{type: 'button', data: {action: 'announce#try'}} Try it + %button.close{type: 'button', 'aria-label': 'Dismiss', data: {action: 'announce#dismiss'}} × diff --git a/app/views/shared/_head.html.haml b/app/views/shared/_head.html.haml index 20b41e7..457f215 100644 --- a/app/views/shared/_head.html.haml +++ b/app/views/shared/_head.html.haml @@ -36,6 +36,6 @@ = preload_link_tag 'archivo-variable-latin.woff2', as: 'font', type: 'font/woff2', crossorigin: 'anonymous' = preload_link_tag 'barlow-condensed-600-latin.woff2', as: 'font', type: 'font/woff2', crossorigin: 'anonymous' - = stylesheet_link_tag 'tokens', 'base', 'generator', 'dialogs', 'sections' + = stylesheet_link_tag 'tokens', 'base', 'generator', 'dialogs', 'sections', 'announce' = javascript_importmap_tags = csrf_meta_tags \ No newline at end of file diff --git a/cypress/e2e/announce.cy.js b/cypress/e2e/announce.cy.js new file mode 100644 index 0000000..869a3f4 --- /dev/null +++ b/cypress/e2e/announce.cy.js @@ -0,0 +1,32 @@ +const KEY = "makeabox:announce:5.0" +const banner = () => cy.get("aside.announce") + +describe("the release banner", () => { + beforeEach(() => { + cy.clearLocalStorage() + cy.visit("/") + }) + + it("floats in under the header and draws the sloped box", () => { + banner().should("be.visible").and("have.class", "in") + banner().should("have.css", "animation-name", "bob") + banner().find(".slope").should("have.css", "stroke-dashoffset", "0px") + cy.screenshot("announce", { capture: "viewport" }) + }) + + it("switches the generator to a sloped front when tried", () => { + banner().find(".try").click() + cy.get('[data-generator-target="shape"]').should("have.value", "sloped") + cy.get('[data-generator-target="sloped"]').should("be.visible") + banner().should("not.be.visible") + cy.window().then((win) => expect(win.localStorage.getItem(KEY)).to.eq("1")) + }) + + it("stays gone once dismissed", () => { + banner().find(".close").click() + banner().should("not.be.visible") + cy.reload() + banner().should("have.attr", "hidden") + cy.get('[data-generator-target="shape"]').should("have.value", "upright") + }) +}) diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index 333f1c4..fe1c3ee 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -28,6 +28,13 @@ expect(response.body).to include('Kerf matters most', 'The default, 0.026 in (0.66 mm)') end + it 'announces the release with sloped sides, hidden until the script shows it' do + expect(response.body).to include( + '