Skip to content

Commit

Permalink
feat: Implement meta info for arrayOf types
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 7, 2020
1 parent 650818a commit b05948b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils/__tests__/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,22 @@ describe('getTypeMeta', () => {
],
});
});

test('returns nested type info for arrayOf types', () => {
const propType = createPropType('arrayOf', [createPropType('string')]);

const component = {
propTypes: {
names: propType,
},
};

expect(getTypeMeta('names', propType, { component })).toEqual({
itemTypes: {
meta: null,
raw: 'string',
name: 'string',
},
});
});
});
11 changes: 11 additions & 0 deletions src/utils/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ export const getTypeMeta = (name, propType, { component }) => {
),
};
}
case 'arrayOf': {
const [arrayOfPropType] = getArgs(propType);

return {
itemTypes: {
meta: getTypeMeta(name, arrayOfPropType, { component }),
raw: getRawTypeName(arrayOfPropType),
name: getNormalizedTypeName(arrayOfPropType),
},
};
}
default:
return null;
}
Expand Down

0 comments on commit b05948b

Please sign in to comment.