Skip to content

Commit

Permalink
chore(docs): add custom browser title to storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
John French committed Oct 27, 2021
1 parent 5ee77bc commit b3578ad
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .storybook/manager.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addons } from '@storybook/addons';
import { STORY_RENDERED } from '@storybook/core-events'
import { create } from '@storybook/theming';

const theme = create({
Expand All @@ -11,3 +12,32 @@ const theme = create({
addons.setConfig({
theme
});

addons.register('TitleAddon', api => {
const customTitle = 'Reactstrap';
let interval = null;
const setTitle = () => {
clearTimeout(interval);

let storyData = null;
try {
storyData = api.getCurrentStoryData();
} catch(e) {}

let title;
if (!storyData) {
title = customTitle;
} else {
title = `${storyData.kind} - ${storyData.name}${customTitle}`
}

if (document.title !== title) {
document.title = title;
}
interval = setTimeout(setTitle, 100);
};
setTitle();
api.on(STORY_RENDERED, story => {
setTitle();
})
})

0 comments on commit b3578ad

Please sign in to comment.