Skip to content

Commit

Permalink
Merge pull request #2653 from abrahamgnz/master
Browse files Browse the repository at this point in the history
Add type check to PropType on OneOf
  • Loading branch information
Hypnosphi authored and shilman committed Feb 21, 2018
1 parent 250b4e8 commit acd5ab0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 6 additions & 7 deletions addons/info/src/components/types/OneOf.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
import { TypeInfo, getPropTypes } from './proptypes';

const OneOf = ({ propType }) => (
<span>
{getPropTypes(propType)
.map(({ value }) => value)
.join(' | ')}
</span>
);
const joinValues = propTypes => propTypes.map(({ value }) => value).join(' | ');

const OneOf = ({ propType }) => {
const propTypes = getPropTypes(propType);
return <span>{`oneOf ${Array.isArray(propTypes) ? joinValues(propTypes) : propTypes}`}</span>;
};

OneOf.propTypes = {
propType: TypeInfo.isRequired,
Expand Down
1 change: 1 addition & 0 deletions examples/official-storybook/components/DocgenButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ DocgenButton.propTypes = {
* `oneOf` is basically an Enum which is also supported but can be pretty big.
*/
enm: PropTypes.oneOf(['News', 'Photos']),
enmEval: PropTypes.oneOf((() => ['News', 'Photos'])()),
/**
* A multi-type prop is also valid and is displayed as `Union<String|Message>`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3592,6 +3592,31 @@ exports[`Storyshots Addon Info.React Docgen Comments from PropType declarations
class="css-d52hbj"
/>
</tr>
<tr>
<td
class="css-1ygfcef"
>
enmEval
</td>
<td
class="css-1ygfcef"
>
<span />
</td>
<td
class="css-d52hbj"
>
-
</td>
<td
class="css-d52hbj"
>
-
</td>
<td
class="css-d52hbj"
/>
</tr>
<tr>
<td
class="css-1ygfcef"
Expand Down

0 comments on commit acd5ab0

Please sign in to comment.