mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 16:11:33 +08:00
Delete extractArgTypes.ts
This commit is contained in:
parent
8dc1320306
commit
6cfa8b9c44
@ -1,42 +0,0 @@
|
|||||||
import { ArgTypes } from '@storybook/api';
|
|
||||||
import { ArgTypesExtractor, hasDocgen, extractComponentProps } from '../../lib/docgen';
|
|
||||||
import { convert } from '../../lib/convert';
|
|
||||||
import { trimQuotes } from '../../lib/convert/utils';
|
|
||||||
|
|
||||||
const SECTIONS = ['props', 'events', 'slots'];
|
|
||||||
|
|
||||||
const trim = (val: any) => (val && typeof val === 'string' ? trimQuotes(val) : val);
|
|
||||||
|
|
||||||
export const extractArgTypes: ArgTypesExtractor = (component) => {
|
|
||||||
if (!hasDocgen(component)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const results: ArgTypes = {};
|
|
||||||
SECTIONS.forEach((section) => {
|
|
||||||
const props = extractComponentProps(component, section);
|
|
||||||
props.forEach(({ propDef, docgenInfo, jsDocTags }) => {
|
|
||||||
const { name, type, description, defaultValue: defaultSummary, required } = propDef;
|
|
||||||
const sbType = section === 'props' ? convert(docgenInfo) : { name: 'void' };
|
|
||||||
let defaultValue = defaultSummary && (defaultSummary.detail || defaultSummary.summary);
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line no-eval
|
|
||||||
defaultValue = eval(defaultValue);
|
|
||||||
// eslint-disable-next-line no-empty
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
results[name] = {
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
type: { required, ...sbType },
|
|
||||||
defaultValue,
|
|
||||||
table: {
|
|
||||||
type,
|
|
||||||
jsDocTags,
|
|
||||||
defaultValue: defaultSummary,
|
|
||||||
category: section,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return results;
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user