-
-
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
Addon-knobs: Add object[] support for select #7957
Addon-knobs: Add object[] support for select #7957
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/storybook/monorepo/f59tdv1gj |
@shilman I was wondering why there is a |
@matthewliuswims Sorry I forgot to explain. We're in the final stages of 5.2 release, so we're not merging any features until that's out (Sep 16 target). Making this explicit with the label since we're a distributed team and it's hard to coordinate. |
@shilman understood. Thank you :) |
@shilman congrats on the 5.2 release! now that it's out, would it be possible to get this PR reviewed + remove the do not merge tag? edit: I see there was a merge conflict, let me resolve it real quick first |
6778c6a
to
9c29266
Compare
Ah, right good point, the knob functions return values can be reached into
/ manipulated before using that data as a prop.
👍
…On Thu, Dec 5, 2019 at 10:28 PM matthewliuswims ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In addons/knobs/src/components/types/Select.tsx
<#7957 (comment)>
:
>
- const selectedKey = Object.keys(entries).find(k => {
- if (Array.isArray(knob.value)) {
- return JSON.stringify(entries[k]) === JSON.stringify(knob.value);
+ const callbackReduceArrayOptions = (acc: any, option: any, i: number) => {
+ if (typeof option !== 'object') return { ...acc, [option]: option };
+ const label = option.label || option.key || i;
+ return { ...acc, [label]: option };
+ };
Does this mean that my objects need to have a label or key attribute to
have a display value?
1.
there's a fallback const label = option.label || option.key || i; to
the index (i.e. i). So it'll always work (label might just not look
very nice) if a user chooses to not pass a label or key.
2.
Also, the label or key would just need to be passed in on the
storybook level (react logic does NOT need to have a label). In fact: you
show a great example of how to do this in your code snippet!
// using your `arrayOfObjects` example
const dogInfo = select(<label>, arrayOfObjects).data // notice we use.data`
// pass dogInfo to react object.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7957?email_source=notifications&email_token=AAHDOBAKRX227N235U2CZNDQXHIHBA5CNFSM4ISZUY5KYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCOGMIWQ#discussion_r354661699>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHDOBD6S5GD6PGM5V4AJK3QXHIHBANCNFSM4ISZUY5A>
.
|
Issue: #810 (was closed long ago). I may be misinterpreting the post, but when OP said he desired his options to look like below
I thought that was for (or included) the
select
knob. However, I was surprised to see that theselect
knob still could NOT take options as an array of objects (only an array of strings). Thus....What I did
select
knob can take in an array OF objects.How to test
in
official-storybook/stories/addon-knobs/with-knobs.stories.js
I added an example for testing purposes and documentation.