How to use the airbnb-prop-types.range function in airbnb-prop-types

To help you get started, we’ve selected a few airbnb-prop-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / airbnb-prop-types / airbnb-prop-types-tests.ts View on Github external
AirbnbPropTypes.nonNegativeNumber();

// $ExpectType Requireable
AirbnbPropTypes.numericString();

// $ExpectType Requireable
const props: PropTypes.Requireable = AirbnbPropTypes.object();
// $ExpectType Requireable<{ foo: string; }>
AirbnbPropTypes.object<{ foo: string }>();

AirbnbPropTypes.or([PropTypes.bool.isRequired, AirbnbPropTypes.explicitNull().isRequired]);
AirbnbPropTypes.or([PropTypes.bool, PropTypes.number, PropTypes.arrayOf(PropTypes.string)]);
AirbnbPropTypes.or([PropTypes.number, PropTypes.string, PropTypes.bool], 'foo');

// $ExpectType Requireable
AirbnbPropTypes.range(0, 10);
// $ExpectType Requireable<5>
AirbnbPropTypes.range<5>(0, 10);

// $ExpectType Requireable>
AirbnbPropTypes.ref();

// $ExpectType Requireable
AirbnbPropTypes.requiredBy('foo', PropTypes.string);
// $ExpectType Validator
AirbnbPropTypes.requiredBy('bar', PropTypes.number, 42).isRequired;

validateRequireableTop(AirbnbPropTypes.restrictedProp());
validateRequireableTop(AirbnbPropTypes.restrictedProp(() => 'Error'));
validateRequireableTop(AirbnbPropTypes.restrictedProp(() => new Error('Error')));

validateRequireableTop(AirbnbPropTypes.sequenceOf({ validator: PropTypes.number }));
github peterpalau / react-bnb-gallery / example / src / components / Title / index.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';

import { forbidExtraProps, range } from 'airbnb-prop-types';
import classnames from 'classnames';

const propTypes = forbidExtraProps({
  children: PropTypes.node.isRequired,
  level: range(1, 7),
});

const defaultProps = {
  level: 2,
};

const Title = ({
  children,
  level,
}) => {
  const Level = `h${level}`;
  return (