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

Add support for array of objects #810

Closed
shilman opened this issue Apr 15, 2017 · 19 comments
Closed

Add support for array of objects #810

shilman opened this issue Apr 15, 2017 · 19 comments

Comments

@shilman
Copy link
Member

shilman commented Apr 15, 2017

Issue by royair
Wednesday Mar 29, 2017 at 18:09 GMT
Originally opened as storybook-eol/storybook-addon-knobs#94


@shilman
Copy link
Member Author

shilman commented Apr 15, 2017

Comment by UsulPro
Wednesday Mar 29, 2017 at 18:19 GMT


@royair isn't object what are you looking for?

@shilman
Copy link
Member Author

shilman commented Apr 15, 2017

Comment by royair
Wednesday Mar 29, 2017 at 18:27 GMT


my options param looks like this:

var OPTIONS = [
  {
    eventKey: "1",
    label: "Banana",
    subtext: "they are tasty"
  },
  {
    eventKey: "2",
    label: "Apple",
    subtext: "they are healthy"
  },
  {
    eventKey: "3",
    label: "Peach",
    subtext: "they are beautiful"
  }
];

@mcmunder
Copy link
Contributor

mcmunder commented Jul 7, 2017

Is anyone working on this? Seems like such an obvious feature to support?!

@ndelangen
Copy link
Member

Related: #799 #1296 #805

I agree this should be addressed, it would make knobs a lot more valuable!

Would you be interested in making a PR @royair @mcmunder ?

@mcmunder
Copy link
Contributor

I'll give it a try!

@ndelangen
Copy link
Member

ndelangen commented Jul 19, 2017

AWESOME, let me know if there's something I can help with 👍

@byrekt
Copy link

byrekt commented Jul 27, 2017

I think you can actually just use object to handle an array of objects:
e.g.
const footnotes = object('Footnotes', [{symbol: 1, content: 'sample'}]);

seems to work for me

@ndelangen
Copy link
Member

@byrekt I can imagine that's good for lots of cases!

@tibbus
Copy link

tibbus commented Jul 31, 2017

You can use it as @byrekt suggest, but React will complain about the types :
**Warning**: Failed prop type: Invalid prop **knob.value** of type **array** supplied to **ObjectType**, expected **object**

A workaround is to create a wrapper component:

const optionsWrapper = {
  options: [
    {
      eventKey: '1',
      label: 'Banana',
      subtext: 'they are tasty'
    },
    {
      eventKey: '2',
      label: 'Apple',
      subtext: 'they are healthy'
    },
    {
      eventKey: '3',
      label: 'Peach',
      subtext: 'they are beautiful'
    }
  ]
};

class MyComponentWrapper extends React.Component {
  render() {
    return <Header {...{ ...this.props, options: this.props.optionsWrapper.options }} />;
  }
}

storiesOf('MyComponent', module).add('default', () => {
  return <MyComponentWrapper options={object('options', optionsWrapper)} />
});

@Hypnosphi
Copy link
Member

Yeah, I think we should update the propType

@vipulbhavsar94
Copy link

vipulbhavsar94 commented Aug 21, 2017

@mcmunder Any updates on this, kind of critical thing for me.

@tibbus
Copy link

tibbus commented Aug 21, 2017

@vipulbhavsar94 Should not be critical, you can use my workaround until is fixed.

@ilyaskhametov
Copy link

I found another way to make array of objects, don't know if it's a right way. This is an example of story for Socials component, which takes an array of objects with information about each social (name, href) and displays it as list:

const socials = [
    {
        name: 'twitter',
        href: 'https://twitter.com/',
    },
    {
        name: 'facebook',
        href: 'https://facebook.com/',
    }
]

const props = {
    socials: [
        object('Twitter', socials[0]),
        object('Facebook', socials[1])
    ]
}

return <Socials {...props} />

@Hypnosphi
Copy link
Member

@illyon nice solution! Works good when you have a fixed set of expected objects

@stale
Copy link

stale bot commented Nov 13, 2017

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. We do try to do some housekeeping every once in a while so inactive issues will get closed after 60 days. Thanks!

@stale stale bot added the inactive label Nov 13, 2017
@Hypnosphi
Copy link
Member

Fixed in 3.2.15

@shilman
Copy link
Member Author

shilman commented Nov 14, 2019

Great Caesar's ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.45 containing PR #7957 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

@HoplaGeiss
Copy link

Naive question - Is this fix also implemented for @storybook/angular?

@shilman
Copy link
Member Author

shilman commented Jan 23, 2020

@HoplaGeiss yeah, it's a knob thing, so should be framework-independent

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

10 participants