question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook not rendering all React props in the controls and docs when using imported types

See original GitHub issue

Describe the bug Storybook is not showing all the props in controls and docs. It happens when I import a Typescript type from another file.

To Reproduce

  1. Create a file with some typing:
// colors.ts
export type TextColor = 'red' | 'blue';
  1. Then use the created type in a component
// Text.tsx
import React, { FC } from 'react';
import TextColor from './colors';

export type Props = {
  textColor: TextColor;
  text: string;
};

const Text: FC<Props> = ({ textColor, text }) => (
  <div style{{ color: textColor }}>{ text }</div>
)

If I do that, only text appears in the controls and docs.

Expected behavior All props should appear in the controls and docs panels.

Screenshots This is my props definition: image

This is what appears in controls. It is missing iconColor and color. image

This is what appears in docs. Also missing iconColor and color and icon has no description. image

This is the typing of Icons, TextColor and ButtonColor: image image

Code snippets See to reproduce section

System: System: OS: Windows 10 10.0.19041 CPU: (4) x64 Intel® Core™ i7-4500U CPU @ 1.80GHz Binaries: Node: 12.13.0 - C:\Program Files\nodejs\node.EXE npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 85.0.4183.102 Edge: Spartan (44.19041.423.0), Chromium (85.0.564.51) npmGlobalPackages: @storybook/cli: 6.0.21

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gregg-cbscommented, Mar 29, 2022

I am having this issue, all my other components work fine, but all of a sudden this new one doesnt? And i cant figure out why.

// storybook
import React from 'react'
import { ComponentStory } from '@storybook/react'

import IconText from '../../components/theme/Diageo/DIconText'
import LocationIcon from '../../components/icons/LocationIcon'

// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
  title: 'Base/IconText',
  component: IconText,
}

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof IconText> = (args) => <IconText {...args} />

export const Base = Template.bind({})
// IconText component
import React from 'react'

type IconTextProps = {
  icon: JSX.Element
  text: string
  reversed?: boolean
  className?: string
}

export default function IconText({ icon, text, reversed, className, ...props }: IconTextProps) {
  return (
    <div className={`icon-text ${className} ${reversed ? 'icon-text-reversed' : null}`} {...props}>
      <span className="icon-text-icon">{icon}</span>
      <span className="icon-text-text">{text}</span>
    </div>
  )
}

output: image

1reaction
jmpolitzercommented, Feb 25, 2021

@shilman Thanks for the response. It turns out that my issue revolved around components imported from an external library, which I found a fix for here. I believe this can be closed.

Screen Shot 2021-02-25 at 3 41 09 PM
Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with Storybook autogenerating docs/prop description for ...
I can get the Storybook controls to load properly. But the ArgsTable in the docs section does not respect my comments that I...
Read more >
ArgTypes - Storybook - JS.ORG
ArgTypes are a first-class feature in Storybook for specifying the behaviour of Args. By specifying the type of an arg, you constrain the...
Read more >
Build a simple component - Storybook Tutorials
The story is a function that returns a rendered element (i.e., a component with a set of props) in a given state---exactly like...
Read more >
Configure Storybook
js that matches all files in your project with extension .stories.* . The intention is you colocate a story file with the component...
Read more >
Material UI in Storybook
What's more, you'll need to express every design decision in a set of atomic ... Use Material UI prop types for better controls...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found