Skip to content

How to display tags in custom DocsPage #30803

Answered by rpasechnikov
rpasechnikov asked this question in Help
Discussion options

You must be logged in to vote

Hi all,

Spent a few more hours on this and got this working afterall. This seems to be exactly what I was after: https://storybook.js.org/docs/api/doc-blocks/doc-block-useof

Here's an example to demonstrate:

type TagConfig = {
  colour?: string
}

const tagConfigs: { [key: string]: TagConfig } = {
  'Tag 1': {
    colour: '#0098ff',
  },
  'Tag 2': {
    colour: '#00cc00',
  }
};

const Tags: React.FC<{tags: string[]}> = ({tags}) => {
  const ignoreTags = ['dev', 'test', 'autodocs'];
  const displayTags = tags.filter(tag => !ignoreTags.includes(tag));

  return (
    <div className={styles.tagContainer}>
      {displayTags.map(tag => <Tag key={tag} tag={tag} colour={tagConfigs[tag]?.colour} 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rpasechnikov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant