Skip to content

Commit

Permalink
Addon-docs Props: Convert default prop value to string (#9525)
Browse files Browse the repository at this point in the history
Addon-docs Props: Convert default prop value to string
  • Loading branch information
shilman committed Jan 18, 2020
2 parents 93afd7f + 39e9739 commit dfffc21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/cra-ts-kitchen-sink/src/stories/Button.tsx
Expand Up @@ -5,6 +5,11 @@ interface ButtonProps {
* Simple click handler
*/
onClick?: () => void;

/**
* Is primary?
*/
primary: boolean;
}

/**
Expand All @@ -15,3 +20,7 @@ export const Button: FC<ButtonProps> = ({ children, onClick }) => (
{children}
</button>
);

Button.defaultProps = {
primary: true,
};
8 changes: 6 additions & 2 deletions lib/components/src/blocks/PropsTable/PropValue.tsx
Expand Up @@ -76,8 +76,12 @@ const PropSummary: FC<PropSummaryProps> = ({ 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;
if (isNil(detail)) {
return <PropText text={summary} />;
return <PropText text={summaryAsString} />;
}

return (
Expand All @@ -98,7 +102,7 @@ const PropSummary: FC<PropSummaryProps> = ({ value }) => {
}
>
<Expandable className="sbdocs-expandable">
<span>{summary}</span>
<span>{summaryAsString}</span>
<ArrowIcon icon={isOpen ? 'arrowup' : 'arrowdown'} />
</Expandable>
</WithTooltipPure>
Expand Down

0 comments on commit dfffc21

Please sign in to comment.