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

addon-docs + typescript does not pick up default props #11026

Closed
youfoundron opened this issue Jun 3, 2020 · 9 comments
Closed

addon-docs + typescript does not pick up default props #11026

youfoundron opened this issue Jun 3, 2020 · 9 comments

Comments

@youfoundron
Copy link

Describe the bug
Default props are not picked up by the @storybook/addon-docs addon when using typescript.

To Reproduce
Steps to reproduce the behavior:

  1. Install latest storybook and addon-docs modules.
  2. Setup a functional component with a default prop and a story for the component.
  3. Run storybook and navigate to the props table in docs.
  4. Note the Default column is empty for the property with a default value specified.

Expected behavior
Expect Default column to be populated based on React functional component definition per page 7 of the args RFC

Screenshots
Screen Shot 2020-06-03 at 12 42 56 AM

Code snippets

/* button.tsx */
import React from 'react'
import cn from 'classnames'

export interface Props {
  label?: string;
  bgColor: string;
  textColor: string;
}

export const Button: React.FC<Props> = ({
  label = 'Submit',
  bgColor,
  textColor,
  ...rest
}) => {
  return (
    <button
      className={cn(
        `text-${textColor}`,
        `bg-${bgColor}-500`,
        `hover:bg-${bgColor}-700`,
      )}
      {...rest}
    >
      {label}
    </button>
  );
};
/* button.stories.tsx */

import React from 'react'
import { actions } from '@storybook/addon-actions'
import { Button, Props as ButtonProps } from './base'

export default {
  title: 'Button',
  component: Button
}

export const basic = (_args: ButtonProps) => {
  const { label, bgColor, textColor, ...rest } = _args
  return (
    <Button
      label={label}
      bgColor={bgColor}
      textColor={textColor}
      {...rest}
    />
  )
}
basic.args = {
  label: 'Hello World',
  bgColor: 'blue',
  textColor: 'white',
  ...actions('onClick', 'onMouseOver')
};

System:

Environment Info:

  System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
  Binaries:
    Node: 14.3.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  Browsers:
    Safari: 13.1.1
  npmPackages:
    @storybook/addon-actions: 6.0.0-beta.20 => 6.0.0-beta.20
    @storybook/addon-controls: 6.0.0-beta.20 => 6.0.0-beta.20
    @storybook/addon-docs: 6.0.0-beta.20 => 6.0.0-beta.20
    @storybook/addon-links: 6.0.0-beta.20 => 6.0.0-beta.20
    @storybook/react: 6.0.0-beta.20 => 6.0.0-beta.20
@danielgamage
Copy link

I've been having trouble with this setup, too. You might get some mileage out of the following changes which I keep having to make to my components:

  export interface Props {
+   /** annotation */
    label?: string;
+   /** annotation */
    bgColor: string;
+   /** annotation */
    textColor: string;
  }

- export const Button: React.FC<Props> = ({
+ export const Button = ({ 
    label = 'Submit',
    bgColor,
    textColor,
    ...rest
- }) => {
+ }: Props) => {

@shilman
Copy link
Member

shilman commented Jul 4, 2020

cc @hipstersmoothie is there anything we can do about this on the react-docgen-typescript side?

@hipstersmoothie
Copy link
Contributor

I think this might have been fixed already. react-docgen-typescript supports this and has tests to show it. I think this should have been fixed with #11184 which went out in beta 31

@shilman
Copy link
Member

shilman commented Jul 4, 2020

You rock @hipstersmoothie. @youfoundron can you try upgrading?

@stale
Copy link

stale bot commented Jul 25, 2020

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!

@stale stale bot added the inactive label Jul 25, 2020
@dgreene1
Copy link

@youfoundron can you try upgrading?

I think he wants you to try the newest storybook beta/alpha

@stale stale bot removed the inactive label Jul 25, 2020
@shilman
Copy link
Member

shilman commented Jul 25, 2020

npx sb@next upgrade --prerelease

@stale
Copy link

stale bot commented Aug 16, 2020

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!

@stale stale bot added the inactive label Aug 16, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Sep 20, 2020
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

5 participants