-
-
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
"Knobs" Coming/Feature Request? #327
Comments
No plans yet but this is something that would be very cool ;-) So any help if not with implementation but at least with some ideas / mockups / investigation how that should / could work in Styleguidist is greatly appreciated. |
This is a super exciting idea. I just started playing with styleguidist yesterday, but my (very uninformed) strategy would be to rely on a common styleguide state object:
Example Wrapperimport { Component, PropTypes, Children, cloneElement } from 'react'
import { connect } from 'react-redux'
export default class Wrapper extends Component {
static propTypes = {
styleguideProps: PropTypes.object,
children: PropTypes.node.isRequired,
}
render() {
const {
styleguideProps,
children,
} = this.props
if(!styleguideProps) {
return children
}
return Children.map(children, child => {
return cloneElement(child, styleguideProps)
})
}
}
const mapStateToProps = (styleguideState, ownProps) => {
return {
styleguideProps: styleguideState[ownProps.componentId],
}
}
export const StateMappedWrapper = connect(mapStateToProps)(Wrapper) |
@alampros I‘m not sure why you need Redux for that ;-) Implementation is the simplest question for this feature — UI is much harder question. |
Yeah, also not sure why you need redux for that... 🤔 I'm wondering if it can be done in a way that https://github.com/storybooks/storybook-addon-knobs can be reused. |
Not sure we could reuse it — it looks very tied to Storybook but we definitely can learn from it. |
I’d be very to cool to have plugins in Styleguidist but I have no idea how we could implement them. |
@sapegin totally fair point. It was the hammer I had in my hand at the time. heh
This seems like a straightforward map of {
'bool': <input type="checkbox" ... />,
'string': <input type="text" ... />,
'enum': <select .... />,
} |
In vacuum — yes ;-) But we need to add them to existing Styleguidist UI. It‘d make UI uglier if we show them by default. Also there‘s s an issue with checkboxes for example: it has two states but actually there’s three: checked, unchecked and the value defined in Markdown file for a particular example. How that should work? |
Perhaps treat it like the |
That won’t work ;-) |
Another implementation in BlueKit: http://bluekit.blueberry.io/demo |
I really like how Carte Blanche is doing it — they not only have custom UI and custom value generators, but they actually update the source code of the examples on state change so you can commit it to the repo. |
I’m looking again how other tools do this and looks like we’re overcomplicate things here. All three (Attelier, Bluekit and Storybook Knobs) allows changing props only for one example, not for all examples of a component. So we could probably do it like in Storybook Knobs, as a tab under an example (where the editor is). Which leads as to another thing: we can make a simple plugins API. Plugins will be visible as tabs under an example, they will have read/write access to example source, style guide config etc. That also means code editor could be implemented as a plugin, as well as its read only alternative. (cc @MicheleBertoli @cef62 — snapguidist could be implemented as a plugin too.) |
That is awesome! It would be great to have such a plugin system! |
Yes @sapegin that plugin system is on top of my todo list since xmas but until April my work commitments are taking all my available time.
@okonet yes that is definitely something I'd love to have in styleguidist! |
Maybe JSON like structure with editable value (inline editor, enables when you click it) Some inspiration for UI:
UPD: Check out this example with code editor https://react.semantic-ui.com/modules/dropdown#dropdown-example-search-selection |
Does this plan still ongoing? Previously I tried to add additional combobox in wrapper.js, but everytime I change the value, wrapper.js can't pass the new props to the child components (I can't find any ways to pass it in preview.js). I also don't understand how codemirror works, is it possible for codemirror to read our changes? |
@darrylsepeda Thanks for your interest! Any help with the plugin API would be the most valuable: #505.
What changes do you mean? But I guess it’s possible because it updates the code every time you edit examples in Markdown files. |
Thanks @sapegin, I will take a look at the API. I mean, the changes that has been made by user in the website (come from our function). |
Looks like you shouldn’t change the Markdown directly as a reaction to change in combobox but some state and than filter Markdown before each render. That’s a good question for plugin API ;-) |
One use case for updating all components in the example is theme or i18n settings: I think this should be allowed via the plugin system as well on the "root" level. Something to think about. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This doesn't add anything to the discussion and generates lots of spam emails to everyone subscribed to issue. I'm locking the issue now. Feel free to send a pull request or open a new, more constructive, issue. |
Are there any plans to add a way for
react-styleguidist
to have more interactive style "knobs" or form elements for the component's prop types. This is something I've seen on many other pattern library generators (see examples below), and I was mainly wondering if this is something that is being planned forreact-styleguidist
? Or is it something you'd be open to having if I looked into building it/adding it in?Some examples would be like:
The text was updated successfully, but these errors were encountered: