Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(storybook): page-frame stories render edge to edge (#8311)

Christopher Chedeauacd5773fe473
diff --git a/apps/storybook/.storybook/preview.tsx b/apps/storybook/.storybook/preview.tsx
index 54460eda9f..4561ef54e8 100644
--- a/apps/storybook/.storybook/preview.tsx
+++ b/apps/storybook/.storybook/preview.tsx
@@ -18,6 +18,8 @@ import {y2kTheme} from '@astryxdesign/theme-y2k';
// Import the base reset stylesheet
import '@astryxdesign/core/reset.css';
+import {storyPadding} from './storyFrame';
+
/**
* Every shipped theme, so the toolbar can reach them and the visual gate can
* photograph a component under each theme that overrides it. A theme missing
@@ -45,12 +47,16 @@ const themes = {
* Theme wrapper div. Without this, the iframe's `<html>` and
* `<body>` keep the browser-default `color-scheme` (typically "light")
* and toggling the toolbar has no visible effect.
+ *
+ * Wraps every story in a 16 px gutter, except stories with the `pageFrame`
+ * parameter, which render page frames edge to edge (see `storyPadding`).
*/
const withTheme: Decorator = (Story, context) => {
// Get theme selection from toolbar
const themeKey = (context.globals?.astryxTheme || 'neutral') as string;
const mode = context.globals?.colorMode === 'dark' ? 'dark' : 'light';
const direction = context.globals?.direction === 'rtl' ? 'rtl' : 'ltr';
+ const padding = storyPadding(context.parameters);
// Sync color-scheme to the document root so light-dark() works
// everywhere, including on <html>/<body> backgrounds and any
@@ -67,7 +73,7 @@ const withTheme: Decorator = (Story, context) => {
dir={direction}
style={{
colorScheme: mode,
- padding: 16,
+ padding,
}}>
<Story />
</div>
@@ -85,7 +91,7 @@ const withTheme: Decorator = (Story, context) => {
dir={direction}
style={{
backgroundColor: 'var(--color-background-surface)',
- padding: 16,
+ padding,
}}>
<Story />
</div>
diff --git a/apps/storybook/.storybook/storyFrame.test.ts b/apps/storybook/.storybook/storyFrame.test.ts
new file mode 100644
index 0000000000..9f8d7bb504
--- /dev/null
+++ b/apps/storybook/.storybook/storyFrame.test.ts
@@ -0,0 +1,21 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {describe, expect, it} from 'vitest';
+
+import {storyPadding} from './storyFrame';
+
+describe('storyPadding', () => {
+ it('leaves page-frame stories edge to edge', () => {
+ expect(storyPadding({pageFrame: true})).toBe(0);
+ });
+
+ it('keeps the 16 px gutter around every other story, whatever its layout', () => {
+ expect(storyPadding({})).toBe(16);
+ expect(storyPadding(undefined)).toBe(16);
+ expect(storyPadding({pageFrame: false})).toBe(16);
+ // The global layout is fullscreen: that alone keeps the gutter.
+ expect(storyPadding({layout: 'fullscreen'} as {pageFrame?: boolean})).toBe(
+ 16,
+ );
+ });
+});
diff --git a/apps/storybook/.storybook/storyFrame.ts b/apps/storybook/.storybook/storyFrame.ts
new file mode 100644
index 0000000000..5c70e40be6
--- /dev/null
+++ b/apps/storybook/.storybook/storyFrame.ts
@@ -0,0 +1,14 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * The padding the theme decorator puts around a story.
+ *
+ * Every story gets a 16 px gutter (the global layout is `fullscreen`, so
+ * Storybook adds none of its own), except stories that set the `pageFrame`
+ * parameter: they render a page frame that sizes itself to the viewport,
+ * such as AppShell's `100dvh` shell, which a gutter would push past the
+ * viewport, making the document scroll.
+ */
+export function storyPadding(parameters?: {pageFrame?: boolean}): number {
+ return parameters?.pageFrame === true ? 0 : 16;
+}
diff --git a/apps/storybook/stories/AppShell.stories.tsx b/apps/storybook/stories/AppShell.stories.tsx
index ab51291648..82a16a6c68 100644
--- a/apps/storybook/stories/AppShell.stories.tsx
+++ b/apps/storybook/stories/AppShell.stories.tsx
@@ -240,6 +240,8 @@ const meta: Meta<typeof AppShell> = {
tags: ['autodocs'],
parameters: {
layout: 'fullscreen',
+ // AppShell sizes itself to the viewport: no story gutter around it.
+ pageFrame: true,
},
argTypes: {
height: {