-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Extensions API #354
Comments
We were talking about Storybook like plugins that would add tabs under examples. But this also can be useful. |
Yeah, I actually don't like how storybook does it since it's very restrictive. This one should theoretically allow writing custom visualizers for the components and create custom controlled components (like knobs?). We should try it out and see if it works well for us. |
I think for knobs Storybook-style is quite good and enough. Why do you think it won’t work well? |
My concern is more UI-wise: storybook only allow you to extend by creating tabs around the content there we are interested in creating extension inside of the content. |
Could you make some mockup of your ideas? That would really help ;-) |
I could when I get some more time :( |
Have watched a ReactConf talk about it and this is amazing! But looks like it only works with Fiber. Not sure they will / can support React 15. |
What do we want to extend by the way?
What else? |
+1 for tabs, it seems a great starting point to me. |
I agree with @okonet, I would love have both possibilities:
While working on |
@cef62 Ping ;-) Do you have some time now? |
I've started digging through the new 5.x implementation. I really like the new AST based parsing, great job @sapegin! At the moment the most viable solution I can think of, but I'm not fond of it, is to support a sort of What I think could be a interesting way to expose a plugin API is to wrap the RSG component, we want expose as customizable parts, with an HoC connected to I want to share a more complete idea as soon as possible. Next two weeks I'll be participating to Jsconfit and Codemotion Amsterdam, then I'll be finally able to give my full attention to the plugin API and Meanwhile what do you think of the idea of using HoCs to connect plugins to |
I think unique ID generation should be part of the core but I don’t know how to do expect use just indexes like Jest does itself. About HOCs: sounds like a good idea, do you know how we could easily implement that? I also think that we should start from predefined extension points (toolbars and tabs) like I describe in #426 — it should be easier to implement and would be enough for many plugins, for Snapguidist as well if I’m not missing something ;-) |
I've a couple of ideas and it's what I hope to share in more detail asap.
I definitely agree with you! |
Front matter is a nice idea but I’m afraid we can’t require users to write it for each example just to be able to use Snapguidist. We could use the text in a paragraph in front of the example. It’s not perfect but probably better than indexes. |
Yep, this is my exact feeling about it. But could/should be optional. I mean the plugin author could support an explicit title/ID/whatever to support specific features, if the user doen't care about those features (like test execution optimization) can simply skip the front matter.
That is a nice idea to avoid unnecessary repetitions on every snippet. |
So, yeah, we could generate these IDs in the core and pass them to your plugin’s tab component or whatever ;-) |
Yes and no. We can just recognize snippet positional index and their content. If the user change the snippet order and the content we don't have any way to be sure of which snippet whas assigned to which ID. |
If we use text than most likely the text will be moved with the snippet and we don’t have a better idea anyway ;-) |
We can't assume there's always going to be a text above the snippet, right? Jest is using a combination of name + index, and we are doing the same at the moment. Afaik we don't have evidence of any performance issue, therefore I wouldn't worry about it. |
No we can't
I was thinking not only about Anyway I agree with you that is not fundamental, but a nice addition to have anyway. |
To start working on the API something very simple: adding buttons to component toolbar. What do you like more 1 or 2? // styleguide.config.js
module.exports = {
// ...
plugins: [
require('styleguidist-plugin-foo')({ some: 'options' })
]
} // Plugin that adds a button to each component toolbar
import React from 'react';
import ToolbarButton from 'react-styleguidist/lib/rsg-components/ToolbarButton');
import MdScreenShare from 'react-icons/lib/md/screen-share');
export default /* plugin options */ options => /* style guide config */ config => {
return {
// Buttons that should be added to a component toolbar
// 1.
getComponentToolbarButtons({ name, urlAnchor, urlIsolated, urlNoChrome }) {
return [
<ToolbarButton to={`http://sizzy.co/?url=${encodeURIComponent(urlNoChrome)}`} title="Open in Sizzy" blank><MdScreenShare /></ToolbarButton>
];
},
// 2.
toolbarButtons: [
({ name, urlAnchor, urlIsolated, urlNoChrome }) =>
<ToolbarButton to={`http://sizzy.co/?url=${encodeURIComponent(urlNoChrome)}`} title="Open in Sizzy" blank><MdScreenShare /></ToolbarButton>
];
};
}; |
IMO always go with functions since it's much more flexible in a long-term. |
@okonet Both are functions. The difference is only in an array placement: inside the function or outside. I like the second one more because it‘s just a component. |
I also like the 2nd variant. |
@cef62 Yeah, that’s the idea for simple things like toolbar buttons. And after that we can think what else we need. |
I agree! Do you have a working branch or is just an idea? I'd love to help on this ;) |
@cef62 There’s the |
Ok thanks! I'll look at it and I'll see how I can contribute to move toward the API you proposed! |
@cef62 I think I need to implement the first version of the API with only component toolbar extension and then you could help with things we’ll need for Snapguidist. |
## New features ### UI refresh Welcome our refined UI! More consistent and clean: ![](https://d3vv6lp55qjaqc.cloudfront.net/items/3j1P0K1a1Q451t2Z2p3G/Screen%20Recording%202017-06-08%20at%2008.54%20PM.gif) 🦊 This is the first part of the planned improvements and a base for upcoming plugin API, see #426 and #354 for more details — we need your feedback there 🚀 🍕 Thanks to @SaraVieira and @n1313 for help! ❤️ ### Props & methods are hidden by default Use the new config option [showUsage](https://react-styleguidist.js.org/docs/configuration.html#showusage) to restore the old behavior. ## Bug fixes ### Crash when using a defaultProp that is not listed in props (#437 by @ankri) ### Isolated examples inside sections ### Issues with `position: relative` (#441) ### Ugly isolated example link (#235)
## New features ### UI refresh Welcome our refined UI! More consistent and clean: ![](https://d3vv6lp55qjaqc.cloudfront.net/items/3j1P0K1a1Q451t2Z2p3G/Screen%20Recording%202017-06-08%20at%2008.54%20PM.gif) 🦊 This is the first part of the planned improvements and a base for upcoming plugin API, see #426 and #354 for more details — we need your feedback there 🚀 🍕 Thanks to @SaraVieira and @n1313 for help! ❤️ ### Props & methods are hidden by default Use the new config option [showUsage](https://react-styleguidist.js.org/docs/configuration.html#showusage) to restore the old behavior. ## Bug fixes ### Crash when using a defaultProp that is not listed in props (#437 by @ankri) ### Isolated examples inside sections ### Issues with `position: relative` (#441) ### Ugly isolated example link (#235)
i like 1st variant |
@stepancar Any particular reason why? |
@sapegin, because in function we can implement any logic to select which buttons should be plased to example. For example, we want to add theme switcher button for several components which support theme switching using context. |
@stepancar In the second you could return null ;-) Maybe you have some other ideas? |
What if we make it more explicit like this? // Plugin that adds a button to each component toolbar
import React from 'react';
import ToolbarButton from 'react-styleguidist/lib/rsg-components/ToolbarButton');
import MdScreenShare from 'react-icons/lib/md/screen-share');
export default /* plugin options */ options => /* style guide config */ config => {
return {
// Similar: onSection, onExample, etc.
onComponent({ addToolbarButton }, { name, urlAnchor, urlIsolated, urlNoChrome }) {
addToolbarButton(
<ToolbarButton to={`http://sizzy.co/?url=${encodeURIComponent(urlNoChrome)}`} title="Open in Sizzy" blank><MdScreenShare /></ToolbarButton>
);
},
};
}; |
@sapegin I like this ↑ How will it be defined there the extension is happening? Is this pre-defiend by RSG? |
I’ve created a PR with some experiments: #505. |
Is there any update on this feature? |
We might want to take a look at https://github.com/camwest/react-slot-fill for allowing extensions for SG.
The text was updated successfully, but these errors were encountered: