storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.68k stars 9.32k forks source link

Manager: Add options to hide sidebar and toolbar per story #29516

Open Sidnioulz opened 1 week ago

Sidnioulz commented 1 week ago

Closes #22081.

Context

What I did

What's left to do

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

Manual testing

  1. Edit code/.storybook/manager.tsx with the snippet below
  2. Run yarn storybook:ui
  3. Notice that on docs entries, the toolbar disappears, and it reappears on other entries
  4. Notice that on the unicode docs pages, the sidebar disappears; good luck navigating away from it :D

The snippet:

import { type State, addons } from 'storybook/internal/manager-api';

addons.setConfig({
  layoutCustomisations: {
    showSidebar(state: State, defaultValue: boolean) {
      if (state.viewMode === 'story' && state.storyId.startsWith('😀')) {
        return false;
      }

      return defaultValue;
    },
    showToolbar(state: State, defaultValue: boolean) {
      if (state.viewMode === 'docs') {
        return false;
      }

      return defaultValue;
    },
  },
});

Documentation

Checklist for Maintainers

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

_core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>_

Greptile Summary

This PR adds layout customization options to conditionally show/hide the Storybook toolbar and sidebar based on story context, primarily addressing the need to hide toolbars on documentation pages.

nx-cloud[bot] commented 1 week ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 84a0da278fa1195ec96fd5ad07c41ad5caf102c7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target - [`nx run-many -t build --parallel=3`](https://cloud.nx.app/runs/S5Xb1SIaRa?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.