Skip to content

Commit

Permalink
Enable auto-title for non-storyStoreV7
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Feb 17, 2022
1 parent 0fa3956 commit c89b67d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/example-react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
builder: 'storybook-builder-vite',
},
features: {
storyStoreV7: true,
storyStoreV7: false,
},
async viteFinal(config, { configType }) {
// customize the Vite config here
Expand Down
1 change: 0 additions & 1 deletion packages/example-react/stories/Button.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button } from './Button';

export default {
title: 'Example/Button',
component: Button,
argTypes: {
backgroundColor: { control: 'color' },
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-builder-vite/input/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
window.FRAMEWORK_OPTIONS = '[FRAMEWORK_OPTIONS HERE]';
window.CHANNEL_OPTIONS = '[CHANNEL_OPTIONS HERE]';
window.FEATURES = '[FEATURES HERE]';
window.STORIES = '[STORIES HERE]';
window.SERVER_CHANNEL_URL = '[SERVER_CHANNEL_URL HERE]';

// We do this so that "module && module.hot" etc. in Storybook source code
Expand Down
15 changes: 11 additions & 4 deletions packages/storybook-builder-vite/transform-iframe-html.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { normalizeStories } from '@storybook/core-common';
import type { CoreConfig } from '@storybook/core-common';
import type { ExtendedOptions } from './types';

export type PreviewHtml = string | undefined;

export async function transformIframeHtml(
html: string,
{ configType, features, framework, presets, serverChannelUrl, title }: ExtendedOptions
) {
export async function transformIframeHtml(html: string, options: ExtendedOptions) {
const { configType, features, framework, presets, serverChannelUrl, title } = options;
const headHtmlSnippet = await presets.apply<PreviewHtml>('previewHead');
const bodyHtmlSnippet = await presets.apply<PreviewHtml>('previewBody');
const logLevel = await presets.apply('logLevel', undefined);
const frameworkOptions = await presets.apply(`${framework}Options`, {});
const coreOptions = await presets.apply<CoreConfig>('core');
const stories = normalizeStories(await options.presets.apply('stories', [], options), {
configDir: options.configDir,
workingDir: process.cwd(),
}).map((specifier) => ({
...specifier,
importPathMatcher: specifier.importPathMatcher.source,
}));

return html
.replace('<!-- [TITLE HERE] -->', title || 'Storybook')
Expand All @@ -23,6 +29,7 @@ export async function transformIframeHtml(
JSON.stringify(coreOptions && coreOptions.channelOptions ? coreOptions.channelOptions : {})
)
.replace(`'[FEATURES HERE]'`, JSON.stringify(features || {}))
.replace(`'[STORIES HERE]'`, JSON.stringify(stories || {}))
.replace(`'[SERVER_CHANNEL_URL HERE]'`, JSON.stringify(serverChannelUrl))
.replace('<!-- [HEAD HTML SNIPPET HERE] -->', headHtmlSnippet || '')
.replace('<!-- [BODY HTML SNIPPET HERE] -->', bodyHtmlSnippet || '');
Expand Down

0 comments on commit c89b67d

Please sign in to comment.