mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Workaround bug in react-docgen-typescript
with string values
This commit is contained in:
parent
5a61260abc
commit
e189c89f0a
@ -18,11 +18,20 @@ function createType(type: DocgenType) {
|
||||
return type != null ? createSummaryValue(type.name) : null;
|
||||
}
|
||||
|
||||
function createDefaultValue(defaultValue: DocgenPropDefaultValue): PropDefaultValue {
|
||||
function createDefaultValue(
|
||||
defaultValue: DocgenPropDefaultValue,
|
||||
type: DocgenType
|
||||
): PropDefaultValue {
|
||||
if (defaultValue != null) {
|
||||
const { value } = defaultValue;
|
||||
const { value, computed } = defaultValue;
|
||||
|
||||
if (!isDefaultValueBlacklisted(value)) {
|
||||
// Work around a bug in `react-docgen-typescript-loader`, which returns 'string' for a string
|
||||
// default, instead of "'string'" -- which is incorrect (PR to RDT to follow)
|
||||
if (typeof computed === 'undefined' && type.name === 'string') {
|
||||
return createSummaryValue(JSON.stringify(value));
|
||||
}
|
||||
|
||||
return createSummaryValue(value);
|
||||
}
|
||||
}
|
||||
@ -38,7 +47,7 @@ function createBasicPropDef(name: string, type: DocgenType, docgenInfo: DocgenIn
|
||||
type: createType(type),
|
||||
required,
|
||||
description,
|
||||
defaultValue: createDefaultValue(defaultValue),
|
||||
defaultValue: createDefaultValue(defaultValue, type),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ export interface DocgenTypeScriptType extends DocgenType {}
|
||||
|
||||
export interface DocgenPropDefaultValue {
|
||||
value: string;
|
||||
computed?: boolean;
|
||||
}
|
||||
|
||||
export interface DocgenInfo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user