Badge Content
The text displayed for a badge is controlled by its title field.
This accepts either a string to display, or a function that returns a string.
Title
badgeMap: {
MyCustomBadge: {
title: 'Custom';
}
}
Will result in
Custom
Title Function
The title of a BadgeConfig also accept a function which must return a string.
The function accepts the following parameters:
badgeId: The ID used to look up the badge's configurationcontent: The parsed `content` of the badgeentry: The Storybook data for the story. An object containing:id: The unique ID of the entry.depth: The depth of the entry in the sidebar tree (how many folders deep - including theroot).name: The name of the entry, usually displayed in the sidebar.refId: An internal Storybook reference.renderLabel: A function for rendering the label in the sidebar. See the Storybook docs for more details.type: The type of the entry.startCollapsed: Whether arootentry is collapsed on initial load. (Only available ontype: 'root').children: The contents of aroot,group, orcomponententry. Lists the direct child entry ID's.parent: The parent of agroup,component,docsorstoryentry. The ID of the entry's direct parent entry.tags: Thetagsof acomponent,docsorstoryentry.title: The title of adocsorstoryentry. Can be inferred, or manually entered in the component'smeta.prepared: A boolean indicating whether thedocs/storyhas been prepared. Iffalse, theargs,argTypes,initialArgsandparametersare unlikely to be populated.importPath: The file path fordocs/storyentries. Relates to their story file (*.stories.tsx?).parameters: Theparametersof adocs/storyentry. Only available if the entry is prepared.args: The currentargsof astoryentry, will differ toinitialArgsif the values have been updated in Storybook but not saved. Only available if the entry is prepared.argTypes: TheargTypesof astoryentry. Only available if the entry is prepared.initialArgs: TheinitialArgsof astoryentry. Only available if the entry is prepared.
getBadgeParts: A function that accepts a string, and splits it into `badgeId` and `content` based on thedelimiterfrom thematcherorbadgesConfig.rawContent: The string that was passed in to thetags/badgesarray.
badgeMap: {
MyCustomBadge: {
title: ({ entry }) => (entry.type === 'docs' ? 'Custom Docs' : 'Custom Story');
}
}
Will result in
Custom Docs
when the badge is displayed on a
Docs Page, and Custom Story
when
dispayed on a story.
Default Behavior
By default, if a badge does not contain a title field, it will return its inferred content. This
will either be the whole string passed to the tags/badges array, or a portion of that string if
using delimiters.