Skip to content

Commit 393ceb5

Browse files
adamwoodnzclaude
andcommitted
Charts: Move WPDS font-family host wrapper into the charts story decorator
The previous commit applied the WPDS body font via a decorator and CSS class in the shared Storybook preview. That worked but put charts-specific concerns into code shared with every other package's stories. Move the host-app font-family wrapper into the charts package's own shared decorator (StoryChartProvider, which backs both chartDecorator and simpleChartDecorator). Charts stories now render inside a div with font-family: var(--wpds-font-family-body, system-ui, sans-serif) without touching the shared storybook preview.jsx or style.scss. Revert the shared Storybook changes from the previous commit so the host-app simulation lives entirely in the charts package. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e99b6e commit 393ceb5

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

projects/js-packages/charts/src/stories/chart-decorator.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,22 @@ const StoryChartProvider = ( {
160160
const providerKey = themeName === 'custom' ? `custom-${ sanitizedAccentColor }` : themeName;
161161

162162
return (
163-
<ThemeProvider color={ themeProviderColor }>
164-
<GlobalChartsProvider key={ providerKey } theme={ theme }>
165-
{ children }
166-
</GlobalChartsProvider>
167-
</ThemeProvider>
163+
<div
164+
/*
165+
Storybook acts as a WPDS-themed host application so charts
166+
inherit the design system body font through normal CSS
167+
cascade.
168+
*/
169+
style={ {
170+
fontFamily: 'var(--wpds-font-family-body, system-ui, sans-serif)',
171+
} }
172+
>
173+
<ThemeProvider color={ themeProviderColor }>
174+
<GlobalChartsProvider key={ providerKey } theme={ theme }>
175+
{ children }
176+
</GlobalChartsProvider>
177+
</ThemeProvider>
178+
</div>
168179
);
169180
};
170181

projects/js-packages/storybook/storybook/preview.jsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,11 @@ const preview = {
5656
backgrounds: { value: 'jetpack-dashboard' },
5757
},
5858
decorators: [
59-
( Story, context ) => {
60-
// Charts stories render inside a WPDS-themed wrapper so they
61-
// inherit the design system body font through normal CSS cascade.
62-
// Chart components intentionally do not declare font-family at
63-
// their root — they rely on the host application to provide it.
64-
const isChartsStory = context.title?.startsWith( 'JS Packages/Charts Library' );
65-
const content = <Story />;
66-
return (
67-
<ThemeProvider id="storybook-stories" targetDom={ document.body }>
68-
{ isChartsStory ? <div className="charts-storybook-host">{ content }</div> : content }
69-
</ThemeProvider>
70-
);
71-
},
59+
Story => (
60+
<ThemeProvider id="storybook-stories" targetDom={ document.body }>
61+
<Story />
62+
</ThemeProvider>
63+
),
7264
],
7365
tags: [ 'autodocs' ],
7466
};

projects/js-packages/storybook/storybook/style.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,3 @@
77
@import "@wordpress/block-library/build-style/style.css";
88
@import "@wordpress/block-library/build-style/theme.css";
99
@import "@wordpress/block-library/build-style/editor.css";
10-
11-
// Charts stories are wrapped by a decorator in preview.jsx that applies
12-
// this class, so the Charts Library renders as if it were inside a
13-
// WPDS-themed host application (inheriting the design system body font
14-
// through normal CSS cascade, rather than each chart declaring
15-
// font-family at its root).
16-
.charts-storybook-host {
17-
font-family: var(--wpds-font-family-body, system-ui, sans-serif);
18-
}

0 commit comments

Comments
 (0)