diff --git a/front/components/GtkUI/Element.tsx b/front/components/GtkUI/Element.tsx index 4c569e1..3201e68 100644 --- a/front/components/GtkUI/Element.tsx +++ b/front/components/GtkUI/Element.tsx @@ -4,12 +4,27 @@ import { RawElement } from "./RawElement"; import { Pressable } from "native-base"; export const Element = (props: ElementProps) => { - if (props.type === "text" && props.data?.onPress) { + let actionFunction = null as null | Function; + + switch (props.type) { + case "text": + actionFunction = props.data?.onPress; + break; + case "toggle": + actionFunction = props.data?.onToggle; + break; + default: + break; + } + + if (actionFunction) { return ( - - + + {({ isHovered }) => { + return ; + }} ); } - return ; + return ; }; diff --git a/front/components/GtkUI/ElementTypes.tsx b/front/components/GtkUI/ElementTypes.tsx index 9ee72b9..fb25abe 100644 --- a/front/components/GtkUI/ElementTypes.tsx +++ b/front/components/GtkUI/ElementTypes.tsx @@ -1,8 +1,4 @@ -import { - Select, - Switch, - Text, -} from "native-base"; +import { Select, Switch, Text } from "native-base"; export type ElementType = "custom" | "default" | "text" | "toggle" | "dropdown"; @@ -17,7 +13,7 @@ export type ElementTextProps = { }; export type ElementToggleProps = { - onToggle: (value: boolean) => void; + onToggle: () => void; value: boolean; defaultValue?: boolean; }; @@ -29,7 +25,10 @@ export type ElementDropdownProps = { defaultValue?: string; }; -export const getElementTextNode = ({ text }: ElementTextProps, disabled: boolean) => { +export const getElementTextNode = ( + { text }: ElementTextProps, + disabled: boolean +) => { return ( { return ( onToggle()} isChecked={value ?? false} defaultIsChecked={defaultValue} disabled={disabled} @@ -76,4 +75,4 @@ export const getElementDropdownNode = ( ))} ); -}; \ No newline at end of file +}; diff --git a/front/components/GtkUI/RawElement.tsx b/front/components/GtkUI/RawElement.tsx index a220889..cb92801 100644 --- a/front/components/GtkUI/RawElement.tsx +++ b/front/components/GtkUI/RawElement.tsx @@ -21,10 +21,14 @@ import { ElementToggleProps, } from "./ElementTypes"; -export const RawElement = ( - { title, icon, type, helperText, description, disabled, data }: ElementProps, - isHovered: boolean -) => { +type RawElementProps = { + element: ElementProps; + isHovered?: boolean; +}; + +export const RawElement = ({ element, isHovered }: RawElementProps) => { + const { title, icon, type, helperText, description, disabled, data } = + element; const screenSize = useBreakpointValue({ base: "small", md: "big" }); const isSmallScreen = screenSize === "small"; return ( @@ -35,6 +39,7 @@ export const RawElement = ( padding: 15, justifyContent: "space-between", alignItems: "center", + backgroundColor: isHovered ? "#f5f5f5" : undefined, }} >