1
1
import React , { useState } from "react" ;
2
- import { commonCss , Widget } from "../widget" ;
2
+ import { Widget } from "../widget" ;
3
3
import {
4
4
InferWidgetProps ,
5
5
StringPropOpt ,
@@ -9,6 +9,12 @@ import {
9
9
} from "../propTypes" ;
10
10
import { PVComponent , PVWidgetPropType } from "../widgetProps" ;
11
11
import { registerWidget } from "../register" ;
12
+ import {
13
+ FormControlLabel ,
14
+ Checkbox as CheckboxMui ,
15
+ ThemeProvider
16
+ } from "@mui/material" ;
17
+ import { defaultColours } from "../../../colourscheme" ;
12
18
13
19
export const CheckboxProps = {
14
20
label : StringPropOpt ,
@@ -31,33 +37,37 @@ export type CheckboxComponentProps = InferWidgetProps<typeof CheckboxProps> &
31
37
export const CheckboxComponent = (
32
38
props : CheckboxComponentProps
33
39
) : JSX . Element => {
34
- const style = {
35
- ...commonCss ( props as any ) ,
36
- display : "flex" ,
37
- alignItems : "center" ,
38
- cursor : "pointer"
39
- } ;
40
-
41
40
const [ checked , setChecked ] = useState ( true ) ;
42
41
43
- const toggle = ( ) : void => {
42
+ const handleChange = ( ) : void => {
44
43
setChecked ( ! checked ) ;
45
44
} ;
46
- const inp = (
47
- < input
48
- style = { { cursor : "inherit" } }
49
- id = "cb"
50
- type = "checkbox"
51
- checked = { checked }
52
- readOnly = { true }
53
- />
54
- ) ;
55
45
56
46
return (
57
- < form onClick = { toggle } style = { style } >
58
- { inp }
59
- < label style = { { cursor : "inherit" } } > { props . label } </ label >
60
- </ form >
47
+ < ThemeProvider theme = { defaultColours } >
48
+ < FormControlLabel
49
+ sx = { {
50
+ color :
51
+ props . foregroundColor ?. toString ( ) ??
52
+ defaultColours . palette . primary . contrastText ,
53
+ "&:npt($checked) .MuiIconButton-label:after" : {
54
+ color :
55
+ props . foregroundColor ?. toString ( ) ??
56
+ defaultColours . palette . primary . main
57
+ }
58
+ } }
59
+ control = {
60
+ < CheckboxMui
61
+ checked = { checked }
62
+ onChange = { handleChange }
63
+ sx = { {
64
+ color : defaultColours . palette . primary . main
65
+ } }
66
+ />
67
+ }
68
+ label = { props . label }
69
+ />
70
+ </ ThemeProvider >
61
71
) ;
62
72
} ;
63
73
0 commit comments