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

Add Addon migration guide for Storybook 7.0 page #21932

Merged
merged 3 commits into from
Apr 5, 2023
Merged

Conversation

kylegach
Copy link
Contributor

@kylegach kylegach commented Apr 4, 2023

What I did

  • Add new docs page: Addon migration guide for Storybook 7.0 at /docs/addons/addon-migration-guide

image

How to test

Follow the documentation contribution instructions for this branch, addon-migration-docs.

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@kylegach kylegach added documentation patch:yes Bugfix & documentation PR that need to be picked to main branch labels Apr 4, 2023
@kylegach kylegach self-assigned this Apr 4, 2023
@kylegach
Copy link
Contributor Author

kylegach commented Apr 4, 2023

@ndelangen — I noticed this sentence in the full migration notes:

The addons export is now a named export only, there's no default export anymore, so make sure to update this usage.

I opted not to include that here. My thinking is that if they're making the code changes to accommodate that breaking change, we might as well point them only to the new packages and not to an already-deprecated technique.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good for @ndelangen to review too

Copy link
Contributor

@jonniebigodes jonniebigodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylegach going to approve this to avoid blocking you, as @shilman already covered the feedback that I had in his comments. Thanks for taking the time to put this together. Appreciate it.

Co-authored-by: Michael Shilman <shilman@users.noreply.github.com>
@kylegach kylegach merged commit 08d48da into next Apr 5, 2023
@kylegach kylegach deleted the addon-migration-docs branch April 5, 2023 17:57
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Apr 6, 2023
@harellevy
Copy link

Here is what I did for addon-notes support in storybook 7, I added this custom panel to the manager.js file:
I'm not a react developer and didn't knew how to do this if else correctly in the template so sorry for that lines...

import { addons, types } from '@storybook/addons';
import React from 'react';
import { useStorybookState } from '@storybook/api';
import { Link as RouterLink } from '@storybook/router';
import { AddonPanel, SyntaxHighlighter as SyntaxHighlighterBase } from '@storybook/components';
import 'github-markdown-css/github-markdown.css';
import theme from './theme';
import Markdown from 'markdown-to-jsx';
addons.register('my/panel', (api) => {
  addons.add('my-panel-addon/panel', {
    title: 'Notes',
    type: types.TAB,
    id: '123',
    route: ({ storyId }) => `/my-addon/${storyId}`,
    match: ({ viewMode }) => viewMode === 'my-addon',
    render: ({ active, key }) => {
      const state = useStorybookState();
      const story = state.storiesHash[state.storyId];
      const notes = story && story.parameters && story.parameters.notes.markdown;
      if (notes) {
        const NotesLink = ({ href, children, ...props }) => {
          const isAbsoluteUrl = /^[a-z][a-z0-9+.-]*:/.test(href);
          const isAnchorUrl = /^#.*/.test(href);

          if (isAbsoluteUrl || isAnchorUrl) {
            return (
              <a href={href} {...props}>
                {children}
              </a>
            );
          }
          return (
            <RouterLink to={href} {...props}>
              {children}
            </RouterLink>
          );
        };

        const SyntaxHighlighter = ({
                                     className,
                                     children,
                                     ...props
                                   }) => {
          // markdown-to-jsx does not add className to inline code
          if (typeof className !== "string") {
            return <code>{children}</code>;
          }
          // className: "lang-jsx"
          const language = className.split("-");

          return (
            <SyntaxHighlighterBase
              language={language[1] || "plaintext"}
              bordered
              format={false}
              copyable
              {...props}
            >
              {children}
            </SyntaxHighlighterBase>
          );
        };

        const defaultOptions = {
          overrides: {
            code: SyntaxHighlighter,
            a: NotesLink,
          },
        };
        const extraElements = Object.entries(
          api.getElements(types.NOTES_ELEMENT)
        ).reduce((acc, [k, v]) => ({ ...acc, [k]: v.render }), {});
        const options = {
          ...defaultOptions,
          overrides: { ...defaultOptions.overrides, ...extraElements },
        };
        return (
          <AddonPanel key={key} active={active}>
            <div className='addon-notes-container markdown-body' style={{ padding: '16px' }}>
              <Markdown options={options}>{notes}</Markdown>
            </div>
          </AddonPanel>
        );
      } else {
        return (
          <AddonPanel key={key} active={active}>
            <div className='addon-notes-container markdown-body' style={{ padding: '16px' }}>
            </div>
          </AddonPanel>
        );
      }

    },
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants