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.

Typescript CSF Format Docs do not display props

See original GitHub issue

Description I am converting my component library to typescript and when I update to typescript doc’s props no longer show up

To Reproduce Adding prop type comments and type comments do not display for props in the table on the docs page. This works for my non typescript components. I added comments for my type as well.

Expected behavior Props to display

Screenshots If applicable, add screenshots to help explain your problem.

Code snippets

Label.tsx 
------------------
import React, { useContext } from "react";
import { ThemeContext } from "styled-components";
import PropTypes from "prop-types";
import { AsteriskStyled, LabelStyled, LabelStyles } from "./LabelStyles";

export interface LabelProps {
  /** content to display in label */
  children: React.ReactNode
  /** ID the label is for */
  htmlFor: string,
  /** if the label is required */
  required?: boolean,
  /** Overrideable styles */
  styles?: LabelStyles,
  rest?: object
}

/**
 * Label for an input
 */
export const Label: React.FC<LabelProps> = ({ children, htmlFor, required, styles, ...rest }) => {
  const Theme = useContext(ThemeContext);
  const StylesOverride = { ...Theme.label, ...styles };

  return (
    <>
      <LabelStyled htmlFor={htmlFor} styles={StylesOverride} {...rest}>
        {children}
      </LabelStyled>
      {required && <AsteriskStyled styles={StylesOverride}>*</AsteriskStyled>}
    </>
  );
};

Label.propTypes = {
  /** content to display in label */
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.string, PropTypes.element, PropTypes.number]).isRequired,
  /** ID the label is for */
  htmlFor: PropTypes.string.isRequired,
  /** if the label is required */
  required: PropTypes.bool,
  /** Overrideable styles */
  styles: PropTypes.shape({
    color: PropTypes.string,
    "font-weight": PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    "asterisk-color": PropTypes.string
  })
};

Label.defaultProps = {
  required: false,
  styles: {}
};

export default Label;

Label.stories.tsx
---------------------
import React from "react";
import { Description, Primary, Props, Subtitle, Title } from "@storybook/addon-docs/dist/blocks";
import { boolean } from "@storybook/addon-knobs";
import Label from "./Label";
import { SlotContext, StoryData } from "@storybook/addon-docs/dist/blocks/shared";

export default { title: "Form|Inputs" };

export const LabelExample = () => {
  return (
    <Label required={boolean("required",true)} htmlFor="hello-world-1">
      Hello World
    </Label>
  );
};

LabelExample.story = {
  name: "Label",
  title: "Label",
  component: Label,
  parameters: {
    docs: {
      page: () => (
        <>
          <Title>Label</Title>
          <Subtitle />
          <Description />
          <Primary slot={
            (stories: StoryData[], context: SlotContext) =>  stories.find((story: StoryData) => story.id === context.id) || stories[0]
          }/>
          <Props
            components={{
              "Label": Label
            }}
          />
        </>
      ),
    },
  },
};

System: Environment Info:

System: OS: macOS 10.15.3 CPU: (4) x64 Intel® Core™ i7-6567U CPU @ 3.30GHz Binaries: Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm Browsers: Chrome: 80.0.3987.163 Firefox: 74.0.1 Safari: 13.0.5 npmPackages: @storybook/addon-a11y: 5.3.18 => 5.3.18 @storybook/addon-actions: 5.3.18 => 5.3.18 @storybook/addon-backgrounds: 5.3.18 => 5.3.18 @storybook/addon-docs: 5.3.18 => 5.3.18 @storybook/addon-knobs: 5.3.18 => 5.3.18 @storybook/addon-links: 5.3.18 => 5.3.18 @storybook/addon-storysource: 5.3.18 => 5.3.18 @storybook/addon-viewport: 5.3.18 => 5.3.18 @storybook/addons: 5.3.18 => 5.3.18 @storybook/preset-typescript: ^3.0.0 => 3.0.0 @storybook/react: 5.3.18 => 5.3.18 @storybook/theming: 5.3.18 => 5.3.18

Additional context I am using storybook 5.3.18 and the preset typescript to compile typescript with a typescript config of

{
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ],
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "preserve",
    "lib": ["es5", "es6", "es7", "es2017", "dom"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitThis": true,
    "outDir": "./dist/",
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5",
    "strict": true,
    "rootDirs": ["src"],
    "baseUrl": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true
  }
}

I messed with jsx between preserve and react

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
whatwg6commented, Apr 11, 2020

Terrible Code snippets!😒

0reactions
stale[bot]commented, Aug 8, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component Story Format (CSF) - Storybook
Component Story Format (CSF) is the recommended way to write stories. It's an open standard based on ES6 modules that is portable beyond...
Read more >
Adventures with Storybook, TypeScript, and Styled Components
If the name of the variable assigned to the component does not match its displayName exactly, props won't be pulled into the ArgsTable....
Read more >
storybook/addon-docs - npm
DocsPage is a zero-config aggregation of your component stories, text descriptions, docgen comments, props tables, and code examples into ...
Read more >
What makes up a Story?
Storybook supports Component Story Format (CSF), an open standard ... you can set the title, which will be shown in the list of...
Read more >
Component Story Format - WebComponents.dev
In CSF, stories and component metadata are defined as ES Modules. Every component story file consists of a required default export and one...
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