当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript prop-types.oneOf函数代码示例

本文整理汇总了TypeScript中prop-types.oneOf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript oneOf函数的具体用法?TypeScript oneOf怎么用?TypeScript oneOf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了oneOf函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: validateRequireableTop

AirbnbPropTypes.forbidExtraProps<ForbidShape>({
    foo: PropTypes.string.isRequired,
    bar: PropTypes.number.isRequired,
    baz: PropTypes.bool,
});

// $ExpectType Requireable<number>
AirbnbPropTypes.integer();

const top = (<T>(x?: T): T => x!)();
type Top = typeof top;
declare function validateRequireableTop(x: React.Requireable<Top>): void;

validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.number));
validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.number, 'foo'));
validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.oneOf(['foo', 'bar'])));

// $ExpectType Requireable<number>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number);
// $ExpectType Requireable<number>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number, 'foo');
// $ExpectType Requireable<string>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.string, 'foo', 'bar');

// $ExpectType Requireable<boolean>
AirbnbPropTypes.mutuallyExclusiveTrueProps('foo');
// $ExpectType Requireable<boolean>
AirbnbPropTypes.mutuallyExclusiveTrueProps('foo', 'bar');

// $ExpectType Requireable<ReactNodeLike>
AirbnbPropTypes.nChildren(1, PropTypes.number);
开发者ID:ChaosinaCan,项目名称:DefinitelyTyped,代码行数:31,代码来源:airbnb-prop-types-tests.ts

示例2: styled

const ToolbarContent = styled(Box)<ToolbarContentProps>`
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min-content;
  grid-gap: inherit;
  grid-area: ${prop("align")};
  justify-content: ${prop("align")};
  align-items: center;

  [aria-orientation="vertical"] > & {
    grid-auto-flow: row;
    grid-auto-rows: min-content;
    justify-content: initial;
    align-content: ${prop("align")};
  }

  ${theme("ToolbarContent")};
`;

// @ts-ignore
ToolbarContent.propTypes = {
  align: PropTypes.oneOf(["start", "center", "end"])
};

ToolbarContent.defaultProps = {
  align: "start"
};

export default as("div")(ToolbarContent);
开发者ID:IgorCRD,项目名称:reakit,代码行数:29,代码来源:ToolbarContent.ts

示例3:

 *
 */

'use strict'

import ColorPropType from './ColorPropType'
import * as ReactPropTypes from 'prop-types'
import ViewStylePropTypes from './ViewStylePropTypes'

