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

Conditionally include the Description column for the PropsTable component #385

Merged
merged 5 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/basic/src/components/Alert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const AlertStyled = styled('div')`
export const Alert = props => <AlertStyled {...props} />

Alert.propTypes = {
/** `info`, `positive`, `negative`, or `warning` */
kind: t.oneOf(['info', 'positive', 'negative', 'warning']),
}

Expand Down
18 changes: 14 additions & 4 deletions packages/docz/src/components/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ const BasePropsTable: SFC<PropsTable> = ({ of: component, components }) => {
return null
}

const includeDescription: boolean = Object.keys(props).some(
(name: string) =>
props[name] &&
typeof props[name].description !== 'undefined' &&
props[name].description !== ''
)
const Table = components.table || 'table'
const Thead = components.thead || 'thead'
const Tr = components.tr || 'tr'
Expand All @@ -122,9 +128,11 @@ const BasePropsTable: SFC<PropsTable> = ({ of: component, components }) => {
<Th className="PropsTable--type">Type</Th>
<Th className="PropsTable--required">Required</Th>
<Th className="PropsTable--default">Default</Th>
<Th width="40%" className="PropsTable--description">
Description
</Th>
{includeDescription && (
<Th width="40%" className="PropsTable--description">
Description
</Th>
)}
</Tr>
</Thead>
<Tbody>
Expand All @@ -142,7 +150,9 @@ const BasePropsTable: SFC<PropsTable> = ({ of: component, components }) => {
{prop.defaultValue &&
prop.defaultValue.value.replace(/\'/g, '')}
</Td>
<Td>{prop.description && prop.description}</Td>
{includeDescription && (
<Td>{prop.description && prop.description}</Td>
)}
</Tr>
)
})}
Expand Down