-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Image): use React.forwardRef() (#4234)
- Loading branch information
1 parent
b6ede3f
commit 0df28d3
Showing
13 changed files
with
148 additions
and
52 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
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,21 @@ | ||
import React from 'react' | ||
import { sandbox } from 'test/utils' | ||
|
||
/** | ||
* Assert a Component correctly implements a shorthand create method. | ||
* @param {React.Component} Component The component to test | ||
*/ | ||
export default function implementsCreateMethod(Component, options = {}) { | ||
describe('forwardsRef', () => { | ||
const { requiredProps = {}, tagName = 'div' } = options | ||
|
||
it(`forwards ref to "${tagName}"`, () => { | ||
const ref = sandbox.spy() | ||
|
||
mount(<Component {...requiredProps} ref={ref} />) | ||
|
||
ref.should.have.been.calledOnce() | ||
ref.should.have.been.calledWithMatch({ tagName: tagName.toUpperCase() }) | ||
}) | ||
}) | ||
} |
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
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 * as ReactIs from 'react-is' | ||
|
||
/** | ||
* Gets a proper `displayName` for a component. | ||
* | ||
* @param {React.ElementType} Component | ||
* @return {String} | ||
*/ | ||
export default function getComponentName(Component) { | ||
if (Component.$$typeof === ReactIs.Memo) { | ||
return getComponentName(Component.type) | ||
} | ||
|
||
if (Component.$$typeof === ReactIs.ForwardRef) { | ||
return Component.displayName | ||
} | ||
|
||
return Component.prototype?.constructor?.name | ||
} |
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,20 @@ | ||
import * as ReactIs from 'react-is' | ||
|
||
/** | ||
* Gets proper props for a component. | ||
* | ||
* @param {React.ElementType} Component | ||
* @return {Object} | ||
*/ | ||
export default function getComponentProps(Component) { | ||
if (Component.$$typeof === ReactIs.Memo) { | ||
return getComponentProps(Component.type) | ||
} | ||
|
||
return { | ||
autoControlledProps: Component.autoControlledProps, | ||
defaultProps: Component.defaultProps, | ||
handledProps: Component.handledProps, | ||
propTypes: Component.propTypes, | ||
} | ||
} |
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