How to use the airbnb-prop-types.requiredBy 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.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 }));
validateRequireableTop(AirbnbPropTypes.sequenceOf({ validator: PropTypes.number }, { validator: PropTypes.string }));
validateRequireableTop(AirbnbPropTypes.sequenceOf(
    { validator: PropTypes.number, min: 0, max: 10 },
    { validator: PropTypes.string },
    { validator: PropTypes.bool },
));

interface ShapeShape {
github DefinitelyTyped / DefinitelyTyped / types / airbnb-prop-types / airbnb-prop-types-tests.ts View on Github external
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 }));
validateRequireableTop(AirbnbPropTypes.sequenceOf({ validator: PropTypes.number }, { validator: PropTypes.string }));
validateRequireableTop(AirbnbPropTypes.sequenceOf(
    { validator: PropTypes.number, min: 0, max: 10 },
    { validator: PropTypes.string },
    { validator: PropTypes.bool },
));

interface ShapeShape {
    foo: string;
    bar?: number | null;
github airbnb / lunar / packages / core / src / components / Pagination / index.tsx View on Github external
<div>
        {nextPage}
        {lastPage}
      </div>
    
  );
}

const alignProp = mutuallyExclusiveTrueProps('centerAlign', 'endAlign', 'startAlign');

Pagination.propTypes = {
  centerAlign: alignProp,
  endAlign: alignProp,
  pageCount: requiredBy('showBookends', PropTypes.number),
  startAlign: alignProp,
  onFirst: requiredBy('showBookends', PropTypes.func),
  onLast: requiredBy('showBookends', PropTypes.func),
};

export default Pagination;
github airbnb / lunar / packages / core / src / components / TextArea / index.tsx View on Github external
/** Add "notranslate" className to prevent Google Chrome translation. */
    noTranslate?: boolean;
    /** Enable proofreader to run spelling and grammar checks. */
    proofread?: boolean;
    /** Additional props that determine more proofreader functionality */
    proofreadProps?: ExtraProofreadProps;
  };

export type State = {
  id: string;
};

/** A controlled textarea field. */
export default class TextArea extends React.Component {
  static propTypes = {
    onCheckText: requiredBy('proofread', PropTypes.func),
  };

  static defaultProps = {
    locale: 'none',
    noTranslate: false,
    proofread: false,
    proofreadProps: undefined,
  };

  state = {
    id: uuid(),
  };

  render() {
    const { fieldProps, inputProps } = partitionFieldProps(this.props);
    const { locale, name, proofread, proofreadProps, onCheckText, ...textareaProps } = inputProps;
github airbnb / lunar / packages / core / src / components / Pagination / index.tsx View on Github external
<div>
        {nextPage}
        {lastPage}
      </div>
    
  );
}

const alignProp = mutuallyExclusiveTrueProps('centerAlign', 'endAlign', 'startAlign');

Pagination.propTypes = {
  centerAlign: alignProp,
  endAlign: alignProp,
  pageCount: requiredBy('showBookends', PropTypes.number),
  startAlign: alignProp,
  onFirst: requiredBy('showBookends', PropTypes.func),
  onLast: requiredBy('showBookends', PropTypes.func),
};

export default Pagination;
github airbnb / lunar / packages / core / src / components / Pagination / index.tsx View on Github external
{nextPage}
        {lastPage}
      
    
  );
}

const alignProp = mutuallyExclusiveTrueProps('centerAlign', 'endAlign', 'startAlign');

Pagination.propTypes = {
  centerAlign: alignProp,
  endAlign: alignProp,
  pageCount: requiredBy('showBookends', PropTypes.number),
  startAlign: alignProp,
  onFirst: requiredBy('showBookends', PropTypes.func),
  onLast: requiredBy('showBookends', PropTypes.func),
};

export default Pagination;
github airbnb / lunar / packages / core / src / components / Chip / index.tsx View on Github external
onClick={onIconClick}
              &gt;
                {afterIcon}
              
            ) : (
              afterIcon
            )}
          
        
      )}
    
  );
}

Chip.propTypes = {
  afterIcon: requiredBy('onIconClick', iconComponent),
  beforeIcon: mutuallyExclusiveProps(PropTypes.node, 'beforeIcon', 'profileImageSrc'),
  compact: mutuallyExclusiveProps(PropTypes.any, 'profileImageSrc', 'compact'),
  profileImageSrc: mutuallyExclusiveProps(
    PropTypes.any,
    'beforeIcon',
    'profileImageSrc',
    'compact',
  ),
  onClick: mutuallyExclusiveProps(PropTypes.func, 'onIconClick'),
};

export default Chip;