-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If your setup is that you write your Docs with mdx manually, you would need to have a Canvas-Block and a Controls-Block for every story. Writing MDX. Jump directly to the Autodocs explanation further down if you don't write docs pages in mdx. Example MDX: {/* Checkbox.mdx */}
import { Canvas, Controls, Subheading } from '@storybook/blocks';
import * as CheckboxStories from './Checkbox.stories';
<Subheading>Unchecked</Subheading>
<Canvas of={CheckboxStories.Unchecked} />
<Controls of={CheckboxStories.Unchecked} />
<Subheading>Unchecked</Subheading>
<Canvas of={CheckboxStories.Checked} />
<Controls of={CheckboxStories.Checked} include={['label']} exclude={['background']} />
//and so on ... If I understand you correctly, you want only show the args you've set for that specific story, not all possible components args (like the default controls-block does it). Then you can set these strings in the exclude or include property of the controls block in the mdx, see above. Sometimes, its better to organize this directly at the meta or story level, just set there
But, instead of writing all that stuff manually, you can create a react component that handles all that logic. Works in Storybook-Angular, too. While you could use that component in mdx directly, the easiest is to define a docs-page-template for your use case. You can customize the DocsPage, see Documentation. You can set this template at the preview(project), meta or story level for parameters.docs.page: myPageTemplate ... i also had shown another example of some customized autodocs in #29156 for more explanation. Here is some example to insert to handle all that logic programmatically (show heading, story-description, canvas, and a controls block which only includes the args explicitly defined at the meta or the specific story level): import {
Subheading,
Meta,
DocsContext,
Controls,
Title,
Source,
Markdown,
Canvas,
Description,
Heading,
} from '@storybook/blocks';
import React, { useContext } from 'react';
export const AutoDocsControls: React.FC = () => {
const { componentStories, projectAnnotations, getStoryContext } =
useContext(DocsContext);
// Get all csf file stories
let stories = componentStories();
// base filter all csf file stories
const { stories: { filter } = { filter: undefined } } =
projectAnnotations.parameters?.['docs'] || {};
if (filter) {
stories = stories.filter((story) => filter(story, getStoryContext(story)));
}
// Filter to only include stories with 'autodocs' tags
stories = stories.filter(
(story) => story.tags?.includes('autodocs') && !story.usesMount
);
return (
<>
<Meta />
<Title />
<Description />
<Heading>Stories</Heading>
<div>
{stories.map(
(story) =>
story && (
<>
<Subheading>{story?.name || ''}</Subheading>
<Markdown>
{story.parameters['docs']?.description?.story || ''}
</Markdown>
<Canvas key={story.id} of={story.moduleExport} />
<Controls
key={story.id}
of={story.moduleExport}
include={[
...(story.initialArgs
? Object.keys(story.initialArgs)
: []),
]}
/>
</>
)
)}
</div>
<Source />
</>
);
}; Hope this helps a bit! PS: If you dont want to show some auto generated args in the controls tables (like private, protected properties, properties with internal tag (or just set at: ignore in the jsdoc) or angular lifecycle properties like ngOnInit, just add these flags to the compodoc options in angular.json: --disablePrivate | Do not show private in generated documentation |
Beta Was this translation helpful? Give feedback.
If your setup is that you write your Docs with mdx manually, you would need to have a Canvas-Block and a Controls-Block for every story. Writing MDX. Jump directly to the Autodocs explanation further down if you don't write docs pages in mdx.
Example MDX: