import * as React from "react"; import Icon, { IconTypes } from "@sc/plugins/webcomponents/v2/Icon"; import { Menu, MenuItem, Button } from "@material-ui/core"; import { DragHandleProps, EditorObjectState, ActionItems } from "./types"; import { EditorContext } from "../../Editor"; import { EditorActions } from "../../types"; const DragHandleMenu = ({ actions, id, dispatch }) => { const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event: React.MouseEvent) => { event.stopPropagation(); setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const handleChange = (action) => { switch (action.type) { case ActionItems.DELETE: dispatch({ type: EditorActions.REMOVE_ITEM, payload: { id } }); break; case ActionItems.DUPLICATE: dispatch({ type: EditorActions.DUPLICATE_ITEM, payload: { id } }); break; } setAnchorEl(null); }; return ( <> {actions.map((action, key) => ( handleChange(action)} // onClick={handleClose} > {action.caption} ))} handleChange({ type: ActionItems.DUPLICATE })} // onClick={handleClose} > Duplicate handleChange({ type: ActionItems.DELETE })} // onClick={handleClose} > Delete ); }; export const DragHandle: React.FC = ({ label, icon, state, color, actions = [], id, }) => { const editor = React.useContext(EditorContext); // const { removeItem, duplicateItem } = editor; const { content, dispatch } = editor; return (
{state === EditorObjectState.ACTIVE && ( <> {label.toUpperCase()} {/* */} )}
); };