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

Knobs addon: new knob type button #2004

Merged
merged 13 commits into from
Oct 18, 2017

Conversation

derrickpelletier
Copy link
Contributor

Issue: #1914

What I did

  • added button knob to the knobs addon so users don't need to include buttons in their stories
  • added ability to hide the label, for button type (and maybe future types?) to render nicer.
  • added button example to cra-kitchen-sink and vue-kitchen-sink with-knobs examples
  • added button usage to addons/knobs/README.md

How to test

  • acccess either vue or cra kitchen sink examples

Is this testable with jest or storyshots?

  • I don't think so, unless I am missing something.

Does this need a new example in the kitchen sink apps?

  • done

Does this need an update to the documentation?

  • done

@codecov
Copy link

codecov bot commented Oct 10, 2017

Codecov Report

Merging #2004 into master will increase coverage by 0.05%.
The diff coverage is 37.5%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2004      +/-   ##
=========================================
+ Coverage   21.34%   21.4%   +0.05%     
=========================================
  Files         262     263       +1     
  Lines        5767    5793      +26     
  Branches      701     694       -7     
=========================================
+ Hits         1231    1240       +9     
- Misses       4002    4015      +13     
- Partials      534     538       +4
Impacted Files Coverage Δ
addons/knobs/src/components/PropForm.js 9.09% <ø> (+0.58%) ⬆️
addons/knobs/src/components/PropField.js 10.63% <0%> (-0.24%) ⬇️
addons/knobs/src/index.js 0% <0%> (ø) ⬆️
addons/knobs/src/vue/index.js 30% <25%> (-1.25%) ⬇️
addons/knobs/src/react/WrapStory.js 19.54% <28.57%> (-0.46%) ⬇️
addons/knobs/src/components/Panel.js 81.03% <50%> (-1.11%) ⬇️
addons/knobs/src/components/types/Button.js 55.55% <55.55%> (ø)
addons/info/src/components/PropVal.js 41.41% <0%> (ø) ⬆️
... and 26 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5457fdb...58e0860. Read the comment docs.

addons/knobs/src/react/WrapStory.js Outdated Show resolved Hide resolved
addons/knobs/README.md Outdated Show resolved Hide resolved
@Hypnosphi
Copy link
Member

Code LGTM. Still not sure this thing belongs to addon-knobs semantically

@derrickpelletier
Copy link
Contributor Author

Ok, who decides how to move forward then? @danielduan?

I can see where you're coming from, because it's functionally a bit different than inputs—but semantically it makes sense to me as a way to control or trigger behaviour in a story.

@danielduan
Copy link
Member

@ndelangen @shilman thoughts?

I definitely see why there's a need for this, but maybe this isn't a "knob"? perhaps it should be its own addon?

Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is good!

I'm struggling understanding the use-case, and I need better examples in order to let this merge.

As it is right now, I wouldn't know how to use it for a real purpose.


const label = 'Do Something';
const handler = () => doSomething('foobar');
button(label, handler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this is used, is quite different from how the other knobs are used. This confuses me, and I'd assume other as well. Having a fully 'working' real-world example would help a lot understanding this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the documentation as of today, I don't get nothin' 😆. How is this supposed to be used ? 🤔

@@ -110,6 +111,8 @@ storiesOf('Button', module)
const salutation = nice ? 'Nice to meet you!' : 'Leave me alone!';
const dateOptions = { year: 'numeric', month: 'long', day: 'numeric' };

button('Arbitrary action', action('You clicked it!'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is rather meaningless right? calling action from a button inside the knobs panel, won't be useful, or am I missing something here?

Could you add an example that would help understand the true use-case of this change? 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally reasonable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I made an example in the CRA for a case where i've normally included a button inside the story itself to trigger something like loading some external data through a render callback component, or generating a set of random data. These are the kind of use cases I'd have in mind for something like this.

I haven't thought too hard about it, there could be better ways to do it.

If you think that's not a good example, or not within knobs paradigm—totally fine. Don't have my heart set on it :)

}

render() {
button('Load the items', () => this.loadItems());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in the constructor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clear example by the way, Thanks!

Copy link
Contributor Author

@derrickpelletier derrickpelletier Oct 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HMR kills it when it is in the constructor. The button stays present in the knob panel but the instance of the example component is new, so the actual component tied to the knob was unmounted. I think there'd need to be modifications to the knobManager to override existing knobs of this type, instead of just returning the existing instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if this is the best solution, that's fine.

Can you take a look at why the CI is disapproving of this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restarted the build tasks

@ndelangen ndelangen merged commit b0fabc3 into storybookjs:master Oct 18, 2017
@ndelangen
Copy link
Member

Great job @derrickpelletier ! Thank you!

@shilman shilman changed the title Issue#1914 button knob Knobs addon: new knob type button Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants