-
-
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
Add custom component display names #933
Add custom component display names #933
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 very cool, thank you!
My only concern is the name:
displayName
in JS / React is a component name, so it's not very clear what it is.sg
suffix isn't used anywhere else. We sometimes usersg
.- All custom Styleguidist JSDoc tags have no prefixes (
ignore
,example
,public
).
I'd choose something like visibleName
to clarify that's it's the name visible in the UI.
loaders/utils/getProps.js
Outdated
if (doc.doclets && doc.doclets.sgDisplayName) { | ||
doc.sgDisplayName = doc.doclets.sgDisplayName; | ||
delete doc.doclets.sgDisplayName; | ||
if (doc.tags) { |
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.
What's the difference between doclets
and tags
? Worth adding a comment.
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.
Honestly, I don't know the difference :D I just noticed, that the custom tag gets added both to doclets and tags while parsing, so i decided it's a good idea to remove it from both. I'll investigate a little more on the matter.
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.
After investigating a little, it seems that doclets and tags are a little redundant.
Here's an example of doclet:
{
version: '1.0.1',
author: '[Jeremy Gayed](https://github.com/tizmagik)',
deprecated: 'Use the [only true button](#button) instead'
}
And here's the tags object:
{
version: [ { title: 'version', description: '1.0.1' } ],
author:
[ { title: 'author',
description: '[Jeremy Gayed](https://github.com/tizmagik)' } ],
deprecated:
[ { title: 'deprecated',
description: 'Use the [only true button](#button) instead' } ]
}
Seems, it's the same data, structured a little differently. The interesting part, that we are using two different parsers to get those results. So, unless there are some subtle differences that I've missed, we can do some refactoring and let one of those go. But anyway, I think this work is outside of this pull request purpose. Should I file an issue for that?
I've noticed that the names of components in sidebar are still not properly updated. Will look into it. |
To be used purely for displaying the component name
b89cdda
to
aab4795
Compare
All right, I've changed the name, updated componenstListRenderer, so it uses visibleName as well and threw in some docs. Also, had to rebase because of conflicts with master. |
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.
The code looks good, just a few tweak for the docs 🦄
docs/Cookbook.md
Outdated
@@ -25,6 +25,7 @@ | |||
* [How to add fonts from Google Fonts?](#how-to-add-fonts-from-google-fonts) | |||
* [How to reuse project’s webpack config?](#how-to-reuse-projects-webpack-config) | |||
* [How to use React Styleguidist with Redux, Relay or Styled Components?](#how-to-use-react-styleguidist-with-redux-relay-or-styled-components) | |||
* [How to change the names of components displayed in Styleguidist UI?](#how-to-change-the-names-of-components-displayed-in-styleguidist-ui) |
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.
Looks like it's not ordered alphabetically.
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.
Hey, it seems that the rest of the items is not ordered alphabetically as well. Should I order them?
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.
Would be super cool! But preferably in a separate 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.
👍
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.
Hey, I finally got to alphabetically ordering the cookbook sections and want to ask: is this really a good idea? In this case, the first entry in the cookbook will be 'Are there any other projects like this?' and it feels that there are more important/useful topics in the cookbook than this... It feels that there can be a benefit in structuring the cookbook, but in some other, more semantic way, like from beginner topics to more advanced stuff or from most frequent requests to more rare/specific.
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.
Let's skip it then ;-) Are you going to change anything else or I can merge 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.
All right! Nope, the rest of the changes is in place already, so this one is ready to go 🚢
docs/Cookbook.md
Outdated
@@ -479,6 +480,29 @@ See in [configuring webpack](Webpack.md#reusing-your-projects-webpack-config). | |||
|
|||
See [working with third-party libraries](Thirdparties.md). | |||
|
|||
## How to change the names of components displayed in Styleguidist UI? | |||
|
|||
Often you might want to change your components' names to be displayed differently, for example, for stylistic purposes or to give them a more descriptive names in your styleguide. |
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.
Not really often, I'd remove “often” ;-)
docs/Cookbook.md
Outdated
|
||
This can be done by adding [@visibleName](Documenting.md#-visiblename-custom-tag) tag to your component documentation. | ||
|
||
In case you want to change components' names in bulk, for example, based on their current name, you can utilize [updateDocs](Configuration.md#updatedocs) configuration option. |
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.
utilize → use
configuration → config
docs/Cookbook.md
Outdated
|
||
In case you want to change components' names in bulk, for example, based on their current name, you can utilize [updateDocs](Configuration.md#updatedocs) configuration option. | ||
|
||
Here's an example of how this can be achieved: |
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.
You could end the previous paragraph with a “:” and remove this one.
docs/Cookbook.md
Outdated
module.exports = { | ||
updateDocs(docs) { | ||
if (docs && docs.displayName) { | ||
docs.visibleName = _.lowerCase(docs.displayName) |
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.
docs.displayName.toLowerCase()
docs/Documenting.md
Outdated
@@ -203,6 +204,23 @@ class Button extends React.Component { | |||
} | |||
``` | |||
|
|||
### @visibleName custom tag |
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.
I think this section should be before “Using JSDoc tags”, similar to “Ignoring props”.
docs/Documenting.md
Outdated
@@ -203,6 +204,23 @@ class Button extends React.Component { | |||
} | |||
``` | |||
|
|||
### @visibleName custom tag | |||
|
|||
Apart from most of the jsDocs tags that can be used with RSG, @visibleName is not present in jsDoc specs. This is a custom tag, that we have added to provide users with a way to define names for components to be used in the UI. |
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.
Something like this would be shorter with the same amount of useful information:
Use
@visibleName
JSDoc tag to define component names that are used in the Styleguidist UI:
(And you could remove the next paragraph too.)
docs/Documenting.md
Outdated
class Button extends React.Component { | ||
``` | ||
|
||
By defining the @visibleName tag above, you let the Styleguidist know that this name should be used whenever the component is displayed in the UI as 'The Best Button Ever 🐙' instead of it's original 'Button' name. |
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.
Instead of repeating what you say in the first paragraph it would be useful to say that this won't change the actual name of the component that is used in JSX.
Is it possible to merge this PR please? These changes would be beneficial in our project. Thx. |
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.
Codecov Report
|
Looks like I forget to include this PR in 7.1.0, sorry 😭 — will try to make 7.2.0 soon! |
## New features * Add custom component display names ([#933](#933)) ``` module.exports = { updateDocs(docs) { if (docs && docs.displayName) { docs.visibleName = docs.displayName.toLowerCase() } return docs } } ``` * Made the mounting point id configurable. ([#1050](#1050)) ## Bug fixes * Cypress failing test ([#1077](#1077))
🎉 This PR is included in version 7.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
- User can define a custom name via a custom @sgDisplayName tag in the doc block
## New features * Add custom component display names ([#933](styleguidist/react-styleguidist#933)) ``` module.exports = { updateDocs(docs) { if (docs && docs.displayName) { docs.visibleName = docs.displayName.toLowerCase() } return docs } } ``` * Made the mounting point id configurable. ([#1050](styleguidist/react-styleguidist#1050))
## New features * Add custom component display names ([#933](styleguidist/react-styleguidist#933)) ``` module.exports = { updateDocs(docs) { if (docs && docs.displayName) { docs.visibleName = docs.displayName.toLowerCase() } return docs } } ``` * Made the mounting point id configurable. ([#1050](styleguidist/react-styleguidist#1050)) ## Bug fixes * Cypress failing test ([#1077](styleguidist/react-styleguidist#1077))
Hey,
here comes my attempt on allowing users to define custom component display names for SG, that was discussed in #195.
Now, the user can define a custom name via a custom @sgDisplayName tag in the doc block, i.e.:
or by utilising newly introduced
updateDocs
config option (#868), i.e.:Let me know, please, if this is close to what you meant it to be.
Also, some updates to the cookbook/docs will follow after initial review.
Cheers,
G.