Skip to content

Commit

Permalink
Addon-docs: Fix TS false default value in prop table (#9560)
Browse files Browse the repository at this point in the history
Addon-docs:  Fix TS false default value in prop table
  • Loading branch information
shilman committed Jan 21, 2020
2 parents cf20e87 + 54bf0e3 commit 1deaeff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/cra-ts-kitchen-sink/src/stories/Button.tsx
Expand Up @@ -10,6 +10,11 @@ interface ButtonProps {
* Is primary?
*/
primary?: boolean;

/**
* default is false
*/
secondary: boolean;
}

/**
Expand All @@ -23,4 +28,5 @@ export const Button: FC<ButtonProps> = ({ children, onClick }) => (

Button.defaultProps = {
primary: true,
secondary: false,
};
5 changes: 3 additions & 2 deletions lib/components/src/blocks/PropsTable/PropValue.tsx
Expand Up @@ -75,11 +75,12 @@ const PropSummary: FC<PropSummaryProps> = ({ value }) => {
const { summary, detail } = value;

const [isOpen, setIsOpen] = useState(false);

// summary is used for the default value
// below check fixes not displaying default values for boolean typescript vars
const summaryAsString =
summary && typeof summary.toString === 'function' ? summary.toString() : summary;
summary !== undefined && summary !== null && typeof summary.toString === 'function'
? summary.toString()
: summary;
if (isNil(detail)) {
return <PropText text={summaryAsString} />;
}
Expand Down

1 comment on commit 1deaeff

@vercel
Copy link

@vercel vercel bot commented on 1deaeff Jan 21, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.