Skip to content

fix: keep prose spacing out of component anatomy; add CardGrid - #194

Merged
tenphi merged 2 commits into
mainfrom
fix/code-group-tab-spacing
Nov 6, 2026
Merged

tenphi merged 2 commits into
mainfrom
fix/code-group-tab-spacing

Conversation

@tenphi

@tenphi tenphi commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Problem

Markdown prose spacing (.cookbook-markdown-content×3 * + :where(…), specificity 0,3,0) applies a 3x top margin to every block that follows a sibling — including component anatomy inside tabs, code groups, code blocks and cards:

  • Tabs / CodeGroup: every tab panel got 24px under the tab list, and the first content after the hidden fallback heading (or a hidden CodeGroup caption, as on the Glaze site) got another 24px, leaving a large empty band under the tabs.
  • Copy button: .td-code-block.td-code-block > [data-element="CopyButton"] ties prose at 0,3,0, so its margin: 0 only wins when its rule happens to be emitted after the prose rule. When a CodeGroup renders inside page content first (Glaze home page), the button picks up a 24px top margin and sits 32px from the top but 8px from the right.
  • Card: the description div after the title got 24px on top of the card's 1.5x grid gap, and a card stretched by a surrounding grid split its extra height between the title and description rows, pushing short descriptions down.
  • Cards side by side: in any grid of cards, every card after the first got a 24px top margin, so it sat lower and shorter than its row neighbour. Sites had to work around this in their own grid wrappers (Glaze's CardGrid gives the first card the same margin).

Fix

Each owning component now resets the affected spacing with a structural selector that outranks prose regardless of stylesheet order:

Component Sub-element Selector
Tabs Tab (new) > List ~ Tab — panels sit directly under the list
Tab Body (new element) > Heading + Body — content starts at the panel padding
CodeGroup MarkdownCodeBlock (new) Caption + MarkdownCodeBlock — the caption's own 1x end margin separates it from the code
MarkdownCodeBlock CopyButton, HoverCopyButton, CopiedButton > pre + CopyButton — corner placement no longer depends on rule order
Card Body (new element) + alignContent: start > h3 + Body — the grid gap alone separates title and body; rows stay at the top when stretched

Tab and Card content is now wrapped in a data-element="Body" div. New names are registered in COOKBOOK_COMPONENT_SUB_ELEMENTS and documented in docs/component-styles.md, including a note in Block spacing on how to add space back.

New CardGrid component

CardGrid lays out Card elements in one column on narrow screens and two equal-height columns from @sm (40rem), with a 2x gap. Its Card sub-element (> Card + Card) removes prose spacing between cards, so cards in a row share the same top and height. It is exported from @tenphi/cookbook/components with a CardGridProps type, registered in COOKBOOK_COMPONENT_NAMES, the config schema and the anatomy reference, and documented with an example in Authoring components. Changeset: minor.

Behavior change: the existing browser assertion that a tab panel has a 24px top margin (pinned during the #135 style-ownership refactor) now expects 0px — that margin was the reported gap.

Verification

  • New browser test: the CodeGroup panel sits flush under the list, the caption starts 16px in, the code follows it by 8px, and the copy button has equal top and right gaps. It fails on main (panel 24px below the list) and passes here.
  • Card prose test now checks the body has no prose margin and the card packs its rows to the top.
  • New CardGrid test: cards in a row share top and height with a 16px gap, the title-to-body gap is 12px, and at 390px the grid is a single column. Without the reset, the second card sits 24px lower and the test fails.
  • Manually checked in the reference build with the prose rule re-appended after all other CSS (the Glaze ordering) and the caption hidden: panel gap 0, code 16px from the panel top, copy button 8px/8px, card title to body 12px.
  • pnpm lint (0 warnings), pnpm test (468 passed), package typechecks, pnpm check:types, pnpm check:recipes, pnpm check:packages, pnpm knip, pnpm check:browser (126 passed).

Entropy

Slightly Increased for renderer styling: five small margin resets, two Body wrappers, five new sub-element names and one new layout component (CardGrid), each relying on a sibling combinator partly for specificity (explained in a comment beside it). Slightly Decreased for site authors: tab, code group and card spacing no longer needs theme overrides, the copy button no longer depends on page-specific CSS order, and card grids no longer need a site-specific wrapper with margin workarounds.

Considered and rejected: lowering the prose selector's specificity (it changes cascade outcomes across every prose/component interaction), and teaching prose spacing to skip [hidden] siblings (it misses CSS-hidden captions and removes spacing between visible blocks around a hidden one).

🤖 Generated with Claude Code

tenphi and others added 2 commits November 6, 2026 11:11
Prose block spacing outranked component roots and tied component
sub-elements, so tab panels sat 24px under the tab list, content after the
hidden tab heading or caption got another 24px, the copy button moved off its
corner depending on stylesheet order, and card bodies got 24px on top of the
card gap.

Reset that spacing in each owning component with structural selectors that
outrank prose, and pack card rows to the top when a grid stretches the card.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cards placed side by side in a grid each picked up Markdown's 24px block
spacing after the first, so neighbouring cards in a row had different tops
and heights. CardGrid lays cards out in one column, or two from @sm, and its
Card sub-element removes that spacing so the grid gap alone separates cards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tenphi tenphi changed the title fix: keep prose spacing out of tab, code group and card anatomy fix: keep prose spacing out of component anatomy; add CardGrid Nov 6, 2026
@tenphi
tenphi merged commit 50cbc33 into main Nov 6, 2026
12 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant