Skip to content

Commit 580f734

Browse files
committed
Moved decision making out of the Button declaration and reorganised styling parameters
1 parent ac618e2 commit 580f734

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

src/ui/widgets/ActionButton/actionButton.tsx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import {
1212
FontPropOpt,
1313
BorderPropOpt,
1414
BoolPropOpt,
15-
FuncPropOpt
15+
FuncPropOpt,
16+
FloatPropOpt
1617
} from "../propTypes";
1718
import { Color } from "../../../types/color";
1819
import { Font } from "../../../types/font";
1920
import { Border } from "../../../types/border";
2021
import { MacroContext } from "../../../types/macros";
2122
import { ExitFileContext, FileContext } from "../../../misc/fileContext";
22-
import { Box, Button, ThemeProvider } from "@mui/material";
23+
import { Button, ThemeProvider } from "@mui/material";
2324

24-
import { defaultColours } from "../../../colourscheme";
25+
import { diamondTheme } from "../../../diamondTheme";
2526

2627
export interface ActionButtonProps {
2728
text: string;
@@ -34,37 +35,48 @@ export interface ActionButtonProps {
3435
font?: Font;
3536
actions?: WidgetActions;
3637
visible?: boolean;
38+
rotationStep?: number;
39+
transparent?: boolean;
3740
}
3841

3942
export const ActionButtonComponent = (
4043
props: ActionButtonProps
4144
): JSX.Element => {
4245
const {
4346
enabled = true,
44-
foregroundColor = defaultColours.palette.primary.contrastText,
45-
backgroundColor = defaultColours.palette.primary.main
47+
foregroundColor = diamondTheme.palette.primary.contrastText,
48+
rotationStep = 0,
49+
transparent = false
4650
} = props;
51+
52+
const backgroundColor = transparent
53+
? "transparent"
54+
: (props.backgroundColor?.toString() ?? diamondTheme.palette.primary.main);
55+
const font = props.font?.css() ?? diamondTheme.typography;
56+
const border = props.border?.css() ?? null;
57+
4758
return (
48-
<ThemeProvider theme={defaultColours}>
59+
<ThemeProvider theme={diamondTheme}>
4960
<Button
5061
variant="contained"
5162
disabled={!enabled}
5263
fullWidth={true}
5364
sx={{
54-
height: "100%",
55-
width: "100%",
56-
minWidth: 0,
57-
minHeight: 0,
58-
padding: 0,
59-
fontFamily: props.font?.css() ?? "",
6065
color: foregroundColor.toString(),
61-
backgroundColor: backgroundColor.toString(),
62-
border: props.border?.css() ?? "",
66+
backgroundColor: backgroundColor,
67+
border: border,
6368
"&.MuiButton-root": {
64-
whiteSpace: "nowrap",
65-
wordBreak: "normal",
69+
display: "block",
70+
alignItems: "center",
71+
justifyContent: "center",
72+
height: "100%",
73+
width: "100%",
74+
minWidth: 0,
75+
minHeight: 0,
76+
padding: 0,
6677
overflow: "hidden",
67-
display: "block"
78+
textOverflow: "ellipsis",
79+
fontFamily: font
6880
},
6981
"&.Mui-disabled": {
7082
cursor: "not-allowed",
@@ -83,7 +95,16 @@ export const ActionButtonComponent = (
8395
<figcaption>{props.text}</figcaption>
8496
</figure>
8597
) : (
86-
(props.text ?? "")
98+
<span
99+
style={{
100+
display: "block",
101+
transform: `rotation(${rotationStep * -90}deg)`.toString(),
102+
whiteSpace: "nowrap",
103+
textOverflow: "ellipsis"
104+
}}
105+
>
106+
{props.text ?? ""}
107+
</span>
87108
)}
88109
</Button>
89110
</ThemeProvider>
@@ -100,7 +121,9 @@ const ActionButtonPropType = {
100121
border: BorderPropOpt,
101122
visible: BoolPropOpt,
102123
enabled: BoolPropOpt,
103-
onClick: FuncPropOpt
124+
onClick: FuncPropOpt,
125+
transparent: BoolPropOpt,
126+
rotationStep: FloatPropOpt
104127
};
105128

106129
const ActionButtonWidgetProps = {
@@ -137,6 +160,8 @@ export const ActionButtonWidget = (
137160
border={props.border}
138161
actions={props.actions as WidgetActions}
139162
visible={props.visible}
163+
transparent={props.transparent}
164+
rotationStep={props.rotationStep}
140165
/>
141166
);
142167
};

0 commit comments

Comments
 (0)