@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import React from 'react' ;
17+ import React , { InputHTMLAttributes , SelectHTMLAttributes , TextareaHTMLAttributes } from 'react' ;
1818import classNames from 'classnames' ;
1919import * as sdk from '../../../index' ;
2020import { debounce } from 'lodash' ;
@@ -29,53 +29,69 @@ function getId() {
2929 return `${ BASE_ID } _${ count ++ } ` ;
3030}
3131
32- interface IProps extends React . InputHTMLAttributes < HTMLSelectElement | HTMLInputElement | HTMLTextAreaElement > {
32+ interface IProps {
3333 // The field's ID, which binds the input and label together. Immutable.
34- id ?: string ,
35- // The element to create. Defaults to "input".
36- // To define options for a select, use <Field><option ... /></Field>
37- element ?: "input" | "select" | "textarea" ,
34+ id ?: string ;
3835 // The field's type (when used as an <input>). Defaults to "text".
39- type ?: string ,
36+ type ?: string ;
4037 // id of a <datalist> element for suggestions
41- list ?: string ,
38+ list ?: string ;
4239 // The field's label string.
43- label ?: string ,
40+ label ?: string ;
4441 // The field's placeholder string. Defaults to the label.
45- placeholder ?: string ,
46- // The field's value.
47- // This is a controlled component, so the value is required.
48- value : string ,
42+ placeholder ?: string ;
4943 // Optional component to include inside the field before the input.
50- prefixComponent ?: React . ReactNode ,
44+ prefixComponent ?: React . ReactNode ;
5145 // Optional component to include inside the field after the input.
52- postfixComponent ?: React . ReactNode ,
46+ postfixComponent ?: React . ReactNode ;
5347 // The callback called whenever the contents of the field
5448 // changes. Returns an object with `valid` boolean field
5549 // and a `feedback` react component field to provide feedback
5650 // to the user.
57- onValidate ?: ( input : IFieldState ) => Promise < IValidationResult > ,
51+ onValidate ?: ( input : IFieldState ) => Promise < IValidationResult > ;
5852 // If specified, overrides the value returned by onValidate.
59- flagInvalid ?: boolean ,
53+ flagInvalid ?: boolean ;
6054 // If specified, contents will appear as a tooltip on the element and
6155 // validation feedback tooltips will be suppressed.
62- tooltipContent ?: React . ReactNode ,
56+ tooltipContent ?: React . ReactNode ;
6357 // If specified alongside tooltipContent, the class name to apply to the
6458 // tooltip itself.
65- tooltipClassName ?: string ,
59+ tooltipClassName ?: string ;
6660 // If specified, an additional class name to apply to the field container
67- className ?: string ,
61+ className ?: string ;
6862 // All other props pass through to the <input>.
6963}
7064
65+ interface IInputProps extends IProps , InputHTMLAttributes < HTMLInputElement > {
66+ // The element to create. Defaults to "input".
67+ element ?: "input" ;
68+ // The input's value. This is a controlled component, so the value is required.
69+ value : string ;
70+ }
71+
72+ interface ISelectProps extends IProps , SelectHTMLAttributes < HTMLSelectElement > {
73+ // To define options for a select, use <Field><option ... /></Field>
74+ element : "select" ;
75+ // The select's value. This is a controlled component, so the value is required.
76+ value : string ;
77+ }
78+
79+ interface ITextareaProps extends IProps , TextareaHTMLAttributes < HTMLTextAreaElement > {
80+ element : "textarea" ;
81+ // The textarea's value. This is a controlled component, so the value is required.
82+ value : string ;
83+ }
84+
85+ type PropShapes = IInputProps | ISelectProps | ITextareaProps ;
86+
7187interface IState {
7288 valid : boolean ,
7389 feedback : React . ReactNode ,
7490 feedbackVisible : boolean ,
7591 focused : boolean ,
7692}
7793
78- export default class Field extends React . PureComponent < IProps , IState > {
94+ export default class Field extends React . PureComponent < PropShapes , IState > {
7995 private id : string ;
8096 private input : HTMLInputElement ;
8197
0 commit comments