35 lines
1.0 KiB
React
35 lines
1.0 KiB
React
import { IoIosArrowBack } from "react-icons/io";
|
|||
|
|
import { Menu, Portal } from "@chakra-ui/react";
|
||
|
|
import { v4 as uuid } from 'uuid';
|
||
|
|
import AlertLevel from "./AlertLevelWidget";
|
||
|
|
|
||
|
|
export default function AddWidgetMenu({onAddWidget, widgetArray, setWidgetArray}) {
|
||
|
|
function appendWidget(name) {
|
||
|
|
const newID = uuid(); // could be replaced with something else like guid
|
||
|
|
setWidgetArray([ // updating widget array containing info on the types of widgets
|
||
|
|
...widgetArray,
|
||
|
|
{i: newID, widget: name}
|
||
|
|
]);
|
||
|
|
onAddWidget(newID); // updating array containing info on layout of widgets
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Menu.Root>
|
||
|
|
<Menu.TriggerItem>
|
||
|
|
<IoIosArrowBack /> Add Widget
|
||
|
|
</Menu.TriggerItem>
|
||
|
|
<Portal>
|
||
|
|
<Menu.Positioner>
|
||
|
|
<Menu.Content>
|
||
|
|
<Menu.Item
|
||
|
|
value="AlertLevel"
|
||
|
|
onClick={() => appendWidget(AlertLevel)}
|
||
|
|
>
|
||
|
|
Alert Level
|
||
|
|
</Menu.Item>
|
||
|
|
</Menu.Content>
|
||
|
|
</Menu.Positioner>
|
||
|
|
</Portal>
|
||
|
|
</Menu.Root>
|
||
|
|
)
|
||
|
|
}
|