11import React , { useState } from "react" ;
2- import { commonCss , Widget } from "../widget" ;
2+ import { Widget } from "../widget" ;
33import {
44 InferWidgetProps ,
55 StringPropOpt ,
@@ -9,6 +9,12 @@ import {
99} from "../propTypes" ;
1010import { PVComponent , PVWidgetPropType } from "../widgetProps" ;
1111import { registerWidget } from "../register" ;
12+ import {
13+ FormControlLabel ,
14+ Checkbox as CheckboxMui ,
15+ ThemeProvider
16+ } from "@mui/material" ;
17+ import { defaultColours } from "../../../colourscheme" ;
1218
1319export const CheckboxProps = {
1420 label : StringPropOpt ,
@@ -31,33 +37,37 @@ export type CheckboxComponentProps = InferWidgetProps<typeof CheckboxProps> &
3137export const CheckboxComponent = (
3238 props : CheckboxComponentProps
3339) : JSX . Element => {
34- const style = {
35- ...commonCss ( props as any ) ,
36- display : "flex" ,
37- alignItems : "center" ,
38- cursor : "pointer"
39- } ;
40-
4140 const [ checked , setChecked ] = useState ( true ) ;
4241
43- const toggle = ( ) : void => {
42+ const handleChange = ( ) : void => {
4443 setChecked ( ! checked ) ;
4544 } ;
46- const inp = (
47- < input
48- style = { { cursor : "inherit" } }
49- id = "cb"
50- type = "checkbox"
51- checked = { checked }
52- readOnly = { true }
53- />
54- ) ;
5545
5646 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 >
6171 ) ;
6272} ;
6373
0 commit comments