Skip to content
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

Feature/add data-tags attribute to sidebar items #10169

Conversation

thehuijb
Copy link

@thehuijb thehuijb commented Mar 20, 2020

Issue: 9209 Add an option to hide a story from the sidebar

What I did

I made an adjustment to how stories are written out to the sidebar to include a data-tags attribute which defaults to data-tags="none"

the tags can then be used to show or hide stories based on plain css selectors:
for instance one could add a rule to hide all stories with data-tags="hidden":

[data-tags=hidden] {
  display: none;
}

or more complex to hide all stories that do not have a certain TAG so you could show just the stories that belong to that TAG:

[data-tags]:not([data-tags~=TAG] {
  display: none;
}

NOTE: - these css options are not included in the PR one must add these depending on the solution they are looking for.

to add the tags to the stories you only need to add it to the default like so:

export default {
  title: 'Welcome',
  tags: 'hidden',
};

or to a specific story like this:

Button.story = {
  tags: 'hidden'
}

you can specify multiple tags using the pipe symbol | e.g. tags: 'web|app' to specify that the component or story belongs to the web and to the app
if you would add tags: 'web|app' to default and then add tags: 'web' to a story and tags: 'app' to another, one could show and hide different stories based on a selected TAG
if components are created under the same branch, the branch will receive the tags from all component and pipe | them together e.g. if one storyfile has

export default {
  title: 'Components/Category/Headings',
  tags: 'web'
}

and another storyfile has

export default {
  title: 'Components/Category/Buttons',
  tags: 'app'
}

the resulting link in the sidebar to Category will have data-tags="web|app"

How to test

  1. start one of the example apps
  2. add tags: 'hidden' to one of the stories files like described above
  3. refresh page and inspect the stories in the sidebar with the devtools
  4. see that the links in the sidebar contain data-tags attibutes
  • Is this testable with Jest or Chromatic screenshots? NO
  • Does this need a new example in the kitchen sink apps? probably NOT
  • Does this need an update to the documentation? YES included

If your answer is yes to any of these, please make sure to include it in your PR.

shilman and others added 10 commits March 26, 2020 10:38
fix storySort docs: rename 'sort' to 'order'
…m:thehuijb/storybook into feature-provide-means-for-tagging-stories

# Conflicts:
#	lib/api/src/lib/stories.ts
#	lib/ui/src/components/sidebar/SidebarStories.tsx
#	lib/ui/src/components/sidebar/Tree/ListItem.tsx
#	lib/ui/src/components/sidebar/treeview/treeview.tsx
@ndelangen
Copy link
Member

How come this PR has 316 commits & 200+ files changed?

@ndelangen ndelangen removed their assignment Mar 26, 2020
@thehuijb
Copy link
Author

How come this PR has 316 commits & 200+ files changed?

good question, how did that happen?
I rebased on the next branch, then did some rework to fix the conflicts you predicted.
guess I'm going to have to submit a new PR

@thehuijb thehuijb closed this Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.