react-bootstrap/prop-types-extra

Name: prop-types-extra

Owner: react-bootstrap

Description: Additional PropTypes for React

Created: 2017-05-12 16:40:41.0

Updated: 2018-05-20 11:59:28.0

Pushed: 2018-05-01 15:11:30.0

Homepage:

Size: 62

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

prop-types-extra Travis npm

Additional PropTypes for React.

Usage
rt elementType from 'prop-types-extra/lib/elementType';
r
rt { elementType } from 'prop-types-extra';

t propTypes = {
meProp: elementType,

If you want to minimize bundle size, import only the validators you use via:

rt elementType from 'prop-types-extra/lib/elementType'
Guide
Installation
m i -S react
m i -S prop-types-extra
all(...validators)

This validator checks that all of the provided validators pass.

t propTypes = {
rtical:  PropTypes.bool.isRequired,

ock: all(
PropTypes.bool.isRequired,
({ block, vertical }) => (
  block && !vertical ?
    new Error('`block` requires `vertical` to be set to have any effect') :
    null
),


The provided validators will be validated in order, stopping on the first failure. The combined validator will succeed only if all provided validators succeed.

As in the example, this can be used to make a type assertion along with additional semantic assertions.

componentOrElement

Checks that the value is a ReactComponent or a DOMElement.

t propTypes = {
ntainer: componentOrElement,
quiredContainer: componentOrElement.isRequired,

This ensures that the value is of the right type to pass to ReactDOM.findDOMNode(), for cases where you need a DOM node.

deprecated(validator, reason)

This validator will log a deprecation warning if the value is present.

t propTypes = {
llapsable: deprecated(PropTypes.bool, 'Use `collapsible` instead.'),

If the collapsable prop above is specified, this validator will log the warning:

The prop `collapsable` of `MyComponent` is deprecated. Use `collapsible` instead.

This validator warns instead of failing on invalid values, and will still call the underlying validator if the deprecated value is present.

This validator will only warn once on each deprecation. To clear the cache of warned messages, such as for clearing state between test cases intended to fail on deprecation warnings, call deprecated._resetWarned().

elementType

Checks that the value is a React element type. This can be either a string (for DOM elements) or a ReactClass (for composite components).

t propTypes = {
mponent: elementType.isRequired,

This ensures that the value of is the right type for creating a ReactElement, such as with <Component {...props} />.

isRequiredForA11y(validator)

This validator checks that the value required for accessibility are present.

t propTypes = {
: isRequiredForA11y(PropTypes.string),

If the id prop above is not specified, the validator will fail with:

The prop `id` is required to make `MyComponent` accessible for users of assistive technologies such as screen readers.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.