mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
add ts 4.9 snippets.
This commit is contained in:
parent
ade1681e15
commit
ab79dfcb79
@ -1,4 +1,3 @@
|
||||
export { render, renderToCanvas } from './render';
|
||||
|
||||
export const parameters = { renderer: 'server' as const };
|
||||
export default {};
|
||||
|
@ -0,0 +1,38 @@
|
||||
```ts
|
||||
// .storybook/main.ts
|
||||
|
||||
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
|
||||
import type { StorybookConfig } from '@storybook/your-framework';
|
||||
import type { Indexer } from '@storybook/types';
|
||||
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
const jsonStoriesIndexer: Indexer = {
|
||||
test: /stories\.json$/,
|
||||
createIndex: async (fileName) => {
|
||||
const content = JSON.parse(fs.readFileSync(fileName));
|
||||
|
||||
const stories = generateStoryIndexesFromJson(content);
|
||||
|
||||
return stories.map((story) => {
|
||||
type: 'story',
|
||||
importPath: `virtual:jsonstories--${fileName}--${story.componentName}`,
|
||||
exportName: story.exportName
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const config: StorybookConfig = {
|
||||
framework: '@storybook/your-framework',
|
||||
stories: [
|
||||
'../src/**/*.mdx',
|
||||
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
||||
// 👇 Make sure files to index are included in `stories`
|
||||
'../src/**/*.stories.json',
|
||||
],
|
||||
experimental_indexers: async (existingIndexers) => [...existingIndexers, jsonStoriesIndexer];
|
||||
};
|
||||
|
||||
export default config;
|
||||
```
|
33
docs/snippets/common/main-config-indexers-title.ts-4-9.mdx
Normal file
33
docs/snippets/common/main-config-indexers-title.ts-4-9.mdx
Normal file
@ -0,0 +1,33 @@
|
||||
```ts
|
||||
// .storybook/main.ts
|
||||
|
||||
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
|
||||
import type { StorybookConfig } from '@storybook/your-framework';
|
||||
import type { Indexer } from '@storybook/types';
|
||||
|
||||
const combosIndexer: Indexer = {
|
||||
test: /\.stories\.[tj]sx?$/,
|
||||
createIndex: async (fileName, { makeTitle }) => {
|
||||
// 👇 Grab title from fileName
|
||||
const title = fileName.match(/\/(.*)\.stories/)[1];
|
||||
|
||||
// Read file and generate entries ...
|
||||
|
||||
return entries.map((entry) => ({
|
||||
type: 'story',
|
||||
// 👇 Use makeTitle to format the title
|
||||
title: `${makeTitle(title)} Custom`,
|
||||
importPath: fileName,
|
||||
exportName: entry.name,
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
const config: StorybookConfig = {
|
||||
framework: '@storybook/your-framework',
|
||||
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
|
||||
experimental_indexers: async (existingIndexers) => [...existingIndexers, combosIndexer];
|
||||
};
|
||||
|
||||
export default config;
|
||||
```
|
25
docs/snippets/common/main-config-indexers.ts-4-9.mdx
Normal file
25
docs/snippets/common/main-config-indexers.ts-4-9.mdx
Normal file
@ -0,0 +1,25 @@
|
||||
```ts
|
||||
// .storybook/main.ts
|
||||
|
||||
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
|
||||
import type { StorybookConfig } from '@storybook/your-framework';
|
||||
|
||||
const config: StorybookConfig = {
|
||||
framework: '@storybook/your-framework',
|
||||
stories: [
|
||||
'../src/**/*.mdx',
|
||||
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
||||
// 👇 Make sure files to index are included in `stories`
|
||||
'../src/**/*.custom-stories.@(js|jsx|ts|tsx)',
|
||||
],
|
||||
experimental_indexers: async (existingIndexers) => {
|
||||
const customIndexer = {
|
||||
test: /\.custom-stories\.[tj]sx?$/,
|
||||
createIndex: // See API and examples below...
|
||||
};
|
||||
return [...existingIndexers, customIndexer];
|
||||
},
|
||||
};
|
||||
|
||||
export default config
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user