const TextStylePropTypes = {
  ...ViewStylePropTypes,

  color: ColorPropType,
  fontFamily: ReactPropTypes.string,
  fontSize: ReactPropTypes.number,
  fontStyle: ReactPropTypes.oneOf(['normal', 'italic']),
  /**
   * Specifies font weight. The values 'normal' and 'bold' are supported for
   * most fonts. Not all fonts have a variant for each of the numeric values,
   * in that case the closest one is chosen.
   */
  fontWeight: ReactPropTypes.oneOf([
    'normal' /* default */,
    'bold',
    '100',
    '200',
    '300',
    '400',
    '500',
    '600',
    '700',
开发者ID:YangShaoQun,项目名称:taro,代码行数:31,代码来源:TextStylePropTypes.ts

示例4:

'use strict'

import ColorPropType from './ColorPropType'
import LayoutPropTypes from './LayoutPropTypes'
import * as ReactPropTypes from 'prop-types'
import ShadowPropTypesIOS from './ShadowPropTypesIOS'
import TransformPropTypes from './TransformPropTypes'

/**
 * Warning: Some of these properties may not be supported in all releases.
 */
const ViewStylePropTypes = {
  ...LayoutPropTypes,
  ...ShadowPropTypesIOS,
  ...TransformPropTypes,
  backfaceVisibility: ReactPropTypes.oneOf(['visible', 'hidden']),
  backgroundColor: ColorPropType,
  borderColor: ColorPropType,
  borderTopColor: ColorPropType,
  borderRightColor: ColorPropType,
  borderBottomColor: ColorPropType,
  borderLeftColor: ColorPropType,
  borderStartColor: ColorPropType,
  borderEndColor: ColorPropType,
  borderRadius: ReactPropTypes.number,
  borderTopLeftRadius: ReactPropTypes.number,
  borderTopRightRadius: ReactPropTypes.number,
  borderTopStartRadius: ReactPropTypes.number,
  borderTopEndRadius: ReactPropTypes.number,
  borderBottomLeftRadius: ReactPropTypes.number,
  borderBottomRightRadius: ReactPropTypes.number,
开发者ID:YangShaoQun,项目名称:taro,代码行数:31,代码来源:ViewStylePropTypes.ts

示例5:

 *
 * The implementation in Yoga is slightly different from what the
 * Flexbox spec defines - for example, we chose more sensible default
 * values. Since our layout docs are generated from the comments in this
 * file, please keep a brief comment describing each prop type.
 *
 * These properties are a subset of our styles that are consumed by the layout
 * algorithm and affect the positioning and sizing of views.
 */
const LayoutPropTypes = {
  /** `display` sets the display type of this component.
   *
   *  It works similarly to `display` in CSS, but only support 'flex' and 'none'.
   *  'flex' is the default.
   */
  display: ReactPropTypes.oneOf(['none', 'flex']),

  /** `width` sets the width of this component.
   *
   *  It works similarly to `width` in CSS, but in React Native you
   *  must use points or percentages. Ems and other units are not supported.
   *  See https://developer.mozilla.org/en-US/docs/Web/CSS/width for more details.
   */
  width: ReactPropTypes.oneOfType([
    ReactPropTypes.number,
    ReactPropTypes.string
  ]),

  /** `height` sets the height of this component.
   *
   *  It works similarly to `height` in CSS, but in React Native you
开发者ID:YangShaoQun,项目名称:taro,代码行数:31,代码来源:LayoutPropTypes.ts

示例6:

// $ExpectType ValidationMap<ForbidShape>
AirbnbPropTypes.forbidExtraProps<ForbidShape>({
    foo: PropTypes.string.isRequired,
    bar: PropTypes.number.isRequired,
    baz: PropTypes.bool,
});

// $ExpectType Requireable<number>
AirbnbPropTypes.integer();

// $ExpectType Requireable<{}>
AirbnbPropTypes.keysOf(PropTypes.number);
// $ExpectType Requireable<{}>
AirbnbPropTypes.keysOf(PropTypes.number, 'foo');
// $ExpectType Requireable<{}>
AirbnbPropTypes.keysOf(PropTypes.oneOf(['foo', 'bar']));

// $ExpectType Requireable<number>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number);
// $ExpectType Requireable<number>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number, 'foo');
// $ExpectType Requireable<string>
AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.string, 'foo', 'bar');

// $ExpectType Requireable<boolean>
AirbnbPropTypes.mutuallyExclusiveTrueProps('foo');
// $ExpectType Requireable<boolean>
AirbnbPropTypes.mutuallyExclusiveTrueProps('foo', 'bar');

// $ExpectType Requireable<ReactNodeLike>
AirbnbPropTypes.nChildren(1, PropTypes.number);
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:31,代码来源:airbnb-prop-types-tests.ts

示例7:

// TS checking
const propTypes: PropTypesMap = {
    any: PropTypes.any,
    array: PropTypes.array.isRequired,
    bool: PropTypes.bool.isRequired,
    element: PropTypes.element.isRequired,
    func: PropTypes.func.isRequired,
    node: PropTypes.node,
    requiredNode: PropTypes.node.isRequired,
    number: PropTypes.number.isRequired,
    object: PropTypes.object.isRequired,
    string: PropTypes.string.isRequired,
    symbol: PropTypes.symbol.isRequired,
    instanceOf: PropTypes.instanceOf(TestClass).isRequired,
    oneOf: PropTypes.oneOf<'a' | 'b' | 'c'>(['a', 'b', 'c']).isRequired,
    oneOfType: PropTypes.oneOfType(arrayOfTypes).isRequired,
    numberOrFalse: PropTypes.oneOfType([PropTypes.oneOf<false>([false]), PropTypes.number]).isRequired,
    // The generic function type (() => any) is assignable to ReactNode because ReactNode extends the empty object type {}
    // Which widens the array literal of validators to just Array<Requireable<() => any>>
    // It's too risky to change ReactNode to exclude {} even though it's invalid, as it's required for children-as-function props to work
    // So we assert the explicit tuple type
    nodeOrRenderFn: PropTypes.oneOfType([PropTypes.node, PropTypes.func] as [PropTypes.Requireable<ReactNode>, PropTypes.Requireable<() => any>]),
    arrayOf: PropTypes.arrayOf(PropTypes.bool.isRequired).isRequired,
    objectOf: PropTypes.objectOf(PropTypes.number.isRequired).isRequired,
    shape: PropTypes.shape(innerProps).isRequired,
    optionalNumber: PropTypes.number,
    customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>
};

// JS checking
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:30,代码来源:prop-types-tests.ts

示例8:

 * @format
 */
'use strict'

import ColorPropType from './ColorPropType'
import ImageResizeMode from './ImageResizeMode'
import LayoutPropTypes from './LayoutPropTypes'
import * as ReactPropTypes from 'prop-types'
import ShadowPropTypesIOS from './ShadowPropTypesIOS'
import TransformPropTypes from './TransformPropTypes'

const ImageStylePropTypes = {
  ...LayoutPropTypes,
  ...ShadowPropTypesIOS,
  ...TransformPropTypes,
  resizeMode: ReactPropTypes.oneOf(Object.keys(ImageResizeMode)),
  backfaceVisibility: ReactPropTypes.oneOf(['visible', 'hidden']),
  backgroundColor: ColorPropType,
  borderColor: ColorPropType,
  borderWidth: ReactPropTypes.number,
  borderRadius: ReactPropTypes.number,
  overflow: ReactPropTypes.oneOf(['visible', 'hidden']),

  /**
   * Changes the color of all the non-transparent pixels to the tintColor.
   */
  tintColor: ColorPropType,
  opacity: ReactPropTypes.number,
  /**
   * When the image has rounded corners, specifying an overlayColor will
   * cause the remaining space in the corners to be filled with a solid color.
开发者ID:YangShaoQun,项目名称:taro,代码行数:31,代码来源:ImageStylePropTypes.ts


注:本文中的prop-types.oneOf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。