Storybook can't import docs from a package
See original GitHub issueDescribe the bug I have written a story for a component from an imported package. While the story loads up in Storybook, it doesn’t automatically import documentation from the package.
To Reproduce Steps to reproduce the behavior:
- Create a story for a component from an imported package e.g.
@blueprintjs/core
- Click on
Docs
on the storybook - Scroll down to args table
- See no description, no default values
Expected behavior See description and default values coming from the package
Code snippets
import React from 'react';
import { Breadcrumbs, IBreadcrumbProps, IBreadcrumbsProps } from '@blueprintjs/core';
export default {
title: 'Components/Breadcrumbs/Breadcrumbs',
component: Breadcrumbs,
};
const items: IBreadcrumbProps[] = [
{ href: '/folder', text: 'Folder One' },
{ href: '/folder/one', text: 'Folder Two' },
{ text: 'Document.xls' },
];
export const Default = (args: IBreadcrumbsProps) => <Breadcrumbs {...args} />;
Default.args = {
items,
collapseFrom: 'start',
} as IBreadcrumbsProps;
Screenshots See the Storybook Docs below
Even though the code in node_modules/@blueprintjs/core/lib/esm/components/breadcrumbs/breadcrumbs.d.ts
has included descriptions for props
export interface IBreadcrumbsProps extends IProps {
/**
* Callback invoked to render visible breadcrumbs. Best practice is to
* render a `<Breadcrumb>` element. If `currentBreadcrumbRenderer` is also
* supplied, that callback will be used for the current breadcrumb instead.
* @default Breadcrumb
*/
breadcrumbRenderer?: (props: IBreadcrumbProps) => JSX.Element;
/**
* Which direction the breadcrumbs should collapse from: start or end.
* @default Boundary.START
*/
collapseFrom?: Boundary;
/**
* Callback invoked to render the current breadcrumb, which is the last
* element in the `items` array.
*
* If this prop is omitted, `breadcrumbRenderer` will be invoked for the
* current breadcrumb instead.
*/
currentBreadcrumbRenderer?: (props: IBreadcrumbProps) => JSX.Element;
/**
* All breadcrumbs to display. Breadcrumbs that do not fit in the container
* will be rendered in an overflow menu instead.
*/
items: IBreadcrumbProps[];
/**
* The minimum number of visible breadcrumbs that should never collapse into
* the overflow menu, regardless of DOM dimensions.
* @default 0
*/
minVisibleItems?: number;
/**
* Props to spread to `OverflowList`. Note that `items`,
* `overflowRenderer`, and `visibleItemRenderer` cannot be changed.
*/
overflowListProps?: Partial<IOverflowListProps<IBreadcrumbProps>>;
/**
* Props to spread to the `Popover` showing the overflow menu.
*/
popoverProps?: IPopoverProps;
}
System
Environment Info:
System:
OS: macOS 11.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.1/bin/npm
Browsers:
Chrome: 87.0.4280.88
Edge: 87.0.664.66
Safari: 14.0.2
Additional context In our design system we would like to use components from Blueprint and display documentation accordingly on Storybook
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Docs Addon | Storybook: Frontend workshop for UI development
import { Meta, Story, Canvas } from '@storybook/addon-docs'; import { Checkbox } from ... Make sure that the versions for your @storybook/* packages...
Read more >How to package .scss files when publishing Storybook ...
1 Answer 1 ; import babel from "rollup-plugin-babel" ; import resolve from "@rollup/plugin-node-resolve" ; import external from "rollup-plugin-peer ...
Read more >@storybook/react-native - npm
TypeScript icon, indicating that this package has built-in type declarations ... Make sure to import the rn-addons.js file in the storybook ...
Read more >Serving Static Files - Storybook
You can import any media assets by simply importing (or requiring) them as shown below. import React from 'react'; import { storiesOf }...
Read more >How to resolve a path alias in Storybook - +return
import { ComponentStory, ComponentMeta } from '@storybook/react'; ... Module not found: Error: Can't resolve ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Eek! Thank you @shilman, I finally got it to load up the docs!
~Solution:~
~1) Import and extend
PureBreadcrumbs
as you did, but withFC
instead ofReact.FC
(If I change it back, it won’t work)~~2) In
Breadcrumbs.stories.tsx
don’t specifyDefault.args
explicitly. (If I change it back, it generates the error you mentioned:this.props.breadcrumbRenderer is not a function
)~~It’s strange, but I’m glad we’ve found a working solution! Must be a new year’s miracle… Thank you so much for your help.~
EDIT: I just had to supply the
breadcrumbRenderer
function and it worked right away as per your recommendation. Changed it back toReact.FC
and it worked fine tooI’ve updated the repro repo here https://github.com/dessskris/sb-extends-props for anyone’s future reference.
Happy New Year!
I think the reason MUI is working and Blueprint is failing is because the Button component extends MUI, whereas the Blueprint code is using Blueprint components directly.
The main.js override says “allow types coming from MUI/blueprint”. But there is another configuration that runs
react-docgen-typescript-plugin
on"**/*.tsx"
. This extracts the docgen information and adds it to the component likeButton.__docgenInfo = { some extracted json data }
, which gets transformed into what’s seen in the table.I tried creating the following in
Breadcrumbs.tsx
:It failed with the error:
In the short term, if your components extend/wrap existing components I’d expect that to work. Maybe you’ll have better luck with Blueprint than I did.
The longer-term fix is to restructure the code so that it’s possible to import type information directly from the type files distributed in node_modules. Pretty sure there’s already an open issue for this.