-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Defaults in props tables when using typescript #9997
Comments
@thany, defaults work for me most of the time with TypeScript. If I have code like this: I get output like this: As you can see, the default value for I'm using the |
I can't write all of my component with destructured props. Sometimes I need the individual props, as well as the whole Example: const FormControl: React.FC<IFocusableFormControl> = props => {
const {
children,
error = false,
...rest
} = props; I could add The reason that this is a feature request and not a bug, is because there's no apparant way to explicitly manage default values for component props. The only way is for Storybook to figure out "implicit" defaults. There's no way to control the defaults it finds, other than by changing the meaning of the code that it analyzes. |
On top of this, some props that are passed on straight to, say, a styled-component that have a default value there, isn't picked up either. That's another good reason to have some feature to explicitly manage default values. Example: const Base = styled.div<MyComponentProps>`
color: ${({color = 'red'}) => color};
`;
const MyComponent: React.FC<MyComponentProps> = ({
enabled = true,
...rest
}) => {
return <Base {...rest} />;
}; In the above example, the color is defaulted to |
@thany should be coming in the next week or two as part of 6.0 props overhaul |
Very cool! 😎 |
Current estimate is May 4. I try to keep this issue updated: #9311 |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
FYI the recommended 6.0 setup (should work in 5.3 too) is ready, and is the default in the most recent versions of both https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-prop-tables-with-typescript I am commenting on all props-related issues to request that you upgrade so we can get this right before release. Thanks! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Args-based props tables are available in 6.0 alpha https://gist.github.com/shilman/69c1dd41a466bae137cc88bd2c6ef487 |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
@shilman I've never been able to get that working in 5.3, but I'm currently doing some research on upgrading to 6.0, and a cursory check reveals that it's most likely completely fixed for our use-cases 🎉 |
What happened to this? lol And what about, just let it take the JSDoc's
|
@default seems to be working for me ATM. |
We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if:
|
Is your feature request related to a problem? Please describe.
The props tables have a column "Default" which is almost always empty. Since I'm using typescript, I have no need for
propTypes
anddefaultProps
in my components. But I don't see a way to expose a default value for a prop to storybook. Defaults are either implied by the implementation, or they are in a destructuring of theprops
argument in aReact.FC<...>
component. But in either case, no default is displayed, even when there absolutely is one. And that's understandable, because it would require deep code analysis which is very error-prone.Describe the solution you'd like
Some way to tell Storybook default props values. Or maybe somehow get metadata from jsdoc (although there's no jsdoc-tag for a default value, afaik)
Describe alternatives you've considered
Moving back to javascript? And then use
propTypes
anddefaultProps
again? No really a viable alternative, tbh.Are you able to assist bring the feature to reality?
Depends on how you feel this should work, really.
Additional context
Just try not to analyze source code using some typescript parser. We've seen that failing already. Maybe work with the authors of jsdoc to get something going from that angle?
If jsdoc provides a solution, I imagine something like this:
Or similar. Currently I wouldn't know how else exposing default props values to storybook would be the best way.
The text was updated successfully, but these errors were encountered: