diff --git a/src/ui/hooks/useStyle.ts b/src/ui/hooks/useStyle.ts index da30e428..08fa953b 100644 --- a/src/ui/hooks/useStyle.ts +++ b/src/ui/hooks/useStyle.ts @@ -24,6 +24,7 @@ export interface UseStyleResult { }; customColors: Record; other: CSSProperties; + styleOpt?: number; } interface UseStyleProps { @@ -35,6 +36,7 @@ interface UseStyleProps { transparent?: boolean; actions?: WidgetActions; customColors?: { [key: string]: Color | undefined }; + styleOpt?: number; } const selectPalette = (theme: Theme, themeName?: string): PaletteColor => { @@ -80,6 +82,8 @@ const backgroundColorSelector = ( ? "transparent" : (backgroundColor?.colorString ?? themePalette?.main); +const styleOptSelector = (styleOpt?: number): number => styleOpt ?? 0; + const fontSelector = (theme: Theme, font?: Font): CSSProperties => fontToCss(font) ?? (theme.typography as CSSProperties); @@ -167,6 +171,8 @@ export const useStyle = ( const cursor = props.actions?.actions.length ? "pointer" : "auto"; + const styleOpt = styleOptSelector(props.styleOpt); + const other: CSSProperties = { cursor, visibility: visible ? "visible" : "hidden" @@ -178,7 +184,8 @@ export const useStyle = ( font, colors: colors, customColors, - other + other, + styleOpt }, newProps ]; diff --git a/src/ui/widgets/GroupBox/__snapshots__/groupBox.test.tsx.snap b/src/ui/widgets/GroupBox/__snapshots__/groupBox.test.tsx.snap index e11d4bab..ab3adc1c 100644 --- a/src/ui/widgets/GroupBox/__snapshots__/groupBox.test.tsx.snap +++ b/src/ui/widgets/GroupBox/__snapshots__/groupBox.test.tsx.snap @@ -6,7 +6,7 @@ exports[` snapshots > it matches the snapshot for Group Box style="width: 100%; height: 100%; position: absolute; padding: 0px 10px 0px 0px; box-sizing: border-box;" >
Test @@ -25,7 +25,7 @@ exports[` snapshots > it matches the snapshot for Line styl style="width: 100%; height: 100%; position: absolute; padding: 0px; box-sizing: border-box;" >
snapshots > it matches the snapshot for Title Bar style="width: 100%; height: 100%; position: absolute; padding: 0px; box-sizing: border-box;" >
Title
@@ -62,7 +62,7 @@ exports[` snapshots > it matches the snapshot for no style style="width: 100%; height: 100%; position: absolute; padding: 0px; box-sizing: border-box;" >
state + } +}); describe(" snapshots", (): void => { test("it matches the snapshot for Group Box style", (): void => { const { asFragment } = render( - + + + ); expect(asFragment()).toMatchSnapshot(); }); test("it matches the snapshot for Title Bar style", (): void => { const { asFragment } = render( - + + + ); expect(asFragment()).toMatchSnapshot(); }); test("it matches the snapshot for Line style", (): void => { const { asFragment } = render( - + + + ); expect(asFragment()).toMatchSnapshot(); }); test("it matches the snapshot for no style", (): void => { const { asFragment } = render( - + + + ); expect(asFragment()).toMatchSnapshot(); }); @@ -36,7 +52,11 @@ describe(" snapshots", (): void => { describe("", (): void => { test("it renders the title", (): void => { - const grouping = ; + const grouping = ( + + + + ); const { getByText } = render(grouping); expect(getByText("Test")).toBeInTheDocument(); }); @@ -44,9 +64,11 @@ describe("", (): void => { test("it renders child div with text", (): void => { const childText = "Testing Child Component"; const groupingWithChild = ( - -
{childText}
-
+ + +
{childText}
+
+
); const { getByText } = render(groupingWithChild); expect(getByText("Test")).toBeInTheDocument(); diff --git a/src/ui/widgets/GroupBox/groupBox.tsx b/src/ui/widgets/GroupBox/groupBox.tsx index e87c44e6..30dfce6e 100644 --- a/src/ui/widgets/GroupBox/groupBox.tsx +++ b/src/ui/widgets/GroupBox/groupBox.tsx @@ -1,7 +1,7 @@ import React, { CSSProperties, useContext } from "react"; import { Widget } from "../widget"; -import { WidgetPropType } from "../widgetProps"; +import { WidgetPropType, ComponentProps } from "../widgetProps"; import { registerWidget } from "../register"; import { ChildrenPropOpt, @@ -14,9 +14,11 @@ import { MacrosPropOpt } from "../propTypes"; import { fontToCss, newFont } from "../../../types/font"; -import { ColorUtils } from "../../../types/color"; import Box from "@mui/material/Box"; import { MacroContext, MacroContextType } from "../../../types/macros"; +import { useStyle } from "../../hooks/useStyle"; + +const widgetName = "groupbox"; const INNER_DIV_STYLE: CSSProperties = { position: "relative", @@ -41,17 +43,22 @@ const GroupBoxProps = { // This could be replaced if we can implement this as part of the // border prop. export const GroupBoxComponent = ( - props: InferWidgetProps + props: InferWidgetProps & ComponentProps ): JSX.Element => { + const [style, newProps] = useStyle( + { ...props, customColors: { lineColor: props.lineColor } }, + widgetName, + props.class + ); const { - backgroundColor = ColorUtils.fromRgba(240, 240, 240), - foregroundColor = ColorUtils.fromRgba(0, 0, 0), - lineColor = ColorUtils.fromRgba(0, 0, 0), font = newFont(14), - styleOpt = 0, + styleOpt = style.styleOpt, transparent = false, - visible = true - } = props; + visible = true, + backgroundColor = style.colors.backgroundColor, + foregroundColor = style.colors.color, + lineColor = style.customColors.lineColor + } = newProps; const outerDivStyle: CSSProperties = { width: "100%", @@ -65,11 +72,11 @@ export const GroupBoxComponent = ( width: "100%", height: "100%", padding: "0px", - border: "1px solid " + lineColor.colorString, + border: "1px solid " + lineColor, whiteSpace: "nowrap", overflow: "visible", - backgroundColor: transparent ? "transparent" : backgroundColor.colorString, - color: foregroundColor.colorString, + backgroundColor: transparent ? "transparent" : backgroundColor, + color: foregroundColor, visibility: visible ? "visible" : "hidden", ...fontToCss(font) }; @@ -105,12 +112,12 @@ export const GroupBoxComponent = ( {styleOpt === 1 ? (
{name} diff --git a/src/ui/widgets/widgetProps.ts b/src/ui/widgets/widgetProps.ts index c28405c0..7b26b6a8 100644 --- a/src/ui/widgets/widgetProps.ts +++ b/src/ui/widgets/widgetProps.ts @@ -70,7 +70,7 @@ type BaseWidgetProps = { baseWidget: React.FC; }; -type ComponentProps = { +export type ComponentProps = { style?: Record; class?: string; };