Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for easy way to show my library's version in storybook

Tags:

storybook

I'm trying to add the current version of a project (essentially the version field from package.json) to storybook so consumers of storybook can tell which version of the project they are looking at. However, I am finding it extremely difficult to do this, I haven't been able to find a way to do it in the config file, and haven't seen any addons that will simply show the current version of the project (other than one that is more made for showing how components have changed over versions, which isn't really what I'm after).

It's easy enough to require the package.json file in a js file, and grab the version from there, but storybook seems pretty locked down in terms of allowing you to send any addition information to the header/sidebar.

Has anybody done anything like this before? I'd be grateful for any thoughts or theories on how this could be done. Thanks!

like image 830
Mitch Goudy Avatar asked Mar 05 '20 17:03

Mitch Goudy


People also ask

What is storybook preview?

In Storybook, your stories render in a particular “preview” iframe (Canvas tab) inside the larger Storybook web application. The JavaScript build configuration of the preview is controlled by a webpack config, but you also may want to directly control the rendered HTML to help your stories render correctly.

What is .storybook folder?

Storybook is configured via a folder called . storybook , which contains various configuration files. Note that you can change the folder that Storybook uses by setting the -c flag to your start-storybook and build-storybook scripts.


1 Answers

Also was interested in this question. I've added to brandTitle to .storybook/manager.js like

import { version } from "../package.json";
addons.setConfig({
   theme: create({
       base: "light",
       brandTitle: `My components v.${version}`
   }),
});

Theming docs

like image 193
Дмитрий Дорогонов Avatar answered Sep 19 '22 16:09

Дмитрий Дорогонов