All files / input types.js

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159                                                                                                                                                                                                                                                                                                                             
/*
Copyright (c) 2018-2019 Uber Technologies, Inc.
 
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import type {OverrideT} from '../helpers/overrides.js';
import {
  STATE_CHANGE_TYPE,
  ADJOINED,
  SIZE,
  ENHANCER_POSITION,
} from './constants.js';
 
export type AdjoinedT = $Keys<typeof ADJOINED>;
 
export type SizeT = $Keys<typeof SIZE>;
 
export type StateTypeT = $Keys<typeof STATE_CHANGE_TYPE>;
 
export type InternalStateT = {
  /** Renders UI in 'focus' state */
  isFocused?: boolean,
};
 
export type StateT = {
  value?: string,
};
 
export type StateReducerT = (
  stateType: StateTypeT,
  nextState: StateT,
  currentState: StateT,
) => StateT;
 
export type SharedPropsT = {
  /** Renders UI in 'focus' state */
  $isFocused: boolean,
  /** Renders UI in 'disabled' state */
  $disabled: boolean,
  /** Renders UI in 'error' state */
  $error: boolean,
  /** Renders UI in 'positive' state */
  $positive: boolean,
  /** Defines styles for inputs that are grouped with other controls. */
  $adjoined: AdjoinedT,
  /** Renders UI in provided size. */
  $size: SizeT,
  /** Renders UI in 'required' state */
  $required: boolean,
  $position: $Keys<typeof ENHANCER_POSITION>,
};
 
export type PropsT = *;
 
export type BaseInputComponentsT = {
  InputContainer?: OverrideT<*>,
  Input?: OverrideT<*>,
  Before?: OverrideT<*>,
  After?: OverrideT<*>,
};
 
export type InputComponentsT = {
  ...BaseInputComponentsT,
  Root?: OverrideT<*>,
  StartEnhancer?: OverrideT<*>,
  EndEnhancer?: OverrideT<*>,
};
 
export type BaseInputPropsT<T> = {
  /** Sets aria-label attribute. */
  'aria-label': ?string,
  /** Sets aria-labelledby attribute. */
  'aria-labelledby': ?string,
  /** Sets aria-describedby attribute. */
  'aria-describedby': ?string,
  /** Defines styles for inputs that are grouped with other controls. */
  adjoined: AdjoinedT,
  /** Determines if browser should provide value suggestions. */
  autoComplete: string,
  /** If true the input will be focused on the first mount. */
  autoFocus: boolean,
  /** Renders component in 'disabled' state. */
  disabled: boolean,
  /** Renders component in 'error' state. */
  error: boolean,
  /** Renders component in 'positive' state. */
  positive?: boolean,
  /** Id attribute value to be added to the input element and as a label's for attribute value. */
  id: string,
  'data-baseweb'?: string,
  /** A ref to access an input element. */
  inputRef: {current: HTMLInputElement | null},
  name: string,
  onBlur: (e: SyntheticFocusEvent<T>) => mixed,
  onChange?: (e: SyntheticInputEvent<T>) => mixed,
  onKeyDown?: (e: SyntheticKeyboardEvent<T>) => mixed,
  onKeyPress?: (e: SyntheticKeyboardEvent<T>) => mixed,
  onKeyUp?: (e: SyntheticKeyboardEvent<T>) => mixed,
  onFocus: (e: SyntheticFocusEvent<T>) => mixed,
  overrides: BaseInputComponentsT,
  placeholder: string,
  /** Renders component in 'required' state. */
  required: boolean,
  /** Renders component in provided size. */
  size: SizeT,
  /** Input type attribute. */
  type: string,
  /** Input value attribute. */
  value?: string,
  rows?: number,
};
 
export type InputPropsT = {
  ...BaseInputPropsT<HTMLInputElement>,
  overrides: InputComponentsT,
  /** An input helper rendered before and attached to the input field. */
  startEnhancer: ?(React.Node | ((props: PropsT) => React.Node)),
  /** An input helper rendered after and attached to the input field. */
  endEnhancer: ?(React.Node | ((props: PropsT) => React.Node)),
  /** Handler for the `focus` event. */
  onFocus: (e: SyntheticFocusEvent<HTMLInputElement>) => mixed,
  /** Handler for the `blur` event. */
  onBlur: (e: SyntheticFocusEvent<HTMLInputElement>) => mixed,
};
 
export type MaskedInputPropsT = {
  /** See pattern examples here: https://github.com/sanniassin/react-input-mask */
  mask?: string,
  /** Character to render for unfilled mask element. */
  maskChar?: string,
  ...InputPropsT,
};
 
export type StatefulContainerPropsT<T> = {
  children: (props: PropsT) => React.Node,
  /** Initial state of an uncontrolled input component. */
  initialState?: StateT,
  /** A state change handler. Used to override default state transitions. */
  stateReducer: StateReducerT,
  onChange: (e: SyntheticInputEvent<T>) => mixed,
};
 
type OmitPropsT = {
  overrides: InputComponentsT,
  children: ?(props: *) => React.Node,
};
 
type FullStPropsT = InputPropsT & StatefulContainerPropsT<HTMLInputElement>;
 
type StInputPropsDiffT = $Diff<FullStPropsT, OmitPropsT>;
 
export type StatefulInputPropsT = {
  ...StInputPropsDiffT,
  overrides?: InputComponentsT,
};