-
-
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
feat(*): allow to show one component per page #768
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool!! 🦄
Minor tweaks, tests, docs ;-)
@@ -8,7 +8,7 @@ exports[`should ignore items without name 1`] = ` | |||
> | |||
<Styled(Link) | |||
className="" | |||
href="#button" | |||
href="blank#button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapegin have a look at master
react-styleguidist/src/rsg-components/slots/__snapshots__/IsolateButton.spec.js.snap
Line 14 in 09d2452
href="blank#!/Pizza/3" |
it's because in test context location.pathname is blank. As i understand for this cases we shoul overwrite window.location for all our tests, but i think it's out of scope this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK.
src/utils/renderStyleguide.js
Outdated
displayMode={displayMode} | ||
oneComponentPerPage={styleguide.config.oneComponentPerPage} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already pass config here, we should access it via context in non-render components and pass as a prop to render components if they need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sapegin thank you! fixed
Codecov Report
|
@sapegin, added description in docs, added tests, fixes according your recomendations about config usage through context |
I'm wondering if we could skip the config part and make it behave like this based on the URL? In this case we could just add additional action (i.e. icon or ⎇-click action) to the sidebar navigation items to open in the isolated mode? The problem with the configuration IMO is that it addresses one use case whereas there are several depending on the current environment—in development I might want to have one component per page but when publishing we should be able to see all. This can't be solved with the config right now. Thoughts? |
That's a very good point! I guess we need both. The option is good to completely disable all components on one page mode. I'm thinking that enabling this option by default in dev mode would be very good. Or make it not a boolean but a string: |
Why not URL based? My concern is that once option is here it's really hard to remove it in the future. |
But the URL is always the same — |
What do you mean? We can come up with the url scheme to differentiate between 2 modes |
We can’t: you open a style guide always at root. |
@okonet For dev mode you can use another config |
Sounds like too much work ;-0 |
Why do I need to change config in order to change the presentation of the component? This seems too much work for me as a user. But if @sapegin believes that config is the way, I’m okay with that. We can tackle that when a better router is in place, I guess. |
I don’t see any other way: we need to know how many components to render when you open a style guide. |
Not sure I'm getting it:
Why should the style guide behave differently in this case? We still can render all components as we do now but only display one if the URL matches? What am I missing? Let's say we have the following URL: |
Because the whole point of this feature is not to render all component at the same page. |
@stepancar What do you think about that?
I kind of like the idea but that may be breaking change to your current implementation. |
@sapegin @stepancar Just chiming in, but yessss! Love this feature. +1 for adding it so it can be one component per page always. |
@sapegin, I think, that developers can just use another config in dev mode or use NODE_ENV. |
Of course they can but why would they do that? For me it makes a lot of sense to have such behavior by default. I don't know how other people use Styleguidist but for I never need to see all component in dev mode. |
Would love to see this feature merged to master. Working on two different design systems that use StyleGuidist for docs and both would benefit from this feature. So basically here to show thumbs up 👍 |
Would love to see individual routes per component rather than the long page showing all! Great work and good discussion here 👍 |
I would also really like to see this feature merged :) This is the functionality that my team's designers would like see in our project. |
@sapegin, I'll try to enable this feature in dev mode by default today. |
} | ||
|
||
renderSections() { | ||
const { searchTerm } = this.state; | ||
const { sections } = this.props; | ||
|
||
const oneComponentPerPage = (this.context.config || {}).oneComponentPerPage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this.context
returns an empty object here. So oneComponentPerPage
is always undefined
@@ -108,6 +108,7 @@ exports[`should filter section names 1`] = ` | |||
}, | |||
] | |||
} | |||
oneComponentPerPage={undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since oneComponentPerPage
is boolean, can it be explicitly defined as false
somewhere?
👋 **[Support Styleguidist](https://opencollective.com/styleguidist) on Open Collective** 👋 ## New features ### Page per section 🚧 This is a huge improvement for large style guides: now you can show only one component at a page instead of all components. ![](https://d3vv6lp55qjaqc.cloudfront.net/items/0W2q2K2s3n2k311O1J0y/Screen%20Recording%202018-03-22%20at%2010.06%20AM.gif) To enable: ```js module.exports = { pagePerSection: true }; ``` This is an experimental feature and we need your feedback to make it better and really useful. For example, right now there’s no isolated mode. So feel free to share your ideas [in issues](https://github.com/styleguidist/react-styleguidist/issues). (#835 by @bitionaire and @stepancar, closes #494 and #768) ### “Fork me” ribbon One more step to make Styleguidist usable for documenting open source projects: ![](https://d3vv6lp55qjaqc.cloudfront.net/items/1t331n2a3v0F2i290K0Z/Image%202018-03-22%20at%209.13.11%20AM.png) New config option to enable the ribbon, define the URL and change the label: ```js module.exports = { ribbon: { url: 'http://example.com/', text: 'Fork me on GitHub' } }; ``` And two new [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/styles/theme.js) to change colors: `color.ribbonBackground` and `color.ribbonText`. (#861 by @glebez and @wkwiatek, part of #195, closes #647) ### Options to change CLI output on server start and build Two new options, `printServerInstructions` and `printBuildInstructions`: ```js module.exports = { printBuildInstructions(config) { console.log( `Style guide published to ${ config.styleguideDir }. Something else interesting.` ); } }; ``` (#878 by @roblevintennis, closes #876) ### Option to modify props A new option, `updateDocs` to modify props before rendering. For example, you can load a component version number from a JSON file: ```js module.exports = { updateDocs(docs) { if (docs.doclets.version) { const versionFilePath = path.resolve( path.dirname(file), docs.doclets.version ); const version = require(versionFilePath).version; docs.doclets.version = version; docs.tags.version[0].description = version; } return docs; } }; ``` (#868 by @ryanoglesby08) ### Limited support for named exports Styleguidist used to require default exports for components. Now you can use named exports too, though Styleguidist still supports only one component per file. I hope this change will make some users happier, see more details [in the docs](https://react-styleguidist.js.org/docs/components.html#loading-and-exposing-components). (#825 by @marcdavi-es, closes #820 and #633) ### Allow arrays of component paths in sections More flexibility in structuring your style guide: ```js module.exports = { sections: [ { name: 'Forms', components: [ 'lib/components/ui/Button.js', 'lib/components/ui/Input.js' ] } ] }; ``` (#794 by @glebez, closes #774) ### Sort properties by `required` and `name` attributes This change should make props tables more predictable for the users. Instead of relying on developers to sort props in a meaningful way, Styleguidist will show required props first, and sort props in each group alphabetically. To disable sorting, use the identity function: ```javascript module.exports = { sortProps: props => props }; ``` (#784 by @dotcs) ## Bug fixes * Allow `Immutable` state in examples (#870 by @nicoffee, closes #864) * Change template container ID to prevent clashes (#859 by @glebez, closes #753) * Better props definitions with Flow types (#781 by @nanot1m)
Was finished in another PR, thanks for help anyway! |
@sapegin added simple implementation of "on component per page feature"
#494