當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript PropTypes.oneOfType方法代碼示例

本文整理匯總了TypeScript中react.PropTypes.oneOfType方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript PropTypes.oneOfType方法的具體用法?TypeScript PropTypes.oneOfType怎麽用?TypeScript PropTypes.oneOfType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在react.PropTypes的用法示例。


在下文中一共展示了PropTypes.oneOfType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: require

import * as React from 'react'

import {PureRender} from "./pure-render"
const omitBy = require('lodash/omitBy')
const isUndefined = require('lodash/isUndefined')
const defaults = require('lodash/defaults')

export type RenderFunction = (props?:any, children?:any) => Element
export type Element = React.ReactElement<any>
export type RenderComponentType<P> = React.ComponentClass<P> | React.ClassicComponentClass<P> | Element | RenderFunction;

export const RenderComponentPropType = React.PropTypes.oneOfType([
  function(props:any, propName: string, componentName: string) {
    return isUndefined(props[propName]) || (props[propName]["prototype"] instanceof React.Component)
  },
  React.PropTypes.element,
  React.PropTypes.func,
])

export function renderComponent(component:RenderComponentType<any>, props={}, children=null){
  let isReactComponent = (
    component["prototype"] instanceof React.Component ||
    (component["prototype"] && component["prototype"].isReactComponent) ||
    typeof component === 'function'
  )
  if (isReactComponent){
    return React.createElement(
      component as React.ComponentClass<any>,
      props, children
    )
  } else if (React.isValidElement(component)){
開發者ID:Nostres,項目名稱:searchkit-redux,代碼行數:31,代碼來源:RenderComponent.ts

示例2:

import { PropTypes } from 'react';
import { ViewProperties, View } from 'react-native';

export interface LayoutParams {
    width?: number | "match_parent" | "wrap_parent";
    height?: number | "match_parent" | "wrap_content";
}

export const LayoutParams = { 
    width: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.oneOf(["match_parent", "wrap_content"])
    ]),
    height: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.oneOf(["match_parent", "wrap_content"])
    ])
}

export interface ViewGroupProperties extends ViewProperties {
    layoutParams?: LayoutParams;
    fitsSystemWindows?: boolean;
}



export const ViewGroupProperties = Object.assign({}, View.propTypes, {
    layoutParams: PropTypes.shape(LayoutParams as any),
    fitsSystemWindows: PropTypes.bool
});
開發者ID:lihongjiang,項目名稱:mao-rn-android-kit,代碼行數:30,代碼來源:types.ts

示例3: defaults

  orderDirection?: string
  include?: Array<string> | string
  exclude?: Array<string> | string
  showCount?: boolean
  showMore?:boolean
}

export const FacetFilterPropTypes = defaults({
  field: React.PropTypes.string.isRequired,
  operator: React.PropTypes.oneOf(["AND", "OR"]),
  size: React.PropTypes.number,
  title: React.PropTypes.string.isRequired,
  id: React.PropTypes.string.isRequired,
  containerComponent:RenderComponentPropType,
  listComponent:RenderComponentPropType,
  itemComponent:RenderComponentPropType,
  translations: SearchkitComponent.translationsPropType(
    FacetAccessor.translations
  ),
  orderKey: React.PropTypes.string,
  orderDirection: React.PropTypes.oneOf(["asc", "desc"]),
  include: React.PropTypes.oneOfType([
      React.PropTypes.string, React.PropTypes.array
  ]),
  exclude: React.PropTypes.oneOfType([
      React.PropTypes.string, React.PropTypes.array
  ]),
  showCount: React.PropTypes.bool,
  showMore: React.PropTypes.bool
},SearchkitComponent.propTypes)
開發者ID:BenJamesbabala,項目名稱:searchkit,代碼行數:30,代碼來源:FacetFilterProps.ts

示例4:

  maxXValue: React.PropTypes.number.isRequired,
  yValue: React.PropTypes.number.isRequired
});

export const bucketDatum = React.PropTypes.shape({
  minXValue: React.PropTypes.number.isRequired,
  maxXValue: React.PropTypes.number.isRequired,
  minYValue: React.PropTypes.number.isRequired,
  maxYValue: React.PropTypes.number.isRequired,
  firstYValue: React.PropTypes.number.isRequired,
  lastYValue: React.PropTypes.number.isRequired
});

export const ticks = React.PropTypes.oneOfType([
  React.PropTypes.func,
  React.PropTypes.number,
  React.PropTypes.arrayOf(React.PropTypes.number)
]);

export const tickFormat = React.PropTypes.oneOfType([
  React.PropTypes.func,
  React.PropTypes.string
]);

export const axisSpecPartial = {
  scale: React.PropTypes.func,
  ticks: ticks,
  tickFormat: tickFormat,
  color: React.PropTypes.string
};
開發者ID:abe732,項目名稱:react-layered-chart,代碼行數:30,代碼來源:propTypes.ts


注:本文中的react.PropTypes.oneOfType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。