diff --git a/docs/configure/sidebar-and-urls.md b/docs/configure/sidebar-and-urls.md index 774d47fabf7d..f49f7a3c66ba 100644 --- a/docs/configure/sidebar-and-urls.md +++ b/docs/configure/sidebar-and-urls.md @@ -26,21 +26,47 @@ If you’d prefer to show top-level nodes as folders rather than roots, you can -## Generating titles based on `__dirname` +## Automatically generate titles -As a CSF file is a JavaScript file, all exports (including the default export) can be generated dynamically. In particular you can use the `__dirname` variable to create the title based on the path name (this example uses the paths.macro): +With CSF 3.0 files, you can choose to leave out a title and let it be inferred from the story's path on disk instead: -If you need, you can also generate automatic titles for all your stories using a configuration object. See the [story loading](./overview.md#with-a-configuration-object) documentation to learn how you can use this feature. +This is controlled by the way your stories are configured: + + + + + + + +Given this configuration, the stories file `../src/components/MyComponent.stories.tsx` will get the title `components/MyComponent`. + +You can further customize the generated title by modifying the stories configuration. + + + + + + + +This configuration would match a custom file pattern, and add a custom prefix of Foo to each generated title. ## Permalinking to stories diff --git a/docs/snippets/common/component-story-auto-title.js.mdx b/docs/snippets/common/component-story-auto-title.js.mdx new file mode 100644 index 000000000000..33b7a49872bc --- /dev/null +++ b/docs/snippets/common/component-story-auto-title.js.mdx @@ -0,0 +1,4 @@ +```js +// CSF 3.0 - MyComponent.stories.js|jsx|ts|tsx +export default { component: MyComponent } +``` \ No newline at end of file diff --git a/docs/snippets/common/component-story-configuration-custom.js.mdx b/docs/snippets/common/component-story-configuration-custom.js.mdx new file mode 100644 index 000000000000..7aa782a847ce --- /dev/null +++ b/docs/snippets/common/component-story-configuration-custom.js.mdx @@ -0,0 +1,8 @@ +```js +// ./storybook/main.js +module.exports = { + stories: [ + { directory: '../src', files: '*.story.tsx', titlePrefix: 'Foo' } + ] +}; +``` \ No newline at end of file diff --git a/docs/snippets/common/component-story-configuration.js.mdx b/docs/snippets/common/component-story-configuration.js.mdx new file mode 100644 index 000000000000..05df51e2c8a5 --- /dev/null +++ b/docs/snippets/common/component-story-configuration.js.mdx @@ -0,0 +1,6 @@ +```js +// ./storybook/main.js +module.exports = { + stories: ['../src'] +}; +``` \ No newline at end of file diff --git a/docs/snippets/common/component-story-dynamic-title.js.mdx b/docs/snippets/common/component-story-dynamic-title.js.mdx deleted file mode 100644 index da1e331e17bb..000000000000 --- a/docs/snippets/common/component-story-dynamic-title.js.mdx +++ /dev/null @@ -1,9 +0,0 @@ -```js -// MyComponent.stories.js|jsx|ts|tsx - -import base from 'paths.macro'; - -export default { - title: `${base}/Component` -} -``` \ No newline at end of file