From 24037e23d25839ccd549d97683699bac69c300b7 Mon Sep 17 00:00:00 2001 From: Cristian Date: Thu, 12 Nov 2026 07:05:09 +0100 Subject: [PATCH] Folder tabs stand one standard control tall Every tab is now 33px, a standard control's height, and the whole box takes the pointer. The open tab's card fills it; the cards filed behind it are drawn 4px shorter at the box's foot, so a filed tab still answers a press in the band above its card. The strip drops from 40px to 33px. --- kit/Tabs.test.tsx | 37 +++++++++++++++++++++++++++++++++++++ kit/Tabs.tsx | 39 +++++++++++++++++++++++---------------- 2 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 kit/Tabs.test.tsx diff --git a/kit/Tabs.test.tsx b/kit/Tabs.test.tsx new file mode 100644 index 0000000..f8b42e0 --- /dev/null +++ b/kit/Tabs.test.tsx @@ -0,0 +1,37 @@ +import { assertEquals } from "@std/assert"; +import { Tabs } from "./Tabs.tsx"; +import { createNativeRoot, nativeNodes } from "./primitives/reconciler.ts"; + +const SHEETS = [ + { id: "general", label: "General" }, + { id: "graphics", label: "Graphics" }, +]; + +function drawnStrip() { + const root = createNativeRoot(() => {}); + root.renderSync( + {}} />, + ); + const nodes = [...nativeNodes()]; + root.renderSync(null); + return nodes; +} + +Deno.test("a filed tab answers the pointer as tall as the open one", () => { + const nodes = drawnStrip(); + const open = nodes.find((node) => node.props.id === "sheets-general"); + const filed = nodes.find((node) => node.props.id === "sheets-graphics"); + assertEquals( + { open: open?.props.height, filed: filed?.props.height }, + { open: 33, filed: 33 }, + ); +}); + +Deno.test("a filed tab's card stands 4px lower than the open one's", () => { + const cards = drawnStrip().filter((node) => node.props.slant !== undefined); + // The open tab paints last, over both its neighbours. + assertEquals( + cards.map((card) => (card.props.inset as { top: number }).top), + [4, 0], + ); +}); diff --git a/kit/Tabs.tsx b/kit/Tabs.tsx index d8cb188..5b2c633 100644 --- a/kit/Tabs.tsx +++ b/kit/Tabs.tsx @@ -17,12 +17,18 @@ import { getFocusedNode, host, type HostNode } from "bureau/host"; * THE TAB'S FORM is a trapezoid slanted 10px on both sides, Mac OS 8's tab * panel: an ink shape with the face laid a pixel inside it, open at the * bottom, so the open tab and the page read as one piece of card. The host - * draws the card whole, a slanted box, at the screen's own pixels. Each tab is pulled left by both its slants, so neighbours interlock the way - * filed card does, and the open tab lies over both of its neighbours. + * draws the card whole, a slanted box, at the screen's own pixels. Each tab is + * pulled left by both its slants, so neighbours interlock the way filed card + * does, and the open tab lies over both of its neighbours. + * + * Every tab is a standard control's height, and that whole box takes the + * pointer. The card filed behind the page is drawn shorter at the box's foot, + * so the strip stays one control tall while the open tab still stands above + * the rest. */ import React, { useRef, useState } from "react"; import { Box, type Ink, type KeyEvent, Text } from "bureau/primitives"; -import { EFFECTS } from "./tokens.ts"; +import { CONTROL_METRICS, EFFECTS } from "./tokens.ts"; import { GamepadPriority, useGamepadFrame, @@ -59,9 +65,9 @@ type TabsProps = { /** The tab's slant, and how far each tab is pulled over the one before. */ const SLANT = 10; const INTERLOCK = -(SLANT * 2) + 2; +const TAB_HEIGHT = CONTROL_METRICS.standard.height; /** The open tab stands 4px taller than the card filed behind it. */ -const TAB_HEIGHT = 36; -const OPEN_TAB_HEIGHT = 40; +const FILED_CARD_DROP = 4; const BADGE_TILES = { alert: { fill: "fill-alert", ink: "knockout-alert" }, @@ -138,7 +144,7 @@ function TabKey( const setStatus = useStatus(); const [hovered, setHovered] = useState(false); const [focused, setFocused] = useState(false); - const height = selected ? OPEN_TAB_HEIGHT : TAB_HEIGHT; + const drop = selected ? 0 : FILED_CARD_DROP; // Card filed behind the page lifts under the pointer; the open tab never // changes at all. const face: Ink = hovered && !selected ? "face-light" : "face"; @@ -156,11 +162,11 @@ function TabKey( ink="ink" align="center" gap={6} - height={height} - minHeight={height} + height={TAB_HEIGHT} + minHeight={TAB_HEIGHT} minWidth={36} shrink={0} - padding={[0, SLANT + 14]} + padding={[drop, SLANT + 14, 0, SLANT + 14]} margin={interlocks ? [0, 0, 0, INTERLOCK] : 0} onPress={onPress} onKey={onKey} @@ -175,17 +181,18 @@ function TabKey( > - { - // Any focus, not only one the keyboard moved: a bumper moves focus - // from code, and the tab it lands on must show it. - focused && - } + > + { + // Any focus, not only one the keyboard moved: a bumper moves focus + // from code, and the tab it lands on must show it. + focused && + } + {leadingGlyph} {tab.label} {badge && (