Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs Props: Convert default prop value to string #9525

Merged
merged 2 commits into from Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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