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

Wrapped components will not display prop types #177

Open
robcaldecottvelo opened this issue Jun 13, 2019 · 5 comments
Open

Wrapped components will not display prop types #177

robcaldecottvelo opened this issue Jun 13, 2019 · 5 comments

Comments

@robcaldecottvelo
Copy link

Many of our stories wrap an actual component in order to provide some local state, but this stops the component props table from appearing.

For example:

MyInput.propTypes = {
  /** The current value. */
  value: PropTypes.string,
  /** Called when the value is changed. */
  onChange: PropTypes.func
};

function MyInput(props) {
  return <input value={props.value} onChange={props.onChange />
}

export { MyInput };
# MyInput

<!-- PROPS -->
import React from "react";
import { storiesOf } from "@storybook/react";
import { MyInput } from "./MyInput";
import readme from "./README.md";

storiesOf("MyComponent", module)
  .addParameters({
    readme: {
      content: readme
    }
  }),
  add("controlled", () => {
    function Story() {
      const [value, setValue] = React.useState("");
      return <MyInput value={value} onChange={event => setValue(event.target.value)} />
    }
    return <Story />;
  }

In the above example no props are displayed because of the wrapper Story component used for the local state. I have tried using includePropTables: [MyInput] but it still won't work.

However, if I change the story to render the MyInput component directly then the props will appear.

Is there any way to coerce this add-on into picking up the actual component props?

@robcaldecottvelo robcaldecottvelo changed the title Wrapped components not display prop types Wrapped components will not display prop types Jun 13, 2019
@lonyele
Copy link
Collaborator

lonyele commented Jun 14, 2019

@robcaldecottvelo Sadly, It has many restrictions covering practical usages. If you have time, git clone this repo and yarn storybook-react you can see the examples of propTable. I explained a little bit about the current situations. Or you can see this one

Btw this one is coming, I feel like it can make this propTable feature more usable.

@cadebward
Copy link

@lonyele similar to the includePropTables PR #163, would it be possible to make something like forcedPropTables which would bypass all previous prop table logic and force the prop table to render based on the passed component? Something like:

.add('Example Story', () => (
  <SomeWrappedComponent />
), readme: { forcedPropTables: [ActualComponentTableThatRenders] })

@lonyele
Copy link
Collaborator

lonyele commented Jun 18, 2019

@cadebward Yeap, that is also on the feature request list! Once @tuchk4 gives me feedbacks on the comments from #170 , #171, I could make it happen(Though It seems he is busy)

FYI below are the comments that can give you more context on this matter

#169 (comment)

...I think changing the logic of includePropTables to not only filter but also add propTables is needed. Currently we filter propTables, but for these cases, we need to add it...

#170 (comment)

...or showing whatever propTables if it is specified

@tuchk4
Copy link
Owner

tuchk4 commented Jun 18, 2019

@lonyele I think we can add docs your wrote at example to the docs or separated md file and link it from main README.

I think we could start to implement #171 and as the result we will have full control on used React components and seems it will be possible to implement this feature.

@alexcracea
Copy link

@lonyele @tuchk4 any news on this?

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