diff --git a/src/ui/widgets/Label/__snapshots__/label.test.tsx.snap b/src/ui/widgets/Label/__snapshots__/label.test.tsx.snap
index 0f776d0e..9d92959c 100644
--- a/src/ui/widgets/Label/__snapshots__/label.test.tsx.snap
+++ b/src/ui/widgets/Label/__snapshots__/label.test.tsx.snap
@@ -1,14 +1,31 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+exports[` > it handles transparent prop`] = `
+
+
+ hello
+
+
+`;
+
+exports[` > it handles transparent prop 1`] = `
+
+
+ hello
+
+
+`;
+
exports[` > it matches the snapshot 1`] = `
-
-
- hello
-
-
+ hello
+
`;
diff --git a/src/ui/widgets/Label/label.module.css b/src/ui/widgets/Label/label.module.css
deleted file mode 100644
index 3de03a30..00000000
--- a/src/ui/widgets/Label/label.module.css
+++ /dev/null
@@ -1,15 +0,0 @@
-.Label {
- left: 0%;
- top: 0%;
- height: 100%;
- width: 100%;
- display: flex;
- padding: 0;
- background-color: #ffffff;
- font: 14px helvetica, sans-serif;
- text-align: center;
- justify-content: center;
- align-items: center;
- white-space: pre;
- overflow: hidden;
-}
\ No newline at end of file
diff --git a/src/ui/widgets/Label/label.test.tsx b/src/ui/widgets/Label/label.test.tsx
index 0274e94e..10fae2f0 100644
--- a/src/ui/widgets/Label/label.test.tsx
+++ b/src/ui/widgets/Label/label.test.tsx
@@ -14,15 +14,9 @@ describe("", (): void => {
});
test("it handles transparent prop", (): void => {
- render();
- const label = screen.getByText("hello");
- // The text is in the span, not the parent div.
- if (label.parentElement && "style" in label.parentElement) {
- expect(label.parentElement.style).toHaveProperty(
- "backgroundColor",
- "transparent"
- );
- }
- expect.assertions(1);
+ const { asFragment } = render(
+
+ );
+ expect(asFragment()).toMatchSnapshot();
});
});
diff --git a/src/ui/widgets/Label/label.tsx b/src/ui/widgets/Label/label.tsx
index 64be7186..0cb4966f 100644
--- a/src/ui/widgets/Label/label.tsx
+++ b/src/ui/widgets/Label/label.tsx
@@ -1,7 +1,6 @@
-import React, { CSSProperties } from "react";
+import React from "react";
-import classes from "./label.module.css";
-import { Widget, commonCss } from "../widget";
+import { Widget } from "../widget";
import { WidgetPropType } from "../widgetProps";
import { registerWidget } from "../register";
import {
@@ -15,6 +14,8 @@ import {
FloatPropOpt,
MacrosPropOpt
} from "../propTypes";
+import { Typography as MuiTypography, styled } from "@mui/material";
+import { diamondTheme } from "../../../diamondTheme";
const LabelProps = {
macros: MacrosPropOpt,
@@ -28,7 +29,7 @@ const LabelProps = {
foregroundColor: ColorPropOpt,
backgroundColor: ColorPropOpt,
border: BorderPropOpt,
- rotationAngle: FloatPropOpt,
+ rotationStep: FloatPropOpt,
wrapWords: BoolPropOpt
};
@@ -37,65 +38,66 @@ const LabelWidgetProps = {
...WidgetPropType
};
+const Typography = styled(MuiTypography)({
+ width: "100%",
+ height: "100%",
+ display: "flex",
+ overflow: "hidden",
+ padding: 0
+});
+
export const LabelComponent = (
props: InferWidgetProps
): JSX.Element => {
// Default labels to transparent.
- const editedProps = {
- ...props,
- transparent: props.transparent ?? true
- };
- const style: CSSProperties = commonCss(editedProps);
const {
+ transparent = true,
+ foregroundColor = diamondTheme.palette.primary.contrastText,
textAlign = "left",
textAlignV = "top",
text = "",
- rotationAngle,
- wrapWords
+ rotationStep = 0,
+ wrapWords = true
} = props;
- const className = props.className ?? `Label ${classes.Label}`;
+ const backgroundColor = transparent
+ ? "transparent"
+ : (props.backgroundColor?.toString() ?? diamondTheme.palette.primary.main);
+ const font = props.font?.css() ?? diamondTheme.typography;
+
// Since display is "flex", use "flex-start" and "flex-end" to align
// the content.
let alignment = "center";
if (textAlign === "left") {
alignment = "flex-start";
- if (wrapWords) {
- style["textAlign"] = "left";
- }
} else if (textAlign === "right") {
alignment = "flex-end";
- if (wrapWords) {
- style["textAlign"] = "right";
- }
- } else {
- if (wrapWords) {
- style["textAlign"] = "center";
- }
}
- style["justifyContent"] = alignment;
- style["cursor"] = "default";
+
let alignmentV = "center";
if (textAlignV === "top") {
alignmentV = "flex-start";
} else if (textAlignV === "bottom") {
alignmentV = "flex-end";
}
- style["alignItems"] = alignmentV;
- let transform = undefined;
- if (rotationAngle) {
- transform = `rotate(${rotationAngle}deg)`;
- }
-
- if (wrapWords) {
- style["wordBreak"] = "break-word";
- style["whiteSpace"] = "break-spaces";
- }
// Simple component to display text - defaults to black text and dark grey background
return (
-
- {text}
-
+
+ {text}
+
);
};
diff --git a/src/ui/widgets/Readback/readback.tsx b/src/ui/widgets/Readback/readback.tsx
index 82162193..7b9fa5f4 100644
--- a/src/ui/widgets/Readback/readback.tsx
+++ b/src/ui/widgets/Readback/readback.tsx
@@ -34,7 +34,7 @@ const ReadbackProps = {
foregroundColor: ColorPropOpt,
backgroundColor: ColorPropOpt,
border: BorderPropOpt,
- rotationAngle: FloatPropOpt,
+ rotationStep: FloatPropOpt,
visible: BoolPropOpt,
wrapWords: BoolPropOpt
};
@@ -60,7 +60,7 @@ export const ReadbackComponent = (
textAlignV = "top",
showUnits = false,
precisionFromPv = false,
- rotationAngle,
+ rotationStep,
visible,
wrapWords = false
} = props;
@@ -140,7 +140,7 @@ export const ReadbackComponent = (
foregroundColor={foregroundColor}
backgroundColor={backgroundColor}
border={border}
- rotationAngle={rotationAngle}
+ rotationStep={rotationStep}
visible={visible}
wrapWords={wrapWords}
>
diff --git a/src/ui/widgets/Symbol/__snapshots__/symbol.test.tsx.snap b/src/ui/widgets/Symbol/__snapshots__/symbol.test.tsx.snap
index 27183781..55519cea 100644
--- a/src/ui/widgets/Symbol/__snapshots__/symbol.test.tsx.snap
+++ b/src/ui/widgets/Symbol/__snapshots__/symbol.test.tsx.snap
@@ -82,14 +82,11 @@ exports[` from .opi file > matches snapshot 1`] = `
-
-
- Fake value
-
-
+ Fake value
+