uncontrollable
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -19,6 +19,2 @@ 'use strict'; | ||
var _reactLibInvariant = require('react/lib/invariant'); | ||
var _reactLibInvariant2 = _interopRequireDefault(_reactLibInvariant); | ||
var _utils = require('./utils'); | ||
@@ -33,21 +29,11 @@ | ||
function uncontrollable(Component, controlledValues) { | ||
var displayName = 'Uncontrolled(' + (Component.displayName || Component.name || 'Component') + ')', | ||
var displayName = Component.displayName || Component.name || 'Component', | ||
basePropTypes = utils.getType(Component).propTypes, | ||
propTypes = {}; | ||
propTypes; | ||
if (process.env.NODE_ENV !== 'production' && basePropTypes) { | ||
utils.transform(controlledValues, function (obj, handler, prop) { | ||
var type = basePropTypes[prop]; | ||
propTypes = utils.uncontrolledPropTypes(controlledValues, basePropTypes, displayName); | ||
_reactLibInvariant2['default'](typeof handler === 'string' && handler.trim().length, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', Component.displayName, prop); | ||
obj[prop] = utils.customPropType(handler, type, Component.displayName); | ||
if (type !== undefined) obj[utils.defaultKey(prop)] = type; | ||
}, propTypes); | ||
} | ||
var component = _react2['default'].createClass({ | ||
displayName: displayName, | ||
displayName: 'Uncontrolled(' + displayName + ')', | ||
@@ -54,0 +40,0 @@ mixins: mixins, |
{ | ||
"name": "uncontrollable", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Wrap a controlled react component, to allow spcific prop/handler pairs to be uncontrolled", | ||
@@ -19,3 +19,9 @@ "author": { | ||
"form" | ||
] | ||
], | ||
"dependencies": { | ||
"invariant": "^2.1.0" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=0.11.0" | ||
} | ||
} |
31
utils.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
exports.customPropType = customPropType; | ||
exports.uncontrolledPropTypes = uncontrolledPropTypes; | ||
exports.getType = getType; | ||
@@ -20,10 +21,16 @@ exports.getLinkName = getLinkName; | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
function customPropType(handler, propType, name) { | ||
return function (props, propName, componentName, location) { | ||
return function (props, propName, componentName) { | ||
if (props[propName] !== undefined) { | ||
if (!props[handler]) return new Error('You have provided a `' + propName + '` prop to ' + '`' + name + '` without an `' + handler + '` handler. This will render a read-only field. ' + 'If the field should be mutable use `' + defaultKey(propName) + '`. Otherwise, set `' + handler + '`'); | ||
if (!props[handler]) { | ||
return new Error('You have provided a `' + propName + '` prop to ' + '`' + name + '` without an `' + handler + '` handler. This will render a read-only field. ' + 'If the field should be mutable use `' + defaultKey(propName) + '`. Otherwise, set `' + handler + '`'); | ||
} | ||
return propType && propType(props, propName, name, location); | ||
return propType && propType(props, propName, name); | ||
} | ||
@@ -33,2 +40,20 @@ }; | ||
function uncontrolledPropTypes(controlledValues, basePropTypes, displayName) { | ||
var propTypes = {}; | ||
if (process.env.NODE_ENV !== 'production' && basePropTypes) { | ||
transform(controlledValues, function (obj, handler, prop) { | ||
var type = basePropTypes[prop]; | ||
_invariant2['default'](typeof handler === 'string' && handler.trim().length, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', displayName, prop); | ||
obj[prop] = customPropType(handler, type, displayName); | ||
if (type !== undefined) obj[defaultKey(prop)] = type; | ||
}, propTypes); | ||
} | ||
return propTypes; | ||
} | ||
var version = _react2['default'].version.split('.').map(parseFloat); | ||
@@ -35,0 +60,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
16454
6
184
0
121
0
2
+ Addedinvariant@^2.1.0
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)