How to use the airbnb-prop-types.and 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
class ClassComp extends React.Component {
    render() {
        return null;
    }
}

function FuncComp() {
    return null;
}

// $ExpectType Requireable
AirbnbPropTypes.and([PropTypes.number]);
// $ExpectType Requireable
AirbnbPropTypes.and([PropTypes.number, AirbnbPropTypes.nonNegativeInteger]);
// $ExpectType Validator
AirbnbPropTypes.and([PropTypes.number, AirbnbPropTypes.integer()], 'foo').isRequired;

// $ExpectType Requireable
AirbnbPropTypes.between({ lt: 1 });
// $ExpectType Requireable
AirbnbPropTypes.between({ lte: 2 });
// $ExpectType Requireable
AirbnbPropTypes.between({ gt: 3 });
// $ExpectType Requireable
AirbnbPropTypes.between({ gte: 4 });
// $ExpectType Requireable
AirbnbPropTypes.between({ lt: 1, gt: 0 });

// $ExpectType Requireable
AirbnbPropTypes.booleanSome('foo', 'bar', 'baz');

// $ExpectType Requireable
github airbnb / react-dates / src / shapes / ModifiersShape.js View on Github external
import PropTypes from 'prop-types';
import { and } from 'airbnb-prop-types';

export default and([
  PropTypes.instanceOf(Set),
  function modifiers(props, propName, ...rest) {
    const { [propName]: propValue } = props;
    let firstError;
    [...propValue].some((v, i) => {
      const fakePropName = `${propName}: index ${i}`;
      firstError = PropTypes.string.isRequired(
        { [fakePropName]: v },
        fakePropName,
        ...rest,
      );
      return firstError != null;
    });
    return firstError == null ? null : firstError;
  },
], 'Modifiers (Set of Strings)');
github airbnb / lunar / packages / core / src / components / ProfilePhoto / index.tsx View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import { and, mutuallyExclusiveProps } from 'airbnb-prop-types';
import withStyles, { WithStylesProps } from '../../composers/withStyles';
import { styleSheet } from './styles';

const mutuallyExclusiveSizePropType = mutuallyExclusiveProps(
  PropTypes.any,
  'small',
  'large',
  'macro',
  'size',
);
const namedSizePropType = and([PropTypes.bool, mutuallyExclusiveSizePropType]);
const unitSizePropType = and([PropTypes.number, mutuallyExclusiveSizePropType]);

export type Props = {
  /** Fallback image if the image is broken. */
  fallbackImageSrc?: string;
  /** URL of the image to display. */
  imageSrc: string;
  /** Whether the component should be inline. */
  inline?: boolean;
  /** Large size (96px). */
  large?: boolean;
  /** Macro size (160px). */
  macro?: boolean;
  /** Size in units to multiply by. */
  size?: number;
  /** Small size (24px). */
github airbnb / lunar / packages / core / src / components / ProfilePhoto / index.tsx View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import { and, mutuallyExclusiveProps } from 'airbnb-prop-types';
import withStyles, { WithStylesProps } from '../../composers/withStyles';
import { styleSheet } from './styles';

const mutuallyExclusiveSizePropType = mutuallyExclusiveProps(
  PropTypes.any,
  'small',
  'large',
  'macro',
  'size',
);
const namedSizePropType = and([PropTypes.bool, mutuallyExclusiveSizePropType]);
const unitSizePropType = and([PropTypes.number, mutuallyExclusiveSizePropType]);

export type Props = {
  /** Fallback image if the image is broken. */
  fallbackImageSrc?: string;
  /** URL of the image to display. */
  imageSrc: string;
  /** Whether the component should be inline. */
  inline?: boolean;
  /** Large size (96px). */
  large?: boolean;
  /** Macro size (160px). */
  macro?: boolean;
  /** Size in units to multiply by. */
  size?: number;
  /** Small size (24px). */
  small?: boolean;