diff --git a/client/src/components/inputs/ButtonGroup.tsx b/client/src/components/inputs/ButtonGroup.tsx index cc982e1a9..5d4c116a8 100644 --- a/client/src/components/inputs/ButtonGroup.tsx +++ b/client/src/components/inputs/ButtonGroup.tsx @@ -1,18 +1,129 @@ +import React from "react"; import ButtonGroup from "@mui/material/ButtonGroup"; +import { Button } from "@/components/inputs"; +import Menu from "@mui/material/Menu"; +import MenuItem from "@mui/material/MenuItem"; import type { ButtonGroupProps } from "@mui/material/ButtonGroup"; +import { ChevronDown } from "lucide-react"; +import { useTheme } from "@mui/material/styles"; export const ButtonGroupInput: React.FC = ({ orientation, + children, + sx, ...props }) => { + const isVertical = orientation === "vertical"; + const theme = useTheme(); + + if (!isVertical) { + return ( + + {children} + + ); + } + + const items = React.Children.toArray(children).filter( + Boolean + ) as React.ReactElement[]; + const [anchorEl, setAnchorEl] = React.useState(null); + const [selectedIndex, setSelectedIndex] = React.useState(0); + const open = Boolean(anchorEl); + + const handleToggleClick = (event: React.MouseEvent) => { + setAnchorEl(event.currentTarget); + }; + const handleClose = () => setAnchorEl(null); + const handleItemClick = (el: React.ReactElement, idx: number) => { + setSelectedIndex(idx); + const onClick = (el.props as any)?.onClick; + if (typeof onClick === "function") onClick(); + handleClose(); + }; + + const selected = items[selectedIndex]; + const selectedLabel = (selected?.props as any)?.children ?? "Actions"; + const selectedOnClick = (selected?.props as any)?.onClick as + | (() => void) + | undefined; + const selectedLoading = Boolean((selected?.props as any)?.loading); + return ( - + <> + + + + + + + {items.length === 0 ? ( + No actions + ) : ( + items.map((el, idx) => ( + handleItemClick(el, idx)} + > + {(el.props as any)?.children} + + )) + )} + + ); }; diff --git a/client/src/components/monitors/HeaderControls.tsx b/client/src/components/monitors/HeaderControls.tsx index 34f6f8240..b0397e778 100644 --- a/client/src/components/monitors/HeaderControls.tsx +++ b/client/src/components/monitors/HeaderControls.tsx @@ -48,11 +48,7 @@ export const HeaderControls = ({ loading={isPosting || isPatching} startIcon={} onClick={async () => { - const res = await post( - `/monitors/${monitor._id}/notifications/test`, - {} - ); - console.log(res); + await post(`/monitors/${monitor._id}/notifications/test`, {}); }} > {t("sendTestNotifications")}