@@ -23,29 +23,47 @@ import { ExitFileContext, FileContext } from "../../../misc/fileContext";
2323import { styled , Button as MuiButton } from "@mui/material" ;
2424
2525import { diamondTheme } from "../../../diamondTheme" ;
26+ import { WIDGET_DEFAULT_SIZES } from "../EmbeddedDisplay/bobParser" ;
2627
2728export interface ActionButtonProps {
28- text : string ;
29+ // text: string;
2930 enabled ?: boolean ;
3031 onClick : ( event : React . MouseEvent < HTMLButtonElement > ) => void ;
31- image ?: string ;
32- backgroundColor ?: Color ;
33- foregroundColor ?: Color ;
34- border ?: Border ;
35- font ?: Font ;
36- actions ?: WidgetActions ;
37- visible ?: boolean ;
38- rotationStep ?: number ;
39- transparent ?: boolean ;
32+ // image?: string;
33+ // backgroundColor?: Color;
34+ // foregroundColor?: Color;
35+ // border?: Border;
36+ // font?: Font;
37+ // actions?: WidgetActions;
38+ // visible?: boolean;
39+ // rotationStep?: number;
40+ // transparent?: boolean;
41+ // width?: number;
42+ // height?: number;
4043}
4144
45+ const ActionButtonPropType = {
46+ text : StringPropOpt ,
47+ actions : ActionsPropType ,
48+ image : StringPropOpt ,
49+ backgroundColor : ColorPropOpt ,
50+ foregroundColor : ColorPropOpt ,
51+ font : FontPropOpt ,
52+ border : BorderPropOpt ,
53+ visible : BoolPropOpt ,
54+ enabled : BoolPropOpt ,
55+ onClick : FuncPropOpt ,
56+ transparent : BoolPropOpt ,
57+ rotationStep : FloatPropOpt ,
58+ height : FloatPropOpt ,
59+ width : FloatPropOpt
60+ } ;
61+
4262const Button = styled ( MuiButton ) ( {
4363 "&.MuiButton-root" : {
4464 display : "block" ,
4565 alignItems : "center" ,
4666 justifyContent : "center" ,
47- height : "100%" ,
48- width : "100%" ,
4967 minWidth : 0 ,
5068 minHeight : 0 ,
5169 padding : 0 ,
@@ -61,13 +79,15 @@ const Button = styled(MuiButton)({
6179} ) ;
6280
6381export const ActionButtonComponent = (
64- props : ActionButtonProps
82+ props : InferWidgetProps < typeof ActionButtonPropType > & ActionButtonProps
6583) : JSX . Element => {
6684 const {
6785 enabled = true ,
6886 foregroundColor = diamondTheme . palette . primary . contrastText ,
6987 rotationStep = 0 ,
70- transparent = false
88+ transparent = false ,
89+ height = WIDGET_DEFAULT_SIZES [ "action_button" ] [ 1 ] ,
90+ width = WIDGET_DEFAULT_SIZES [ "action_button" ] [ 0 ]
7191 } = props ;
7292
7393 const backgroundColor = transparent
@@ -76,16 +96,39 @@ export const ActionButtonComponent = (
7696 const font = props . font ?. css ( ) ?? diamondTheme . typography ;
7797 const border = props . border ?. css ( ) ?? null ;
7898
99+ const inputWidth = rotationStep === 0 || rotationStep === 2 ? width : height ;
100+ const inputHeight = rotationStep === 0 || rotationStep === 2 ? height : width ;
101+
102+ const offset = width / 2 - height / 2 ;
103+ const transform = ( function ( ) {
104+ switch ( rotationStep ) {
105+ case 0 : // 0 degrees
106+ case 2 : // 180 degrees
107+ return `rotate(${ rotationStep * - 90 } deg)` ;
108+ case 1 : // 90 degrees
109+ return `rotate(${ rotationStep * - 90 } deg) translateY(${ offset } px) translateX(${ offset } px)` ;
110+ case 3 : // -90 degrees
111+ return `rotate(${ rotationStep * - 90 } deg) translateY(${ - offset } px) translateX(${ - offset } px)` ;
112+ default : // Unreachable
113+ return "" ;
114+ }
115+ } ) ( ) ;
116+
79117 return (
80118 < Button
81119 variant = { transparent ? "text" : "contained" }
82120 disabled = { ! enabled }
83121 fullWidth = { true }
84122 sx = { {
123+ "&.MuiButton-root" : {
124+ height : inputHeight ,
125+ width : inputWidth
126+ } ,
85127 color : foregroundColor . toString ( ) ,
86128 backgroundColor : backgroundColor ,
87129 border : border ,
88- fontFamily : font
130+ fontFamily : font ,
131+ transform : transform . toString ( )
89132 } }
90133 onClick = { props . onClick }
91134 >
@@ -102,8 +145,7 @@ export const ActionButtonComponent = (
102145 < span
103146 style = { {
104147 display : "block" ,
105- lineHeight : 1 ,
106- transform : `rotate(${ rotationStep * - 90 } deg)`
148+ lineHeight : 1
107149 } }
108150 >
109151 { props . text ?? "" }
@@ -113,21 +155,6 @@ export const ActionButtonComponent = (
113155 ) ;
114156} ;
115157
116- const ActionButtonPropType = {
117- text : StringPropOpt ,
118- actions : ActionsPropType ,
119- image : StringPropOpt ,
120- backgroundColor : ColorPropOpt ,
121- foregroundColor : ColorPropOpt ,
122- font : FontPropOpt ,
123- border : BorderPropOpt ,
124- visible : BoolPropOpt ,
125- enabled : BoolPropOpt ,
126- onClick : FuncPropOpt ,
127- transparent : BoolPropOpt ,
128- rotationStep : FloatPropOpt
129- } ;
130-
131158const ActionButtonWidgetProps = {
132159 ...ActionButtonPropType ,
133160 ...PVWidgetPropType
@@ -164,6 +191,8 @@ export const ActionButtonWidget = (
164191 visible = { props . visible }
165192 transparent = { props . transparent }
166193 rotationStep = { props . rotationStep }
194+ height = { props . height }
195+ width = { props . width }
167196 />
168197 ) ;
169198} ;
0 commit comments