ContextToolbar
ContextToolbar
is a UI widget for displaying context toolbars (usually a set of buttons) below a certain target
element (HTML or SVG).
Learn more about the ContextToolbar plugin.
constructorβ
constructor(opt?: ContextToolbar.Options);
The ContextToolbar constructor accepts several parameters:
toolsβ
[optional] An array of tools. Each tool is an object that can have the following properties:
actionβ
The name of the action. This action is then triggered on the context toolbar object so that you can react to it later.
contentβ
The content of the button. It can be a text or an arbitrary HTML.
iconβ
Optionally, instead of passing content
, you can just pass a path to an image.
attrsβ
An object with attributes that will be applied on the generated button. Useful for adding your own custom attributes
such as { 'data-tooltip': 'My Tooltip' }
.
targetβ
[optional] The target element (either HTML or SVG), or an object representing a point with properties x
and y
representing client coordinates.
paddingβ
[optional] The gap between the anchor of the target element and the context toolbar. The default is 20
.
positionβ
[optional] The name of the position on the target element to which the toolbar is attached. The default is 'bottom'
.
anchorβ
[optional] The name of the position on the toolbar, where it is attached to the target. The default is 'top'
.
autoCloseβ
[optional] Determines if the context toolbar should be closed if the user clicked outside the area of the context
toolbar. The default is true
.
verticalβ
[optional] When set to true
the toolbar arranges tools from top to bottom instead of left to right. The default
is false
.
scaleβ
[optional] Optional parameter that sets the scale of the context toolbar.
Methodsβ
render()β
contextToolbar.render(): this;
Render the context toolbar onto the screen.
remove()β
contextToolbar.remove(): this;
Remove the context toolbar. Usually, you don't have to call this method as the context toolbar is closed automatically
if the user clicked outside the area of the context toolbar (unless you set the autoClose
option to false
).
on()β
contextToolbar.on(eventName: string, callback: EventHandler, context?: any): this;
Register a handler function that will be called whenever eventName
is triggered. The optional context
is an object
that will be the context of the handler function (the this
).
Static Methodsβ
close()β
ui.ContextToolbar.close(): void;
This is a static method that closes any context toolbar that is currently open.
update()β
ui.ContextToolbar.update(): void;
This is a static method that updates the position of the opened context toolbar (if any). Call this method if your
target
element changes its position while you still want to keep the context toolbar opened.
Eventsβ
The ui.ContextToolbar
object triggers events that correspond to the actions that you defined in the tools
array.
Events can be handled by using the on()
method.
action:[action]β
Triggered when the user clicks on one of the buttons in the context toolbar.
closeβ
Triggered when the context toolbar gets closed.
Typesβ
Optionsβ
interface Options extends mvc.ViewOptions<undefined> {
padding?: number;
autoClose?: boolean;
vertical?: boolean;
type?: string;
tools?: { [key: string]: any };
root?: HTMLElement;
target?: mvc.$Element | dia.Point;
anchor?: dia.PositionName;
position?: dia.PositionName;
scale?: number;
}