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
1 parent 2039097 commit 850ca06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/cra-ts-kitchen-sink/src/stories/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ interface ButtonProps {
/**
* Is primary?
*/
primary: boolean;
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
Original file line number Diff line number Diff line change
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

0 comments on commit 850ca06

Please sign in to comment.