-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to hide a story from the sidebar #9209
Comments
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
FWIW, I solved my issue without this feature using the import React from 'react';
import { storiesOf } from '@storybook/react';
import IconsGrid from './IconsGrid';
if (process.env.STORYBOOK_VISUAL_TESTING === 'true') {
storiesOf('VisualTests', module).add('icons', () => <IconsGrid />);
storiesOf('VisualTests', module).add('icons-color-size', () => (
<IconsGrid color="#e04c36" size="24px" />
));
} I still think the feature is useful because my workaround requires the usage of |
I'm interested in this functionality as well. Our use-case is we're leveraging stories in Storybook and a different app as well (the CSF format is awesome for many reasons!). If we could flag a story as hidden from the Storybook UI, it would allow flexibility in writing them for either or both places. |
@evanmwillhite ooh! can you share more about your CSF usage?! super curious. |
@shilman for sure! We have a need for a fully customizable "style guide" (a la Carbon Design System) so we've built a Gatsby theme for that as it offers design and content management flexibility. But for the components section of that style guide - specifically when showing components and their code - we love the idea of being able to use Storybook's generated components for that as it's solved that problem so well (and Storybook is already our choice for component library and development environment so we're invested). But as you can probably imagine, the component library may contain a lot more components and display them differently than a curated style guide (different audiences). There's probably a number of ways to solve this problem, but our first thought was that it would be nice if Storybook could generate the component, but we could specify to hide it from the Storybook menu. We're looking into writing an addon for this right now actually, but any insights you might have would be super helpful! |
@evanmwillhite nice!! yeah CSF makes that pretty easy 😁 as for hiding the story from the sidebar, I think we'll probably end up adding it at some point, both based on the upvotes here and I'm pretty sure it's come up other places as well. But I don't have a timeline yet. It should be a pretty simple change, tho perhaps there are a few corner cases to work out. Any proposed APIs for that? Currently the API for hiding it from docs is |
@shilman Thanks for the update here, yeah we'd totally love to have that. Perhaps something like |
@techninja "build everything"? my proposal for |
Yep, sorry that's what I was referring to. I've been attempting to do something like this in an addon though it's not entirely clear the best way to do so, and the docs are a little lacking on any APIs surrounding this. |
For those who can't wait for the above proposal, here's a little work around
|
not stale |
What are the corner cases @shilman? |
No corner cases AFAIK. Just adds complexity. |
This would be a killer feature to have with addon-docs. I have a bunch of mdx files with designer focused documentation. (not stories.mdx) This file generally just documents the component and references story ids to render stories. A lot of the time we want to add examples in this doc but still want it to be verified with typescript/eslint so we end up creating real stories for them. The only problem is the sidebar gets cluttered with these stories that aren't as useful or needed when not using addon-docs Context: We are moving to a model where the docs tab is a design focused experience and the canvas tab is more focused on devs. we don't want to inundate our devs with a bunch useless examples |
For others needing something like this, I added the following to my
Then for any story I wanted filtered out, I just put |
That's pretty nice, thanks! I wanted to exclude some "development only" stories (where I tests regressions and else), from the published Storybook. addons.setConfig({
...
});
if (process.env.NODE_ENV !== 'development') {
addons.setConfig({
sidebar: {
filters: {
devel: item => {
return !item.tags.includes('devel');
},
},
},
});
} |
Tagging only works in Storybook v7+ right? I'm trying to achieve the same in SB 6.5 but this example doesn't work and there's really no clear documentation that I could find for what parameters can be passed in setConfig. |
Yeah @SimonHarte, as noted above, this is available in SB 7.4+. Unfortunately no option I know of exists in 6.5, except for the CSS workarounds noted up above in this issue. |
…1490) # Pull Request ## 🤨 Rationale The latest version of Storybook added a way to hide certain stories from the sidebar. I've been wanting this for "internal" stories that are only used to be composed into higher level MDX docs pages. storybookjs/storybook#9209 (comment) ![image](https://github.com/ni/nimble/assets/10500124/35418193-4e5a-48ee-9716-bb29b12eb91d) ## 👩💻 Implementation 1. Update all Storybook-related dependencies to latest - This has the unfortunate side effect of printing a huge string of garbage to the console when you run `npm run storybook -w @ni/nimble-components`. I believe it's caused by storybookjs/storybook#23675 but I'm not clear on how to apply the workaround since we don't appear to use a shared configuration. 3. Add storybook configuration to hide stories that start with "Internal" or "patterns" or "Tests" for the version hosted on nimble.ni.dev (shouldn't affect PR builds or dev builds) 4. Update MDX docs for hidden sections ## 🧪 Testing I looked to see if there were any other notable features in their [release notes](https://github.com/storybookjs/storybook/releases) or [blogs](https://storybook.js.org/blog/storybook-7-1/) and didn't find much other than official support for the [Figma addon](https://storybook.js.org/blog/figma-plugin-for-storybook/). The only behavior change I noticed is a new badge on the Controls tab that shows how many API entry points we document 🤷♀️ 1. Inspected local build and PR build of Storybook to ensure expected items are hidden 2. Poked around to see if anything else broke. I'll check the nimble.ni.dev/storybook after this deploys to ensure it's actually working, but I already verified the value of `window.location.hostname` in dev tools so I think it'll work. ## ✅ Checklist <!--- Review the list and put an x in the boxes that apply or ~~strike through~~ around items that don't (along with an explanation). --> - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
For those coming here from a search engine, |
Hi can you elaborate on this ?
Hi thank you for the reply ! Could you elaborate ? I am unsure where to find the manager.js to which I should set the
My usecase: I have several mystory.stories.tsx files, that I gather / summarize in a documentation.mdx I would like to only show the documentation.mdx in the sidebar. |
I did not see I had to install this package I created a file in .storybook directory called manager.ts and made my pattern as abovementioned. |
@ndelangen The filter future is not yet documented in the storybook documentation https://storybook.js.org/docs/react/configure/features-and-behavior P. S. import { addons } from '@storybook/manager-api';
addons.setConfig({
sidebar: {
filters: {
patterns: (item) => {
return !item.tags.includes('isHidden');
}
}
}
});
|
@bastiW that's correct. I have a task to formally write this API into a RFC. (I'm hoping I'll be able to get to that task this week). After a discussion with the core team (also welcome to outside contributors!) we'll formalize this API into the docs. |
How do I add "tags" to a Story when using the MDX format? |
Hey @dep, can you elaborate your use case? What Storybook version are you using and how are you defining your mdx stories? This change is for Storybook 7 which indexes tags as part of stories. In Storybook 7 the way mdx stories are written changed, so that you only refer to stories created in the export const Primary = {
tags: ['some-tag']
} |
@yannbf Thanks for the reply! My stories generally follow this format: import { Markdown, Meta, Story, Canvas } from "@storybook/addon-docs";
import { Box, Card, CardActions, CardContent, Button, Typography } from "../..";
import { prettifyDocSource } from "../../utils/prettify-doc-source";
import ComponentCounts from "./utilization.md";
<Meta
title="Components/Cards"
component={Card}
parameters={{
docs: {
transformSource: (source) => prettifyDocSource(source),
},
controls: {
expanded: true,
},
}}
/>
# Card
Cards contain content and actions about a single subject.
Cards are surfaces that display content and actions on a single topic.
They should be easy to scan for relevant and actionable information. Elements, like text and images, should be placed on them in a way that clearly indicates hierarchy.
#### Basic Card
export const BasicCard = (args) => {
const bull = (
<Box
component="span"
sx={{ display: "inline-block", mx: "2px", transform: "scale(0.8)" }}
>
•
</Box>
);
return (
<Card sx={{ minWidth: 275 }}>
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
);
};
<Canvas>
<Story name="Basic card"><BasicCard /></Story>
</Canvas>
'''jsx
<Card sx={{ minWidth: 275 }}>
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be•nev•o•lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
'''
> #### Outlined Card
export const OutlinedCard = (args) => {
const bull = (
<Box
component="span"
sx={{ display: "inline-block", mx: "2px", transform: "scale(0.8)" }}
>
•
</Box>
);
const ExampleCard = (
<>
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</>
);
return (
<Box sx={{ minWidth: 275 }}>
<Card variant="outlined">
<>
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be{bull}nev{bull}o{bull}lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</>
</Card>
</Box>
);
};
<Canvas>
<Story name="Outlined Card"><OutlinedCard /></Story>
</Canvas>
'''jsx
<Box>
<Card variant="outlined">
<>
<CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="div">
be•nev•o•lent
</Typography>
<Typography sx={{ mb: 1.5 }} color="text.secondary">
adjective
</Typography>
<Typography variant="body2">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</>
</Card>
</Box>
''' I would generally like to only see a single item in the Sidebar for "Card" so our users can consume how to use a component from top to bottom. |
To avoid import { addons } from '@storybook/manager-api';
import {API_PreparedIndexEntry, API_StatusObject} from "@storybook/types";
addons.setConfig({
sidebar: {
filters: {
patterns: (item: API_PreparedIndexEntry & {
status: Record<string, API_StatusObject | null>;
}): boolean => {
return !(item.tags ?? []).includes('hideInSidebar');
}
}
}
}); and in your stories: const meta: Meta<ListComponent> = {
title: 'List',
component: ListComponent,
tags: ['hideInSidebar'],
... with these "@storybook/addon-controls": "^7.6.3",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/angular": "^7.5.3",
"@storybook/core-server": "^7.5.3",
"@storybook/jest": "^0.2.3",
"@storybook/test-runner": "^0.13.0",
"@storybook/testing-library": "^0.2.2", |
@dep —
Sorry for the late reply here, but just in case it's still useful, you can achieve this (for all stories) with "docs mode": https://storybook.js.org/docs/writing-docs/build-documentation. |
@yuri-scarbaci-lenio do I understand you correctly, that because you filtered out the story from the sidebar, when you opened the story directly with a URL, you would expect that specific story to not have the sidebar? If so, I don't think that is a correct mental model to have. Displaying stories only without the manager UI (sidebar, panel, toolbar) is supported by using the |
Hey @yuri-scarbaci-lenio Thanks for elaborating, but I think it's still confusing to understand what you're trying to achieve. I tried to reproduce this issue and I couldn't. I added a tag to the story, plus the filter, and the story rendered correctly when:
IMO you could take a look into referencing your stories via the Story doc block, instead of iframes: |
You can also setup the tags at the story level to look like this: |
Hello, I did try again using and given: before 3- the story hosting the iframe properly connects to the url and show it as expected to be clear, I did not change the iframe src url, they where correct from the get go, the only change I did after your suggestions is that I am now using react-vite and latest storybook (which may imply this is not correctly working in some storybook combination, but given it works starting thanks a lot, this will help a lot with documenting microfront-end scenarios!
The issue is in our scenarios we are purposely using the iframes because we specifically have to document how our components works in micro-front-end application that are built with iframes which like it or not is one of the current industry accepted way to build micro-front-ends portals and that from the design system standpoint has a pletora of specific challenges to address that are unique to this way of composing the final app |
For anybody who's landing on this issue, here is the recommended way to hide stories from the sidebar: |
Hiding a story from the sidebar using the |
Is your feature request related to a problem? Please describe.
I am doing visual regression testing with Storybook iframes. I have some docs pages that aren't specific for a single component, for example, I have an "icons" page that shows all the icons of the library in a grid. I would like to test all these icons but since they are on a docs page, I don't have the iframe available.
Describe the solution you'd like
I would like to be able to create stories that are hidden on the sidebar but can still be accessible by the URL. Perhaps a per-story configuration.
Describe alternatives you've considered
I can create a story just for the icons grid, but it is redundant and a bit out of place since I already have the icons doc page that has a lot more info
Are you able to assist bring the feature to reality?
Yes, if the suggestion makes sense for the project, I can find some time to implement it
The text was updated successfully, but these errors were encountered: