diff --git a/src/utils/__tests__/propTypeInfo.js b/src/utils/__tests__/propTypeInfo.js index f569a4c34..140621b58 100644 --- a/src/utils/__tests__/propTypeInfo.js +++ b/src/utils/__tests__/propTypeInfo.js @@ -360,4 +360,30 @@ describe('getTypeMeta', () => { ], }); }); + + test('returns constants for enum types', () => { + const SIZE = { + SMALL: 'sm', + MEDIUM: 'md', + LARGE: 'lg', + }; + + const propType = createPropType('oneOf', [Object.values(SIZE)]); + + const component = { + name: 'Button', + propTypes: { + size: propType, + }, + SIZE, + }; + + expect(getTypeMeta('size', propType, { component })).toEqual({ + constants: [ + 'Button.SIZE.SMALL', + 'Button.SIZE.MEDIUM', + 'Button.SIZE.LARGE', + ], + }); + }); }); diff --git a/src/utils/propTypeInfo.js b/src/utils/propTypeInfo.js index fd5615df0..f5048304b 100644 --- a/src/utils/propTypeInfo.js +++ b/src/utils/propTypeInfo.js @@ -110,6 +110,15 @@ export const getTypeMeta = (name, propType, { component }) => { ), }; } + case 'oneOf': { + const staticProperty = toStaticPropertyName(name); + + return { + constants: Object.keys(component[staticProperty] ?? {}).map( + (name) => `${component.name}.${staticProperty}.${name}` + ), + }; + } default: return null; }