Skip to content

feat: ResponsiveContainer for auto-sizing charts to parent (#120)#130

Merged
Ben Severn (benzsevern) merged 2 commits into
mainfrom
feat/120-responsive-container
May 28, 2026
Merged

feat: ResponsiveContainer for auto-sizing charts to parent (#120)#130
Ben Severn (benzsevern) merged 2 commits into
mainfrom
feat/120-responsive-container

Conversation

@benzsevern
Copy link
Copy Markdown
Collaborator

Summary

  • New <ResponsiveContainer> render-prop wrapper using ResizeObserver. SSR-safe (renders nothing without a defaultSize until first measurement), supports aspectRatio, minWidth, minHeight, maxHeight, debounced updates.
  • Pure computeResponsiveSize helper extracted so the size-derivation logic is unit-tested (project convention is no-jsdom; see src/interactive/InteractiveChart.test.ts).
  • Exported from goldenchart and goldenchart/components barrels.
  • README quick-start gains a responsive example.

Verification

  • npm run typecheck clean
  • npx vitest run src/components/ResponsiveContainer.test.ts — 7 tests pass
  • npm run build && npm run check:bundle — browser entry 48 KB gzipped (budget 75 KB)

Test plan

  • Typecheck clean
  • New tests pass
  • Bundle guard green
  • CI green

Closes #120.

GoldenChart components require explicit width/height. This wrapper
observes its `<div>` with ResizeObserver and hands the measured size
to a render-prop child, so charts can fill their parent in flex/grid
dashboards.

- new src/components/ResponsiveContainer.tsx — ResizeObserver-backed,
  SSR-safe (renders nothing without a defaultSize until first measure),
  with aspectRatio derivation, min/max clamps, debounced updates
- pure `computeResponsiveSize` helper extracted + unit-tested (project
  convention: no jsdom — see InteractiveChart.test.ts)
- exported from goldenchart and goldenchart/components
- README quick-start gains a responsive example

Bundle 48 KB gzipped (budget 75 KB).
@benzsevern Ben Severn (benzsevern) merged commit 11fc885 into main May 28, 2026
5 checks passed
@benzsevern Ben Severn (benzsevern) deleted the feat/120-responsive-container branch May 28, 2026 16:38
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.

ResponsiveContainer: auto-size charts to parent

1 participant