This repository was archived by the owner on Mar 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
packages/react-component-ref Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 "bugs" : " https://github.com/stardust-ui/react/issues" ,
77 "dependencies" : {
88 "@babel/runtime" : " ^7.1.2" ,
9- "@stardust-ui/react-proptypes" : " ^0.37.0" ,
109 "prop-types" : " ^15.7.2" ,
1110 "react-is" : " ^16.6.3"
1211 },
Original file line number Diff line number Diff line change 1- import * as customPropTypes from '@stardust-ui/react-proptypes'
21import * as PropTypes from 'prop-types'
32import * as React from 'react'
43import * as ReactIs from 'react-is'
54
65import RefFindNode from './RefFindNode'
76import RefForward from './RefForward'
8- import { RefProps } from './types'
7+ import { RefProps , refPropType } from './types'
98
109const Ref : React . FunctionComponent < RefProps > = props => {
1110 const { children, innerRef } = props
@@ -17,9 +16,12 @@ const Ref: React.FunctionComponent<RefProps> = props => {
1716}
1817
1918Ref . displayName = 'Ref'
20- Ref . propTypes = {
21- children : PropTypes . element . isRequired ,
22- innerRef : customPropTypes . ref . isRequired as PropTypes . Validator < React . Ref < any > > ,
19+ // TODO: use Babel plugin for this
20+ if ( process . env . NODE_ENV !== 'production' ) {
21+ Ref . propTypes = {
22+ children : PropTypes . element . isRequired ,
23+ innerRef : refPropType . isRequired ,
24+ }
2325}
2426
2527export default Ref
Original file line number Diff line number Diff line change 1- import * as customPropTypes from '@stardust-ui/react-proptypes'
21import * as PropTypes from 'prop-types'
32import * as React from 'react'
43import * as ReactDOM from 'react-dom'
54
65import handleRef from './handleRef'
7- import { RefProps } from './types'
6+ import { RefProps , refPropType } from './types'
87
98export default class RefFindNode extends React . Component < RefProps > {
109 static displayName = 'RefFindNode'
1110
12- static propTypes = {
13- children : PropTypes . element . isRequired ,
14- innerRef : customPropTypes . ref . isRequired as PropTypes . Validator < React . Ref < any > > ,
15- }
11+ // TODO: use Babel plugin for this
12+ static propTypes =
13+ process . env . NODE_ENV !== 'production'
14+ ? {
15+ children : PropTypes . element . isRequired ,
16+ innerRef : refPropType . isRequired ,
17+ }
18+ : { }
1619
1720 prevNode : Node | null = null
1821
Original file line number Diff line number Diff line change 1- import * as customPropTypes from '@stardust-ui/react-proptypes'
21import * as PropTypes from 'prop-types'
32import * as React from 'react'
43
54import handleRef from './handleRef'
6- import { RefProps } from './types'
5+ import { RefProps , refPropType } from './types'
76
87export default class RefForward extends React . Component < RefProps > {
98 static displayName = 'RefForward'
109
11- static propTypes = {
12- children : PropTypes . element . isRequired ,
13- innerRef : customPropTypes . ref . isRequired as PropTypes . Validator < React . Ref < any > > ,
14- }
10+ // TODO: use Babel plugin for this
11+ static propTypes =
12+ process . env . NODE_ENV !== 'production'
13+ ? {
14+ children : PropTypes . element . isRequired ,
15+ innerRef : refPropType . isRequired ,
16+ }
17+ : { }
1518
1619 handleRefOverride = ( node : HTMLElement ) => {
1720 const { children, innerRef } = this . props
Original file line number Diff line number Diff line change 11import * as React from 'react'
22
3- /**
4- * Check that the passed object is a valid React ref object.
5- */
3+ /** Checks that the passed object is a valid React ref object. */
64const isRefObject = ( ref : any ) : ref is React . RefObject < any > =>
75 // https://github.com/facebook/react/blob/v16.8.2/packages/react-reconciler/src/ReactFiberCommitWork.js#L665
86 ref !== null && typeof ref === 'object' && ref . hasOwnProperty ( 'current' )
Original file line number Diff line number Diff line change @@ -5,9 +5,7 @@ const nullRefObject: React.RefObject<null> = { current: null }
55// A map of created ref objects to provide memoization.
66const refObjects = new WeakMap < Node , React . RefObject < Node > > ( )
77
8- /**
9- * Creates a React ref object from existing DOM node.
10- */
8+ /** Creates a React ref object from existing DOM node. */
119const toRefObject = < T extends Node > ( node : T ) : React . RefObject < T > => {
1210 // A "null" is not valid key for a WeakMap
1311 if ( node === null ) {
Original file line number Diff line number Diff line change 1+ import * as PropTypes from 'prop-types'
12import * as React from 'react'
23
34export interface RefProps {
@@ -10,3 +11,9 @@ export interface RefProps {
1011 */
1112 innerRef : React . Ref < any >
1213}
14+
15+ /** A checker that matches the React.Ref type. */
16+ export const refPropType = PropTypes . oneOfType ( [
17+ PropTypes . func ,
18+ PropTypes . object ,
19+ ] ) as PropTypes . Requireable < React . Ref < any > >
You can’t perform that action at this time.
0 commit comments