1
- import React , { useContext } from 'react' ;
1
+ import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { FormAutocomplete } from './FormAutocomplete' ;
4
4
import { FormCheckbox } from './FormCheckbox' ;
@@ -8,25 +8,28 @@ import { FormRadio } from './FormRadio';
8
8
import { FormSelect } from './FormSelect' ;
9
9
import { FormSwitch } from './FormSwitch' ;
10
10
import { FormTextarea } from './FormTextarea' ;
11
- import { FormContext } from './form-helpers' ;
12
-
13
- function FormGroup ( { children, name, ...props } ) {
14
- const formState = useContext ( FormContext ) ;
15
- const validationMessage = formState . getValidationMessage ( name ) ;
11
+ import { FormValidationFeedback } from './FormValidationFeedback' ;
16
12
13
+ function FormGroup ( { children, name, feedback, mockInvalidSibling, ...props } ) {
17
14
return (
18
15
< div className = "form-group" >
19
16
< FormLabel { ...props } />
20
17
{ children }
21
- < div className = "valid-feedback" > </ div >
22
- < div className = "invalid-feedback" > { validationMessage } </ div >
18
+ { feedback && < FormValidationFeedback mockInvalidSibling = { mockInvalidSibling } name = { name } /> }
23
19
</ div >
24
20
) ;
25
21
}
26
22
23
+ FormGroup . defaultProps = {
24
+ feedback : true ,
25
+ mockInvalidSibling : false ,
26
+ } ;
27
+
27
28
FormGroup . propTypes = {
28
- name : PropTypes . string . isRequired ,
29
29
children : PropTypes . element ,
30
+ feedback : PropTypes . bool ,
31
+ mockInvalidSibling : PropTypes . bool ,
32
+ name : PropTypes . string . isRequired ,
30
33
} ;
31
34
32
35
export function FormGroupAutocomplete ( props ) {
@@ -39,7 +42,7 @@ export function FormGroupAutocomplete(props) {
39
42
40
43
export function FormGroupCheckbox ( props ) {
41
44
return (
42
- < FormGroup { ...props } >
45
+ < FormGroup mockInvalidSibling = { true } { ...props } >
43
46
< FormCheckbox { ...props } />
44
47
</ FormGroup >
45
48
) ;
@@ -55,7 +58,7 @@ export function FormGroupInput(props) {
55
58
56
59
export function FormGroupRadio ( { options, id, ...props } ) {
57
60
return (
58
- < FormGroup { ...props } >
61
+ < FormGroup mockInvalidSibling = { true } { ...props } >
59
62
< div >
60
63
{ options . map ( ( option , index ) => (
61
64
< FormRadio
@@ -91,7 +94,7 @@ export function FormGroupSelect(props) {
91
94
92
95
export function FormGroupSwitch ( props ) {
93
96
return (
94
- < FormGroup { ...props } >
97
+ < FormGroup mockInvalidSibling = { true } { ...props } >
95
98
< FormSwitch { ...props } />
96
99
</ FormGroup >
97
100
) ;
0 commit comments