Skip to content

Commit b89cdda

Browse files
committed
add docs and cookbook example on visibleName tag
1 parent cf6d852 commit b89cdda

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/Cookbook.md

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [How to add fonts from Google Fonts?](#how-to-add-fonts-from-google-fonts)
2626
* [How to reuse project’s webpack config?](#how-to-reuse-projects-webpack-config)
2727
* [How to use React Styleguidist with Redux, Relay or Styled Components?](#how-to-use-react-styleguidist-with-redux-relay-or-styled-components)
28+
* [How to change the names of components displayed in Styleguidist UI?](#how-to-change-the-names-of-components-displayed-in-styleguidist-ui)
2829
* [What’s the difference between Styleguidist and Storybook?](#whats-the-difference-between-styleguidist-and-storybook)
2930
* [Are there any other projects like this?](#are-there-any-other-projects-like-this)
3031

@@ -479,6 +480,29 @@ See in [configuring webpack](Webpack.md#reusing-your-projects-webpack-config).
479480

480481
See [working with third-party libraries](Thirdparties.md).
481482

483+
## How to change the names of components displayed in Styleguidist UI?
484+
485+
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.
486+
487+
This can be done by adding [@visibleName](Documenting.md#-visiblename-custom-tag) tag to your component documentation.
488+
489+
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.
490+
491+
Here's an example of how this can be achieved:
492+
493+
```javascript
494+
const _ = require('lodash')
495+
496+
module.exports = {
497+
updateDocs(docs) {
498+
if (docs && docs.displayName) {
499+
docs.visibleName = _.lowerCase(docs.displayName)
500+
}
501+
return docs
502+
}
503+
}
504+
```
505+
482506
## What’s the difference between Styleguidist and Storybook?
483507

484508
Both tools are good and mature, they have many similarities but also some distinctions that may make you choose one or the other. For me the biggest distinction is how you describe component variations.

docs/Documenting.md

+18
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ You can use the following [JSDoc](http://usejsdoc.org/) tags when documenting co
152152
* [@author](http://usejsdoc.org/tags-author.html)
153153
* [@since](http://usejsdoc.org/tags-since.html)
154154
* [@version](http://usejsdoc.org/tags-version.html)
155+
* [@visibleName](#-visiblename-custom-tag)
155156

156157
When documenting props you can also use:
157158

@@ -203,6 +204,23 @@ class Button extends React.Component {
203204
}
204205
```
205206

207+
### @visibleName custom tag
208+
209+
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.
210+
211+
Let's take a look at the example:
212+
213+
```javascript
214+
/**
215+
* The only true button.
216+
*
217+
* @visibleName The Best Button Ever 🐙
218+
*/
219+
class Button extends React.Component {
220+
```
221+
222+
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.
223+
206224
## Writing code examples
207225
208226
Code examples in Markdown use ES6+JSX syntax. All components covered by the style guide can be used in all examples:

0 commit comments

Comments
 (0)