Badge Style
Badges will inherit the baseStyle by default, so any badges that either don't have an entry
in the badgeMap, or that don't define a style key in their definition, will have the same
look.
To define a custom style for each badge, so that they are easy to tell apart, pass in a BadgeStyle
object to its configuration in the badgeMap. This can be a partial style, and any values not
provided will fall back to the values.
The style property accepts either an inline BadgeStyle object,
or a function that returns a BadgeStyle.
Inline Style
An inline style object can contain any of the available properties.
Any that are not provided will fall back to the values from baseStyle.
badgeMap: {
MyCustomBadge: {
title: 'My Custom Badge',
styles: {
backgroundColor: '#00C7AC',
borderColor: 'red',
color: '#FFFFFF'
}
}
},
Style Function
A style function accepts a BadgeFnParameters object as its only parameter and returns a
BadgeStyle. This can be used to adjust the style based on
information about the story it's being added to:
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: 'My Custom Badge',
styles: ({ entry }) => ({ backgroundColor: entry.type === 'story' ? '#00C7AC' : '#FFFFFF'});
}
},
Available Style Properties
The BadgeStyle object is a limited subset of CSS properties, if there are any you need simply
raise a
feature request.
The available properties (and their values in the built-in styles) are:
| Property | Value in default | Value in github |
| backgroundColor | #EDEFF5 | #EDEFF5 |
| borderColor | #474D66 | #474D66 |
| borderRadius | 3px | 10px |
| borderStyle | solid | solid |
| borderWidth | 1px | 1px |
| boxShadow | none | none |
| color | #474D66 | #474D66 |
| fontFamily | inherit | inherit |
| fontSize | 0.625rem | 0.75rem |
| fontWeight | bold | bold |
| lineHeight | 1 | 1 |
| paddingBlock | 2px | 2px |
| paddingInline | 5px | 8px |
| textTransform | uppercase | lowercase |