import useWidgets from "@engine/App/Widgets/_actions/hooks/useWidgets"; import { WidgetDictionaryItem } from "@engine/App/Widgets/_actions/widgetsTypes"; import Edit from "@granity/icons/Edit"; import { IconButton, SvgIconProps, TextField } from "@granity/ui"; import { ChangeEvent, FC, useState } from "react"; import EditorModal from "./EditorModal"; export type EditWidgetModalProps = { widget?: WidgetDictionaryItem; iconSize?: SvgIconProps["fontSize"]; }; const EditWidgetModal: FC = ({ widget, iconSize = "small" }) => { const [displayNameValue, setDisplayNameValue] = useState(""); const [isModalOpen, setIsModalOpen] = useState(false); const { displayWidgetName, getWidgetInfoFromWidget, updateWidgetInfo } = useWidgets(); const onDisplayNameInputChange = ({ target }: ChangeEvent) => { setDisplayNameValue(target.value); }; const handleModalOpen = () => { setIsModalOpen(true); }; const handleModalClose = () => { clearInput(); setIsModalOpen(false); }; const onSave = () => { if (!widget) { return; } updateWidgetInfo(widget.id, { ...getWidgetInfoFromWidget(widget.id), displayName: displayNameValue, }); handleModalClose(); }; const onCancel = () => { handleModalClose(); }; const clearInput = () => { setDisplayNameValue(""); }; return ( <> {widget ? ( {() => ( )} ) : null} ); }; export default EditWidgetModal;