Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show objects as objects and not strings within Props Tables (when using Typescript type definitions) #15347

Open
martinburford opened this issue Jun 24, 2021 · 2 comments

Comments

@martinburford
Copy link

martinburford commented Jun 24, 2021

Hi there,

When using PropTypes within a React component, props which contain objects are rendered like this, showing key/value pairs in a tabulated format:

001

When switching over to TypeScript and providing type definitions via interfaces, objects get shown as strings, like this:

002

The interface I'm using is nothing more than this:

Screenshot 2021-06-24 at 12 42 14

My question is ... how can I get a similar format for objects (as shown when defined via PropTypes) within Props tables when defining types via Typescript interfaces and to NOT have them returned as strings. With a bit of nesting, a single string of key/value pairs gets quite unreadable pretty quickly.

I am having PropsTables defined via this code in my story files:

import Image from '../';

<Props of={Image} />
@martinburford
Copy link
Author

martinburford commented Jun 25, 2021

The current implementation (understandably) truncates types defined via TypeScript. PLEASE update this to include some kind of prettified formatting of objects defined this way. It's largely unreadable in this format. Many thanks!

Screenshot 2021-06-25 at 11 23 59

@MondaySam
Copy link

MondaySam commented Jun 28, 2021

I think I stumbled upon a related issue concerning PropTypes and imported Objects.

In my Button.js I am using PropTypes.oneOf(Object.values(BTN_SIZES))
with const BTN_SIZES = {SMALL: 'small', REGULAR: 'regular', LARGE: 'large'}

Now, if that BTN_SIZES Object is defined within my Button.js, everything is fine.
However, if I define and export the BTN_SIZES in another class, and import it into Button.js,
Storybook no longer returns a list of the entries, but a Dropdown with just numbers from 0 to X, where X equals the number of characters within the PropTypes.oneOf()-Bracket.
So it treats Object.values(BTN_SIZES) as a String.

@shilman shilman removed the PN label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants