nope/resources/ui/gojs/helpers/add-button.ts
Martin Karkowski 8516245f01 Adding Editor
2021-07-27 12:55:15 +02:00

44 lines
1.3 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-06-22 09:33:55
* @modify date 2021-06-22 09:33:55
* @desc [description]
*/
import * as go from "gojs";
const make = go.GraphObject.make; // for conciseness in defining templates
/**
*
* @param label
* @param callback
* @returns
*/
export function createNextButton(label: string, callback: (e: go.InputEvent, g: go.GraphObject) => void) {
return {
selectionAdornmentTemplate:
make(go.Adornment, "Spot",
make(go.Panel, "Auto",
// this Adornment has a rectangular blue Shape around the selected node
make(go.Shape, { fill: null, stroke: "dodgerblue", strokeWidth: 3 }),
make(go.Placeholder)
),
// and this Adornment has a Button to the right of the selected node
make("Button",
{
alignment: go.Spot.Right, alignmentFocus: go.Spot.Left,
click: (event, graph) => {
const node = graph.part.adornedPart;
const diagram = node.diagram;
console.log(event, graph);
}
}, // define click behavior for Button in Adornment
make(go.TextBlock, label, // the Button content
{ font: "bold 6pt sans-serif" })
)
) // end Adornment
};
}