-
SummaryI have a class similar to this one:
And a sample story:
I'm currently using html-vite framework, but I'm wondering if that's the correct framework to use? I'm looking to get autodocs to generate args and argTypes automatically based on the SimpleComponent constructor arguments? However it seems I currently need to manually re-specify all the args and argTypes in the story file, rather than autodocs automatically picking them up from the source Typescript file. Is it just not supported to have Vanille -no-framework files used with autodocs? Additional informationstorybook v8.2.9 main.ts:
preview.ts
Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The way argTypes are parsed is unique to the individual frameworks, since different frameworks define inputs/outputs differently. Unless I just don't know what framework/pattern that you are using, you seem to be using a custom object structure that is unique to your classes. So, I don't expect there to be a an existing solution that you could just drop in. You may be able to just tweak one for your structure though, if one is close. I don't see the The closest framework that does implement argTypes parsing is maybe I don't think there is documentation on implementing the functions that hook the independent framework solutions for auto populated argTypes, but I was curious what all you would need to do and I wrote a very naive solution for the component that you provided. You would not want to actually use my solution, but if you are familiar with a typescript parsing tool then this may give you a starting point to implement your own solution. There are two functions, Here is the bad solution that I wrote for your // .storybook/preview.ts
import type { Preview } from '@storybook/html';
import { SourceType } from 'storybook/internal/docs-tools';
/**
* Very poorly written example, just to show idea.
*/
const extractArgTypes = (component: any) => {
const targetElement = document.createElement('div');
const tmp = new component(targetElement);
const keys = Object.keys(tmp.config);
const argTypes: any = {};
if (keys.length > 1) {
for (const k of keys) {
const type = typeof tmp.config[k];
if (type === 'string') {
argTypes[k] = {
type: { name: 'string' },
description: `Desc ${k}`,
};
} else if (type === 'boolean') {
argTypes[k] = {
type: { name: 'boolean' },
description: `Desc ${k}`,
};
}
}
}
return argTypes;
};
/**
* Very poorly written example, just to show idea.
*/
const extractComponentDescription = (component: any) => {
return `Component: ${component.name}`;
};
const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
extractArgTypes,
extractComponentDescription,
story: { inline: true },
source: {
type: SourceType.DYNAMIC,
language: 'html',
code: undefined,
excludeDecorators: undefined,
},
},
},
};
export default preview; Here is a Stackblitz for my bad, but working, solution: https://stackblitz.com/edit/github-8egspp |
Beta Was this translation helpful? Give feedback.
The way argTypes are parsed is unique to the individual frameworks, since different frameworks define inputs/outputs differently. Unless I just don't know what framework/pattern that you are using, you seem to be using a custom object structure that is unique to your classes. So, I don't expect there to be a an existing solution that you could just drop in. You may be able to just tweak one for your structure though, if one is close.
I don't see the
@storybook/html-vite
framework specifying functions to parse argTypes. A table listing the frameworks that do implement it is here: https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/props-tables.md#known-limitationsThe …