1- import React , { CSSProperties } from "react" ;
1+ import React from "react" ;
22
3- import classes from "./label.module.css" ;
4- import { Widget , commonCss } from "../widget" ;
3+ import { Widget } from "../widget" ;
54import { WidgetPropType } from "../widgetProps" ;
65import { registerWidget } from "../register" ;
76import {
@@ -43,11 +42,9 @@ export const LabelComponent = (
4342 props : InferWidgetProps < typeof LabelProps >
4443) : JSX . Element => {
4544 // Default labels to transparent.
46- const editedProps = {
47- ...props ,
48- transparent : props . transparent ?? true
49- } ;
50- const style : CSSProperties = commonCss ( editedProps ) ;
45+
46+ const transparent = props . transparent ?? true ;
47+
5148 const {
5249 textAlign = "left" ,
5350 textAlignV = "top" ,
@@ -60,49 +57,45 @@ export const LabelComponent = (
6057 let alignment = "center" ;
6158 if ( textAlign === "left" ) {
6259 alignment = "flex-start" ;
63- if ( wrapWords ) {
64- style [ "textAlign" ] = "left" ;
65- }
6660 } else if ( textAlign === "right" ) {
6761 alignment = "flex-end" ;
68- if ( wrapWords ) {
69- style [ "textAlign" ] = "right" ;
70- }
71- } else {
72- if ( wrapWords ) {
73- style [ "textAlign" ] = "center" ;
74- }
7562 }
76- style [ "justifyContent" ] = alignment ;
77- style [ "cursor" ] = "default" ;
63+
7864 let alignmentV = "center" ;
7965 if ( textAlignV === "top" ) {
8066 alignmentV = "flex-start" ;
8167 } else if ( textAlignV === "bottom" ) {
8268 alignmentV = "flex-end" ;
8369 }
84- style [ "alignItems" ] = alignmentV ;
70+
8571 let transform = undefined ;
8672 if ( rotationAngle ) {
8773 transform = `rotate(${ rotationAngle } deg)` ;
8874 }
8975
90- if ( wrapWords ) {
91- style [ "wordBreak" ] = "break-word" ;
92- style [ "whiteSpace" ] = "break-spaces" ;
93- }
94-
9576 // Simple component to display text - defaults to black text and dark grey background
9677 return (
9778 < ThemeProvider theme = { defaultColours } >
9879 < Typography
80+ noWrap = { ! wrapWords }
9981 sx = { {
82+ width : "100%" ,
83+ height : "100%" ,
84+ display : "flex" ,
85+ justifyContent : alignment ,
86+ alignItems : alignmentV ,
87+ textAlign : textAlign ,
88+ wordBreak : wrapWords ? "break-word" : null ,
89+ whiteSpace : wrapWords ? "break-spaces" : null ,
10090 color :
10191 props . foregroundColor ?. toString ( ) ??
10292 defaultColours . palette . primary . contrastText ,
93+ backgroundColor : transparent
94+ ? null
95+ : ( props . backgroundColor ?. toString ( ) ??
96+ defaultColours . palette . primary . main ) ,
10397 fontFamily : props . font ?. css ( ) ?? null ,
104- transform : transform ?. toString ( ) ?? null ,
105- border : "2px"
98+ transform : transform ?. toString ( ) ?? null
10699 } }
107100 >
108101 { text }
0 commit comments