How to use the oneOf function from prop-types

Find comprehensive JavaScript prop-types.oneOf code examples handpicked from public code repositorys.

91
92
93
94
95
96
97
98
99
100
// JS's instanceof operator.
optionalMessage: PropTypes.instanceOf(Message),

// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: PropTypes.oneOf(['News', 'Photos']),

// An object that could be one of many types
optionalUnion: PropTypes.oneOfType([
  PropTypes.string,
fork icon388
star icon0
watch icon59

9
10
11
12
13
14
15
16
17
18
  host: PropTypes.string.isRequired,
  secret: PropTypes.string.isRequired,
  scope: PropTypes.arrayOf(PropTypes.string).isRequired,
  afterAuth: PropTypes.func.isRequired,
  shopStore: PropTypes.object,
  accessMode: PropTypes.oneOf(['offline', 'online'])
};

const defaults = {
  shopStore: new MemoryStrategy(),
fork icon87
star icon0
watch icon1

86
87
88
89
90
91
92
93
94
95
uri: PropTypes.string,
/*
 * The HTTP Method to use. Defaults to GET if not specified.
 * NOTE: On Android, only GET and POST are supported.
 */
method: PropTypes.oneOf(['GET', 'POST']),
/*
 * Additional HTTP headers to send with the request.
 * NOTE: On Android, this can only be used with GET requests.
 */
fork icon87
star icon0
watch icon76

+ 3 other calls in file

43
44
45
46
47
48
49
50
51
const formType = PropTypes.shape({
  title: stringType,
  formItems: PropTypes.arrayOf(PropTypes.shape({
    label: stringType,
    mdTitle: PropTypes.string,
    type: PropTypes.oneOf(['textarea', 'version', 'code', 'input']).isRequired,
    required: PropTypes.bool
  }))
})
fork icon0
star icon4
watch icon2

15
16
17
18
19
20
21
22
23
24
uri: PropTypes.string,
bundle: PropTypes.string,
method: PropTypes.string,
headers: PropTypes.objectOf(PropTypes.string),
body: PropTypes.string,
cache: PropTypes.oneOf([
  'default',
  'reload',
  'force-cache',
  'only-if-cached',
fork icon5
star icon3
watch icon0

684
685
686
687
688
689
690
691
692
693
if (process.env.NODE_ENV !== 'production') {
  FolderViewer.propTypes = {
    path: PropTypes.string.isRequired,
    details: PropTypes.objectOf(PropTypes.shape({
      path: PropTypes.string.isRequired,
      type: PropTypes.oneOf(['directory', 'file']).isRequired,
      contentType: PropTypes.string,
      // file only
      integrity: PropTypes.string,
      // file only
fork icon0
star icon1
watch icon0

241
242
243
244
245
246
247
248
249
250
251
};


var PROP_TYPES = process.env.NODE_ENV !== 'production' ? {
    value: PropTypes.string.isRequired,
    size: PropTypes.number,
    level: PropTypes.oneOf(['L', 'M', 'Q', 'H']),
    bgColor: PropTypes.string,
    fgColor: PropTypes.string,
    includeMargin: PropTypes.bool,
    imageSettings: PropTypes.shape({
fork icon0
star icon0
watch icon1

+ 8 other calls in file

2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
CardImgOverlay.defaultProps = defaultProps$K;


/**
 * CarouselContext
 * {
 *  direction: PropTypes.oneOf(['start', 'end']).isRequired,
 * }
 */


var CarouselContext = React__default["default"].createContext({});
fork icon0
star icon0
watch icon1

33
34
35
36
37
38
39
40
41
42
},
scrollOnMountCalled: false,
tabWillChangeWithoutGesture: false,

propTypes: {
  tabBarPosition: PropTypes.oneOf([
    "top",
    "bottom",
    "overlayTop",
    "overlayBottom",
fork icon0
star icon0
watch icon1

+ 16 other calls in file

185
186
187
188
189
190
191
192
193
194
commentText: PropTypes.string.isRequired,
commentee: PropTypes.string,
intl: intlShape.isRequired,
objectId: PropTypes.number.isRequired,
objectTitle: PropTypes.string,
objectType: PropTypes.oneOf([0, 1, 2]).isRequired,
user: PropTypes.shape({
    id: PropTypes.number,
    banned: PropTypes.bool,
    username: PropTypes.string,
fork icon0
star icon0
watch icon1

+ 3 other calls in file

31
32
33
34
35
36
37
38
39
40
},
scrollOnMountCalled: false,
tabWillChangeWithoutGesture: false,

propTypes: {
  tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]),
  initialPage: PropTypes.number,
  page: PropTypes.number,
  onChangeTab: PropTypes.func,
  onScroll: PropTypes.func,
fork icon0
star icon0
watch icon1

253
254
255
256
257
258
259
260
261
262
263


TextBlock.propTypes = {
  width: PropTypes.number,
  fontFamily: PropTypes.string,
  vAlign: PropTypes.oneOf(["top", "middle", "bottom"]),
  textAlign: PropTypes.oneOf(["left", "center", "justify", "right"]),
  underline: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  bold: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  italic: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
  lineHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
fork icon0
star icon0
watch icon4

3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
  children: PropTypes.node,
  circle: PropTypes.bool,
  className: PropTypes.string,
  color: PropTypes.string,
  tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  size: PropTypes.oneOf(['lg', 'sm'])
};
Pagination.defaultProps = {
  circle: false,
  className: "",
fork icon0
star icon0
watch icon1

+ 9 other calls in file

517
518
519
520
521
522
523
524
525
526
 * - `'all'`
 *
 * @platform ios
 */
dataDetectorTypes: (PropTypes.oneOfType([
  PropTypes.oneOf(DataDetectorTypes),
  PropTypes.arrayOf(PropTypes.oneOf(DataDetectorTypes)),
]): React$PropType$Primitive<
  | 'phoneNumber'
  | 'link'
fork icon0
star icon0
watch icon1

3
4
5
6
7
8
9
10
11
12
13
14


class ButtonSizeOption extends React.Component {
  static get propTypes() {
    return {
      onChange: PropTypes.func.isRequired,
      buttonLarge: PropTypes.oneOf([undefined, 'on']),
    };
  }


  render() {
fork icon0
star icon0
watch icon1

+ 7 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14


class HideConversationOption extends React.Component {
  static get propTypes() {
    return {
      onChange: PropTypes.func.isRequired,
      hideConversation: PropTypes.oneOf([undefined, 'on']),
    };
  }


  render() {
fork icon0
star icon0
watch icon1

+ 7 other calls in file

25
26
27
28
29
30
31
32
33
34
35
});
const CustomizationOptionUrlPropTypes = Object.assign(baseUrlProps, {
  buttonHideUsername: PropTypes.oneOf([undefined, 'on']),
  buttonRecommendation: PropTypes.array,
  buttonType: ButtonType,
  theme: PropTypes.oneOf(['dark', 'light']),
});


const baseQueryParamConfig = {};
CUSTOMIZATION_OPTION_KEYS.forEach(key => {
fork icon0
star icon0
watch icon1

+ 15 other calls in file

31
32
33
34
35
36
37
38
39
40
video_number: PropTypes.number.isRequired,
date: PropTypes.instanceOf(Date).isRequired,
video_id: PropTypes.string,
live_example: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.oneOf([false]),
]),
can_contribute: PropTypes.bool,
topics: PropTypes.arrayOf(PropTypes.shape(link)),
links: PropTypes.arrayOf(PropTypes.shape(link)),
fork icon0
star icon0
watch icon2

+ 5 other calls in file