Skip to content

Commit a99f07f

Browse files
committed
Refactored code to be compatible with tests
1 parent 6f74e87 commit a99f07f

File tree

1 file changed

+55
-34
lines changed

1 file changed

+55
-34
lines changed

src/ui/widgets/ActionButton/actionButton.tsx

+55-34
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
ColorPropOpt,
1212
FontPropOpt,
1313
BorderPropOpt,
14-
BoolPropOpt
14+
BoolPropOpt,
15+
FuncPropOpt
1516
} from "../propTypes";
1617
import { Color } from "../../../types/color";
1718
import { Font } from "../../../types/font";
@@ -35,6 +36,45 @@ export interface ActionButtonProps {
3536
visible?: boolean;
3637
}
3738

39+
export const ActionButtonComponent = (
40+
props: ActionButtonProps
41+
): JSX.Element => {
42+
return (
43+
<ThemeProvider theme={defaultColours}>
44+
<Button
45+
variant="contained"
46+
disabled={props.disabled}
47+
sx={{
48+
height: "100%",
49+
width: "100%",
50+
fontFamily: props.font?.css() ?? "",
51+
color:
52+
props.foregroundColor?.toString() ??
53+
defaultColours.palette.primary.contrastText,
54+
backgroundColor:
55+
props.backgroundColor?.toString() ??
56+
defaultColours.palette.primary.main,
57+
border: props.border?.css() ?? ""
58+
}}
59+
onClick={props.onClick}
60+
>
61+
{props.image !== undefined ? (
62+
<figure className={classes.figure}>
63+
<img
64+
style={{ width: "100%", display: "block" }}
65+
src={props.image}
66+
alt={props.image}
67+
></img>
68+
<figcaption>{props.text}</figcaption>
69+
</figure>
70+
) : (
71+
(props.text ?? "")
72+
)}
73+
</Button>
74+
</ThemeProvider>
75+
);
76+
};
77+
3878
const ActionButtonPropType = {
3979
text: StringPropOpt,
4080
actions: ActionsPropType,
@@ -44,7 +84,8 @@ const ActionButtonPropType = {
4484
font: FontPropOpt,
4585
border: BorderPropOpt,
4686
visible: BoolPropOpt,
47-
disabled: BoolPropOpt
87+
disabled: BoolPropOpt,
88+
onClick: FuncPropOpt
4889
};
4990

5091
const ActionButtonWidgetProps = {
@@ -70,38 +111,18 @@ export const ActionButtonWidget = (
70111
);
71112
}
72113
return (
73-
<ThemeProvider theme={defaultColours}>
74-
<Button
75-
variant="contained"
76-
disabled={props.disabled}
77-
sx={{
78-
height: "100%",
79-
width: "100%",
80-
fontFamily: props.font?.css() ?? "",
81-
color:
82-
props.foregroundColor?.toString() ??
83-
defaultColours.palette.primary.contrastText,
84-
backgroundColor:
85-
props.backgroundColor?.toString() ??
86-
defaultColours.palette.primary.main,
87-
border: props.border?.css() ?? ""
88-
}}
89-
onClick={onClick}
90-
>
91-
{props.image !== undefined ? (
92-
<figure className={classes.figure}>
93-
<img
94-
style={{ width: "100%", display: "block" }}
95-
src={props.image}
96-
alt={props.image}
97-
></img>
98-
<figcaption>{props.text}</figcaption>
99-
</figure>
100-
) : (
101-
(props.text ?? "")
102-
)}
103-
</Button>
104-
</ThemeProvider>
114+
<ActionButtonComponent
115+
text={props.text ?? ""}
116+
disabled={props.readonly}
117+
onClick={onClick}
118+
image={props.image}
119+
backgroundColor={props.backgroundColor}
120+
foregroundColor={props.foregroundColor}
121+
font={props.font}
122+
border={props.border}
123+
actions={props.actions as WidgetActions}
124+
visible={props.visible}
125+
/>
105126
);
106127
};
107128

0 commit comments

Comments
 (0)