Skip to content

Commit

Permalink
fix: Ensure shape prop types adhere to nested enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 8, 2020
1 parent 0d5fb69 commit 7924a7e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/utils/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const getDefaultValue = (component, propTypeName) => {
return defaultValue;
};

export const getTypeMeta = (name, propType, { component }) => {
export const getTypeMeta = (name, propType, { component, prefix }) => {
const propTypeDocs = propType.__docs__;

switch (getRawTypeName(propType)) {
Expand All @@ -105,13 +105,17 @@ export const getTypeMeta = (name, propType, { component }) => {
const [shape] = getArgs(propType);

return {
types: Object.entries(shape).map(([name, propType]) =>
getPropTypeDefinition(component, name, propType)
types: Object.entries(shape).map(([shapePropName, propType]) =>
getPropTypeDefinition(component, shapePropName, propType, {
prefix: name,
})
),
};
}
case 'oneOf': {
const staticProperty = toStaticPropertyName(name);
const staticProperty = toStaticPropertyName(
prefix ? `${prefix}.${name}` : name
);

return {
constants: Object.keys(component[staticProperty] ?? {}).map(
Expand Down Expand Up @@ -146,7 +150,12 @@ export const getTypeMeta = (name, propType, { component }) => {
}
};

export const getPropTypeDefinition = (component, name, propType) => {
export const getPropTypeDefinition = (
component,
name,
propType,
{ prefix } = {}
) => {
const propDocs = propType.__docs__;
const propMeta = propType.__reflect__;

Expand All @@ -158,7 +167,7 @@ export const getPropTypeDefinition = (component, name, propType) => {
isRequired: propMeta?.some((item) => item.name === 'isRequired') ?? false,
examples: propDocs?.tags?.examples ?? [],
type: {
meta: getTypeMeta(name, propType, { component }),
meta: getTypeMeta(name, propType, { component, prefix }),
raw: getRawTypeName(propType),
name: getNormalizedTypeName(propType),
},
Expand Down

0 comments on commit 7924a7e

Please sign in to comment.