Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Skill page: on a phone every prompt wraps to be read whole, and the install command fades at its edge while more of it is hidden

Lucas Marques8de93246516d
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index 821732f..1b735e1 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -355,9 +355,10 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.example > * { min-width: 0; }
.example-prompt { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }
.example-figure { container-type: inline-size; }
-/* a follow-up is a sentence: it wraps in its pill, and the copy icon stays by its first line */
-.pill[data-command="follow-up"] { height: auto; min-height: 48px; padding-block: 6px; align-items: start; }
-.pill[data-command="follow-up"] .pill-line { padding-block: 8px; line-height: 20px; white-space: normal; overflow: visible; text-wrap: pretty; }
+/* a prompt is read, not run: it wraps in its pill when it must, and the copy icon stays by its first line. Only the
+ install command, a shell line, keeps to one line and scrolls. */
+.pill:is([data-command="prompt"], [data-command="follow-up"], [data-command="usage"]) { height: auto; min-height: 48px; padding-block: 6px; align-items: start; }
+.pill:is([data-command="prompt"], [data-command="follow-up"], [data-command="usage"]) .pill-line { padding-block: 8px; line-height: 20px; white-space: normal; overflow: visible; text-wrap: pretty; }
/* The generated page pads its column by 24px above and below and 16px at the sides. The frame bleeds by that much,
so the plate meets the column: its edges on the column's, its top on the prompt's. Stacked, the frame stops at the
link above it instead of covering it. The height is the one the page takes before it is measured: its plate, as
diff --git a/apps/site/components/command.tsx b/apps/site/components/command.tsx
index 4b3b568..3182935 100644
--- a/apps/site/components/command.tsx
+++ b/apps/site/components/command.tsx
@@ -1,20 +1,39 @@
"use client";
-import { useRef } from "react";
+import { useEffect, useRef, useState } from "react";
import { CopyIcon } from "./copy";
/**
* One line to type, in a pill with a copy icon. `kind` says which line it is,
* for the tests (`prompt` is an example's, `follow-up` the change asked for
* after it, `usage` the bare command); a shell command takes the `$` in front
- * of it. A follow-up is a sentence, so it wraps instead of scrolling.
+ * of it. A prompt is read, so it wraps when it must. The install command is a
+ * shell line, so it stays one line: wider than the pill, it scrolls and fades
+ * at the edge while more of it is hidden, as the home's install does.
*/
export function Command({ code, kind, label }: { code: string; kind: "install" | "prompt" | "follow-up" | "usage"; label: string }) {
const line = useRef<HTMLElement>(null);
+ const [more, setMore] = useState(false);
+ const one = kind === "install";
+
+ useEffect(() => {
+ const el = line.current;
+ if (!one || !el) return;
+ const measure = () => setMore(el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
+ measure();
+ el.addEventListener("scroll", measure, { passive: true });
+ const resize = new ResizeObserver(measure);
+ resize.observe(el);
+ return () => {
+ el.removeEventListener("scroll", measure);
+ resize.disconnect();
+ };
+ }, [one, code]);
+
return (
<div className="pill" data-command={kind}>
- {kind === "install" && <span aria-hidden="true" className="select-none text-faint">$</span>}
- <code ref={line} className="pill-line" title={code}>{code}</code>
+ {one && <span aria-hidden="true" className="select-none text-faint">$</span>}
+ <code ref={line} className="pill-line" title={code} data-more={more ? "" : undefined}>{code}</code>
<CopyIcon text={code} select={line} label={label} />
</div>
);
diff --git a/apps/site/test/skill.spec.ts b/apps/site/test/skill.spec.ts
index d744be1..f45788c 100644
--- a/apps/site/test/skill.spec.ts
+++ b/apps/site/test/skill.spec.ts
@@ -107,6 +107,26 @@ for (const width of [1200, 320]) {
});
}
+for (const width of [320, 900]) {
+ test(`at ${width}px every prompt reads whole, and the install line fades while more of it is hidden`, async ({ page }) => {
+ await page.setViewportSize({ width, height: 800 });
+ await page.goto("/skill");
+ const lines = page.locator('[data-command="prompt"] .pill-line');
+ await expect(lines).toHaveCount(4);
+ for (const over of await lines.evaluateAll((els) => els.map((el) => el.scrollWidth - el.clientWidth))) expect(over).toBeLessThanOrEqual(0);
+ const install = page.locator('[data-command="install"] .pill-line');
+ expect(await install.evaluate((el) => getComputedStyle(el).whiteSpace)).toBe("nowrap");
+ const hidden = await install.evaluate((el) => el.scrollWidth - el.clientWidth > 1);
+ if (hidden) {
+ await expect(install).toHaveAttribute("data-more", "");
+ await install.evaluate((el) => { el.scrollLeft = el.scrollWidth; });
+ await expect(install).not.toHaveAttribute("data-more");
+ } else {
+ await expect(install).not.toHaveAttribute("data-more");
+ }
+ });
+}
+
test("at 1200px each plate starts on its prompt's line and meets the column's edges", async ({ page }) => {
await page.goto("/skill");
await frames(page);