Skip to content
This repository was archived by the owner on Aug 28, 2022. It is now read-only.

Commit 4493a8c

Browse files
eliperkinsatticoos
authored andcommitted
fix(prop-types): support PropTypes from either React or prop-types module (#61)
This ensures compatibility with React 16+ and his suppresses warnings for projects which do not include PropTypes or versions of React less than 15.5.
1 parent 638ed1f commit 4493a8c

File tree

8 files changed

+27
-6
lines changed

8 files changed

+27
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"node-jsdom": "^3.1.5",
4646
"nps": "^5.1.0",
4747
"nps-utils": "^1.2.0",
48+
"prop-types": "^15.5.10",
4849
"react": "16.0.0-alpha.6",
4950
"react-addons-test-utils": "^15.5.1",
5051
"react-dom": "^15.5.4",

src/__tests__/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint func-style:0, react/prop-types:0 */
22
import 'react-native-mock-render/mock' // eslint-disable-line
33
import React from 'react'
4+
import PropTypes from 'prop-types'
45
import {StyleSheet, View} from 'react-native'
56
import renderer from 'react-test-renderer'
67
import {shallow} from 'enzyme'
@@ -375,7 +376,7 @@ it('should accept user defined contextTypes', () => {
375376
const dynamicStyles = jest.fn()
376377
const Child = glamorous.view(dynamicStyles)
377378
Child.contextTypes = {
378-
fontSize: React.PropTypes.number,
379+
fontSize: PropTypes.number,
379380
}
380381

381382
const context = {

src/__tests__/with-theme.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint func-style:0, react/prop-types:0 */
2-
import React, {PropTypes} from 'react'
2+
import React from 'react'
3+
import PropTypes from 'prop-types'
34
import {View} from 'react-native'
45
import renderer from 'react-test-renderer'
56

src/create-glamorous.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, {PropTypes} from 'react'
1+
import React from 'react'
22
import {StyleSheet} from 'react-native'
33
import {CHANNEL} from './constants'
44
import getStyles from './get-styles'
5+
import PropTypes from './react-compat'
56

67
function prepareStyles(styles) {
78
return styles.filter(style => {

src/react-compat.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
// eslint-disable-next-line import/no-mutable-exports
4+
let PropTypes
5+
6+
if (parseFloat(React.version.slice(0, 4)) >= 15.5) {
7+
try {
8+
PropTypes = require('prop-types')
9+
} catch (error) {
10+
// ignore
11+
}
12+
}
13+
PropTypes = PropTypes || React.PropTypes
14+
15+
export default PropTypes

src/theme-provider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, {PropTypes} from 'react'
1+
import React from 'react'
22
import brcast from 'brcast'
33
import {CHANNEL} from './constants'
4+
import PropTypes from './react-compat'
45

56
export default class ThemeProvider extends React.Component {
67
static childContextTypes = {

src/with-theme.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, {PropTypes} from 'react'
1+
import React from 'react'
22
import {CHANNEL} from './constants'
3+
import PropTypes from './react-compat'
34

45
function generateWarningMessage(componentName) {
56
// eslint-disable-next-line max-len

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5089,7 +5089,7 @@ promise@^7.1.1:
50895089
dependencies:
50905090
asap "~2.0.3"
50915091

5092-
prop-types@^15.5.4, prop-types@~15.5.7:
5092+
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@~15.5.7:
50935093
version "15.5.10"
50945094
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
50955095
dependencies:

0 commit comments

Comments
 (0)