-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
More detailed props table #1485
Merged
ndelangen
merged 24 commits into
storybookjs:release/3.3
from
billyvg:prop-table-detailed
Sep 6, 2017
Merged
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bc63adf
Detailed formatting of arrayOf, shape, oneOf
billyvg 1d54f15
Add babel watch task
billyvg aa44f18
Merge branch 'master' into prop-table-detailed
ndelangen ba35434
Merge branch 'master' into prop-table-detailed
ndelangen bd7b139
Merge branch 'master' into prop-table-detailed
ndelangen 093dd01
Merge branch 'master' into prop-table-detailed
billyvg 7ce5673
addon info: make propTypes table better
billyvg 2f62f90
Merge branch 'master' into prop-table-detailed
billyvg eda55b9
Merge branch 'release/3.3' into prop-table-detailed
ndelangen e5152f5
Merge branch 'release/3.3' into prop-table-detailed
ndelangen 40a229e
cleanup deprecated tests
billyvg a54f714
cleanup <PrettyPropType>
billyvg 34333bd
add: styled components
billyvg ff6d332
Merge branch 'release/3.3' into prop-table-detailed
ndelangen 2fdeff5
removed in favor of glamorous component
billyvg 4c1ce1f
Merge branch 'release/3.3' into prop-table-detailed
Hypnosphi 81dae0b
Merge branch 'release/3.3' into prop-table-detailed
ndelangen 738a8c5
Merge branch 'release/3.3' into prop-table-detailed
billyvg c90b09e
fix: add key for OneOfType
billyvg 691771f
fix: use native buttons
billyvg 05e43d7
Merge branch 'release/3.3' into prop-table-detailed
Hypnosphi 569d3a2
Merge branch 'release/3.3' into prop-table-detailed
ndelangen e43d49b
ADD an example usage of complex PropType and add descriptions for Con…
ndelangen f2a9b66
Merge branch 'release/3.3' into prop-table-detailed
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