-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(injector): add reconcilePropTypes (#10)
- Loading branch information
Showing
8 changed files
with
154 additions
and
8 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
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,7 @@ | ||
import * as React from 'react'; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
} | ||
|
||
export default function Component(props: Props): JSX.Element; |
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,29 @@ | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { chainPropTypes } from 'some-utils-module'; | ||
|
||
function Component(props) { | ||
const { children } = props; | ||
return ( | ||
<button> | ||
<span>{children}</span> | ||
</button> | ||
); | ||
} | ||
|
||
Component.propTypes = { | ||
children: chainPropTypes(PropTypes.node.isRequired, (props) => { | ||
const summary = React.Children.toArray(props.children)[0]; | ||
if (isFragment(summary)) { | ||
return new Error('Not accepting Fragments'); | ||
} | ||
|
||
if (!React.isValidElement(summary)) { | ||
return new Error('First child must be an element'); | ||
} | ||
|
||
return null; | ||
}), | ||
}; | ||
|
||
export default Component; |
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 { TestOptions } from '../types'; | ||
|
||
const options: TestOptions = { | ||
injector: { | ||
removeExistingPropTypes: true, | ||
reconcilePropTypes: (prop, previous: any, generated) => { | ||
const isCustomValidator = previous !== undefined && !previous.startsWith('PropTypes'); | ||
|
||
if (isCustomValidator) { | ||
return previous; | ||
} | ||
return generated; | ||
}, | ||
}, | ||
}; | ||
|
||
export default options; |
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,29 @@ | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
import { chainPropTypes } from 'some-utils-module'; | ||
|
||
function Component(props) { | ||
const { children } = props; | ||
return ( | ||
<button> | ||
<span>{children}</span> | ||
</button> | ||
); | ||
} | ||
|
||
Component.propTypes = { | ||
children: chainPropTypes(PropTypes.node.isRequired, (props) => { | ||
const summary = React.Children.toArray(props.children)[0]; | ||
if (isFragment(summary)) { | ||
return new Error('Not accepting Fragments'); | ||
} | ||
|
||
if (!React.isValidElement(summary)) { | ||
return new Error('First child must be an element'); | ||
} | ||
|
||
return null; | ||
}), | ||
}; | ||
|
||
export default Component; |
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 @@ | ||
{ | ||
"type": "ProgramNode", | ||
"body": [ | ||
{ | ||
"type": "ComponentNode", | ||
"name": "Component", | ||
"types": [ | ||
{ | ||
"type": "PropTypeNode", | ||
"name": "children", | ||
"propType": { | ||
"type": "UnionNode", | ||
"types": [{ "type": "ElementNode", "elementType": "node" }, { "type": "UndefinedNode" }] | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |