-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1485 from billyvg/prop-table-detailed
More detailed props table
- Loading branch information
Showing
20 changed files
with
451 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
|
||
import PrettyPropType from './PrettyPropType'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const ArrayOf = ({ propType }) => | ||
<span> | ||
<span>[</span> | ||
<span> | ||
<PrettyPropType propType={propType.value} /> | ||
</span> | ||
<span>]</span> | ||
</span>; | ||
|
||
ArrayOf.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; | ||
|
||
export default ArrayOf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const Enum = ({ propType }) => | ||
<span> | ||
{propType.value.map(({ value }) => value).join(' | ')} | ||
</span>; | ||
|
||
Enum.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const InstanceOf = ({ propType }) => | ||
<span> | ||
{propType.value} | ||
</span>; | ||
|
||
InstanceOf.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; | ||
|
||
export default InstanceOf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
|
||
const ObjectType = () => | ||
<span> | ||
{'{}'} | ||
</span>; | ||
|
||
export default ObjectType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
|
||
import PrettyPropType from './PrettyPropType'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const ObjectOf = ({ propType }) => | ||
<span> | ||
{'{[<key>]: '} | ||
<PrettyPropType propType={propType.value} /> | ||
{'}'} | ||
</span>; | ||
|
||
ObjectOf.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; | ||
|
||
export default ObjectOf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
|
||
const ObjectType = () => | ||
<span> | ||
{'{}'} | ||
</span>; | ||
|
||
export default ObjectType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const OneOf = ({ propType }) => | ||
<span> | ||
{propType.value.map(({ value }) => value).join(' | ')} | ||
</span>; | ||
|
||
OneOf.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; | ||
|
||
export default OneOf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import PrettyPropType from './PrettyPropType'; | ||
import { TypeInfo } from './proptypes'; | ||
|
||
const OneOfType = ({ propType }) => { | ||
const length = propType.value.length; | ||
return ( | ||
<span> | ||
{propType.value | ||
.map((value, i) => [ | ||
<PrettyPropType | ||
key={`${value.name}${value.value ? `-${value.value}` : ''}`} | ||
propType={value} | ||
/>, | ||
i < length - 1 ? <span> | </span> : null, | ||
]) | ||
.reduce((acc, tuple) => acc.concat(tuple), [])} | ||
</span> | ||
); | ||
}; | ||
OneOfType.propTypes = { | ||
propType: TypeInfo.isRequired, | ||
}; | ||
export default OneOfType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import ObjectType from './ObjectType'; | ||
import Shape from './Shape'; | ||
import OneOfType from './OneOfType'; | ||
import ArrayOf from './ArrayOf'; | ||
import ObjectOf from './ObjectOf'; | ||
import OneOf from './OneOf'; | ||
import InstanceOf from './InstanceOf'; | ||
import Signature from './Signature'; | ||
|
||
import { TypeInfo } from './proptypes'; | ||
|
||
// propType -> Component map - these are a bit more complex prop types to display | ||
const propTypeComponentMap = new Map([ | ||
['shape', Shape], | ||
['union', OneOfType], | ||
['arrayOf', ArrayOf], | ||
['objectOf', ObjectOf], | ||
// Might be overkill to have below proptypes as separate components *shrug* | ||
['object', ObjectType], | ||
['enum', OneOf], | ||
['instanceOf', InstanceOf], | ||
['signature', Signature], | ||
]); | ||
|
||
const PrettyPropType = props => { | ||
const { propType, depth } = props; | ||
if (!propType) { | ||
return <span>unknown</span>; | ||
} | ||
|
||
const { name } = propType || {}; | ||
|
||
if (propTypeComponentMap.has(name)) { | ||
const Component = propTypeComponentMap.get(name); | ||
return <Component propType={propType} depth={depth} />; | ||
} | ||
|
||
// Otherwise, propType does not have a dedicated component, display proptype name by default | ||
return ( | ||
<span> | ||
{name} | ||
</span> | ||
); | ||
}; | ||
|
||
PrettyPropType.displayName = 'PrettyPropType'; | ||
|
||
PrettyPropType.defaultProps = { | ||
propType: null, | ||
depth: 1, | ||
}; | ||
|
||
PrettyPropType.propTypes = { | ||
propType: TypeInfo, | ||
depth: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default PrettyPropType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const styles = { | ||
hasProperty: { | ||
whiteSpace: 'nowrap', | ||
}, | ||
}; | ||
|
||
const PropertyLabel = ({ property, required }) => { | ||
if (!property) return null; | ||
|
||
return ( | ||
<span style={styles.hasProperty}> | ||
{property} | ||
{required ? '' : '?'}:{' '} | ||
</span> | ||
); | ||
}; | ||
|
||
PropertyLabel.propTypes = { | ||
property: PropTypes.string, | ||
required: PropTypes.bool, | ||
}; | ||
|
||
PropertyLabel.defaultProps = { | ||
property: '', | ||
required: false, | ||
}; | ||
|
||
export default PropertyLabel; |
Oops, something went wrong.