@dhis2/prop-types
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -12,2 +12,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "conditional", { | ||
enumerable: true, | ||
get: function get() { | ||
return _conditional.conditional; | ||
} | ||
}); | ||
Object.defineProperty(exports, "instanceOfComponent", { | ||
@@ -37,2 +43,4 @@ enumerable: true, | ||
var _conditional = require("./conditional"); | ||
var _instanceOfComponent = require("./instanceOfComponent.js"); | ||
@@ -47,2 +55,3 @@ | ||
_propTypes.default.arrayWithLength = _arrayWithLength.arrayWithLength; | ||
_propTypes.default.conditional = onditional; | ||
_propTypes.default.instanceOfComponent = _instanceOfComponent.instanceOfComponent; | ||
@@ -49,0 +58,0 @@ _propTypes.default.mutuallyExclusive = _mutuallyExclusive.mutuallyExclusive; |
import propTypes from 'prop-types'; | ||
import { arrayWithLength } from './arrayWithLength.js'; | ||
import { conditional } from './conditional'; | ||
import { instanceOfComponent } from './instanceOfComponent.js'; | ||
@@ -7,6 +8,7 @@ import { mutuallyExclusive } from './mutuallyExclusive.js'; | ||
propTypes.arrayWithLength = arrayWithLength; | ||
propTypes.conditional = onditional; | ||
propTypes.instanceOfComponent = instanceOfComponent; | ||
propTypes.mutuallyExclusive = mutuallyExclusive; | ||
propTypes.requiredIf = requiredIf; | ||
export { arrayWithLength, instanceOfComponent, mutuallyExclusive, requiredIf }; | ||
export { arrayWithLength, conditional, instanceOfComponent, mutuallyExclusive, requiredIf }; | ||
export default propTypes; |
@@ -0,1 +1,8 @@ | ||
## [1.6.1](https://github.com/dhis2/prop-types/compare/v1.6.0...v1.6.1) (2020-03-31) | ||
### Bug Fixes | ||
* **conditional:** expose prop type publicly ([9439a60](https://github.com/dhis2/prop-types/commit/9439a60cfe2ab6493848e548d46045b0f6cca8c7)) | ||
# [1.6.0](https://github.com/dhis2/prop-types/compare/v1.5.0...v1.6.0) (2020-03-27) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@dhis2/prop-types", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"main": "./build/cjs/index.js", | ||
@@ -5,0 +5,0 @@ "module": "./build/es/index.js", |
@@ -19,2 +19,5 @@ # DHIS2 propTypes | ||
</dd> | ||
<dt><a href="#conditional">conditional(propsToPropType)</a> ⇒ <code>Error</code> | <code>null</code></dt> | ||
<dd><p>Conditionally determines a prop type bases on the passed props</p> | ||
</dd> | ||
<dt><a href="#instanceOfComponent">instanceOfComponent(Component)</a> ⇒ <code>Error</code> | <code>null</code></dt> | ||
@@ -62,2 +65,44 @@ <dd><p>Ensure the prop value is an instance of a certain component</p> | ||
``` | ||
<a name="conditional"></a> | ||
## conditional(propsToPropTypes) ⇒ <code>Error</code> \| <code>null</code> | ||
Determine the prop type of a prop by the value(s) of a/several passed prop(s). | ||
This will restrict the propType in contrast to `oneOfType`. | ||
**Kind**: global function | ||
**Returns**: <code>Error</code> \| <code>null</code> - Returns null if all conditions are met, or an error | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| propsToPropType | <code>Function</code> | | The function that will determine the actual prop type | | ||
**Example** | ||
```js | ||
import React from 'react' | ||
import { conditional } from '@dhis2/prop-types' | ||
const Select = ({ multiple, selected: _selected, options }) => { | ||
const selected = multiple ? _selected : [ _selected ] | ||
return ( | ||
// ... | ||
) | ||
} | ||
const option = propTypes.shape({ | ||
value: propTypes.string.isReuqired, | ||
labe: propTypes.string.isReuqired, | ||
}) | ||
LotsOfLists.propTypes = { | ||
// ... | ||
options: propTypes.arrayOf(option).isRequired, | ||
selected: conditional( | ||
props => props.multiple ? propTypes.arrayOf(option) : option | ||
).isRequired, | ||
// ... | ||
} | ||
``` | ||
<a name="instanceOfComponent"></a> | ||
@@ -64,0 +109,0 @@ |
73725
1451
205