3
3
4
4
import React from 'react' ;
5
5
import PropTypes from 'prop-types' ;
6
- import { Grid , Stack , Switch , FormControlLabel } from '@mui/material' ;
6
+ import { Grid , Stack , Switch , FormControlLabel , FormHelperText , FormControl } from '@mui/material' ;
7
7
import makeStyles from '@mui/styles/makeStyles' ;
8
8
import { BasicInputPlaceholder } from '../BasicInputPlaceholder' ;
9
9
import { TooltipInfo } from '../../../misc' ;
@@ -13,7 +13,7 @@ const useStyles = makeStyles(getCommonInputStyles);
13
13
14
14
export const BasicToggleInput = ( props ) => {
15
15
const classes = useStyles ( ) ;
16
- const { id, label, tooltipText, value, switchProps, changeSwitchType, isDirty, ...otherProps } = props ;
16
+ const { id, label, tooltipText, value, switchProps, changeSwitchType, isDirty, error , ...otherProps } = props ;
17
17
18
18
if ( switchProps . disabled )
19
19
return (
@@ -28,28 +28,25 @@ export const BasicToggleInput = (props) => {
28
28
29
29
return (
30
30
< Grid item xs = { 3 } >
31
- < Stack
32
- data-cy = { `toggle-input-${ id } ` }
33
- direction = "row"
34
- spacing = { 1 }
35
- alignItems = "center"
36
- className = { isDirty ? classes . dirtyInput : classes . notDirtyInput }
37
- >
38
- < FormControlLabel
39
- value = "value"
40
- control = {
41
- < Switch
42
- color = "secondary"
43
- onChange = { ( event ) => changeSwitchType ( event . target . checked ) }
44
- checked = { value }
45
- { ...switchProps }
46
- />
47
- }
48
- label = { label }
49
- labelPlacement = "end"
50
- />
51
- < TooltipInfo title = { tooltipText } variant = "small" />
52
- </ Stack >
31
+ < FormControl className = { isDirty ? classes . dirtyInput : classes . notDirtyInput } >
32
+ < Stack data-cy = { `toggle-input-${ id } ` } direction = "row" spacing = { 1 } alignItems = "center" >
33
+ < FormControlLabel
34
+ value = "value"
35
+ control = {
36
+ < Switch
37
+ color = "secondary"
38
+ onChange = { ( event ) => changeSwitchType ( event . target . checked ) }
39
+ checked = { value }
40
+ { ...switchProps }
41
+ />
42
+ }
43
+ label = { label }
44
+ labelPlacement = "end"
45
+ />
46
+ < TooltipInfo title = { tooltipText } variant = "small" />
47
+ </ Stack >
48
+ < FormHelperText error = { error ?. message ?. length > 0 } > { error ?. message ?? '' } </ FormHelperText >
49
+ </ FormControl >
53
50
</ Grid >
54
51
) ;
55
52
} ;
@@ -83,6 +80,10 @@ BasicToggleInput.propTypes = {
83
80
* Boolean value that defines whether the input has been modified or not; if true, a special css class is applied.
84
81
*/
85
82
isDirty : PropTypes . bool ,
83
+ /**
84
+ * Error object that contains the type of error and its message
85
+ */
86
+ error : PropTypes . object ,
86
87
} ;
87
88
BasicToggleInput . defaultProps = {
88
89
isDirty : false ,
0 commit comments