ToggleGroup
The basic control for creating groups of toggle buttons.
Usage
{
type: "toggleGroup",
options: object[],
key?: string | string[],
full?: boolean, // false by default
gap?: number, // 0 by default
hidden?: boolean, // false by default
disabled?: boolean, // false by default
css?: string,
width?: string | number | "content", // "content" by default
height?: string | number | "content", // "content" by default
padding?: string | number,
// service properties and methods
$on?: { [eventName: string]: function },
$handler?: function,
$setValue?: function,
$layout?: function
}
Toggle configuration object inside ToggleGroup:
{
id?: string,
hidden?: boolean,
disabled?: boolean,
full?: boolean,
text?: string,
icon?: string,
offText?: string,
offIcon?: string,
value?: string | number
}
The objects with the toggle
configuration inside the control can be used both with the boolean value and the string one, if the value
property is specified. The value
property is needed for assigning the set value as a value of the applied property. Check the example below to get the idea.
Description
ToggleGroup properties
Basic properties
type
- (required) the type of a control. Set it to "toggleGroup"key
- (optional) the name of the specified/modified property or the path to it in the object of a Diagram itemoptions
- (required) an array of ToggleGroup options, each option is set as an object with a set ofkey:value
pairs - attributes of options and their valueshidden
- (optional) defines whether a ToggleGroup is hidden. false by defaultdisabled
- (optional) defines whether a control is enabled (false) or disabled (true). false by defaultfull
- (optional) defines whether the ToggleGroup will be extended to the width specified by thewidth
property. false by defaultgap
- (optional) sets an offset between the elements (buttons) of an option. 0 by defaultcss
- (optional) adds style classes to a controlwidth
- (optional) the width of a control. "content" by defaultheight
- (optional) the height of a control. "content" by defaultpadding
- (optional) sets padding between a cell and a border of the ToggleGroup control
Service properties and methods
warning
Note that it's highly not recommended to redefine the service properties and methods for the default types of controls, since it may cause breaks in their functionality.
$on
- (optional) - allows setting an event listener. The object has the following properties:eventName
- a callback function which is called with the following parameters:object
- an object with the following properties:control
- the ToggleGroup Form controleditor
- the object of the Diagram Editorid
- the id of a Diagram item
arguments
- (optional) - the original event arguments
$handler
- (optional) - a callback function that allows handling actions on firing thechange
event of the ToggleGroup Form control and thechange
event of DataCollection. Called with the following parameter:object
- an object with the following properties:id
- the id of a Diagram itemkey
- the name of the specified/modified property or the path to it in the object of a Diagram itemeditor
- the object of the Diagram Editorcontrol
- the object of the ToggleGroup Form control the component is built onvalue
- the new value of the ToggleGroup Form control
$setValue
- (optional) - a callback function that allows setting the value of the ToggleGroup Form control on initialization of a control and on changing the value in DataCollection. Called with the following parameter:object
- an object with the following properties:editor
- the object of the Diagram Editorcontrol
- the object of the ToggleGroup Form control the component is built onvalue
- the value of a Diagram item
$layout
- (optional) - a callback function that allows setting the structure of a control. Returns the configuration of the ToggleGroup Form control. Called with the following parameter:object
- the configuration of a control without service properties
Toggle properties
id
- (optional) the id of a control, auto-generated if not sethidden
- (optional) defines whether an option is hidden. false by defaultdisabled
- (optional) defines whether an option is enabled (false) or disabled (true). false by defaultfull
- (optional) defines whether the option will be extended to the width specified by thewidth
property. false by defaulttext
- (optional) sets a text inside the option. When initialized together with theoffText
property, the specified text will be rendered in the selected (pressed) stateicon
- (optional) sets the CSS class of an icon displayed inside the option. When initialized together with theoffIcon
property, the specified CSS classes of icons will be rendered in the selected (pressed) state of the optionoffText
- (optional) sets the text that will be rendered in the unselected (unpressed) state of the optionoffIcon
- (optional) sets the CSS class of an icon that will be rendered in the unselected (unpressed) state of the optionvalue
- (optional) specifies the value in the selected (pressed) state. If not defined, the option is used with the boolean value
Example
const editor = new dhx.DiagramEditor("editor_container", {
type: "default",
view: {
editbar: {
properties: {
$shape: [
{
type: "toggleGroup",
key: "textAlign",
gap: 4,
$on: {
beforeChange: (spec, values) => !Object.values(values).every(i => !i),
},
options: [
{
icon: "dxi dxi-format-align-left",
value: "left"
},
{
icon: "dxi dxi-format-align-center",
value: "center"
},
{
icon: "dxi dxi-format-align-right",
value: "right"
}
]
}
]
}
}
}
});