React UI Components Documentation
ReactJS ToolBar Component
The ToolBar component for ReactJS represents a toolbar where different tools (including widgets) can be automatically added. By default, jqxToolBar supports the widgets Button, ToggleButton, DropDownList, ComboBox and Input but custom tools can also be added.
Prerequisites
Refer to ReactJS Getting Started before you start with this help topic.
Configuration
The ToolBar component for ReactJS requires the following imports.
import React from 'react';import ReactDOM from 'react-dom'; import JqxToolbar from 'jqwidgets-react/react_jqxtoolbar.js';
Then we create our component class. Properties and methods are put as ReactJS props.
Finally we render our class in the desired HTML element:
ReactDOM.render(<App />, document.getElementById('app'));
Events Methods & Properties
In order to bind to any event, change any property or call any method, we need a reference to the component.
For that we use the ReactJS "ref" Callback Attribute:
<JqxToolBar ref='myToolBar' width={800} height={35}...../>
Now, when we have a reference, we need to call the desired event/property/method.
This is done in the componentDidMount() ReactJS Component Lifecycle method.
Events
The open event is triggered when the user selects an item.
The following example demonstrates how to add an event listener:
Methods & Properties
This is how you call methods & props:
//Get Methodslet tools = this.refs.myToolbar.enable(); //Render Methodthis.refs.myToolbar.render(); //Get Propertieslet height = this.refs.myToolbar.height(); //Set Propertiesthis.refs.myToolbar.height(50);
Every component have a method setOptions which accepts a object as an argument. This object contains component settings.
this.refs.myToolbar.setOptions({ minimizeWidth: 100, width: 300, height: 50})
Every component also have a method getOptions which returns a object containing the component settings.
let options = this.refs.myToolbar.getOptions();
ToolBar Examples
Overview
The following example demonstrates how to create a ToolBar component.
import React from 'react';import ReactDOM from 'react-dom'; import JqxToolBar from 'jqwidgets-react/react_jqxtoolbar.js'; class App extends React.Component { render () { let tools = 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input | custom'; let initTools = (type, index, tool, menuToolIninitialization) => { let icon = document.createElement('div'); if (type == "toggleButton") { icon.className = 'jqx-editor-toolbar-icon jqx-editor-toolbar-icon-arctic buttonIcon '; } switch (index) { case 0: icon.className += "jqx-editor-toolbar-icon-bold jqx-editor-toolbar-icon-bold-arctic"; icon.setAttribute("title", "Bold"); tool[0].appendChild(icon); break; case 1: icon.className += "jqx-editor-toolbar-icon-italic jqx-editor-toolbar-icon-italic-arctic"; icon.setAttribute("title", "Italic"); tool[0].appendChild(icon); break; case 2: icon.className += "jqx-editor-toolbar-icon-underline jqx-editor-toolbar-icon-underline-arctic"; icon.setAttribute("title", "Underline"); tool[0].appendChild(icon); break; case 3: tool.jqxToggleButton({ width: 80, toggled: true }); tool[0].innerText = "Enabled"; tool.on("click", () => { let toggled = tool.jqxToggleButton("toggled"); if (toggled) { tool.text("Enabled"); } else { tool.text("Disabled"); } }); break; case 4: tool.jqxDropDownList({ width: 130, source: ["<span style='font-family: Courier New;'>Courier New</span>", "<span style='font-family: Times New Roman;'>Times New Roman</span>", "<span style='font-family: Verdana;'>Verdana</span>"], selectedIndex: 1 }); break; case 5: tool.jqxComboBox({ width: 50, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 }); break; case 6: tool.jqxInput({ width: 200, placeHolder: "Type here to search..." }); break; case 7: let button = document.createElement('div'); button.innerHTML = "<img src='images/administrator.png' title='Custom tool' />"; tool[0].appendChild(button); tool.jqxButton({ height: 15 }); break; } } return ( <JqxToolBar width={800} height={35} initTools={initTools} tools={tools} /> ) }} ReactDOM.render(<App />, document.getElementById('app'));
Disabled ToolBar
The following example demonstrates how to disable the ToolBar component.
import React from 'react';import ReactDOM from 'react-dom'; import JqxToolBar from 'jqwidgets-react/react_jqxtoolbar.js'; class App extends React.Component { render () { let tools = 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input | custom'; let initTools = (type, index, tool, menuToolIninitialization) => { let icon = document.createElement('div'); if (type == "toggleButton") { icon.className = 'jqx-editor-toolbar-icon jqx-editor-toolbar-icon-arctic buttonIcon '; } switch (index) { case 0: icon.className += "jqx-editor-toolbar-icon-bold jqx-editor-toolbar-icon-bold-arctic"; icon.setAttribute("title", "Bold"); tool[0].appendChild(icon); break; case 1: icon.className += "jqx-editor-toolbar-icon-italic jqx-editor-toolbar-icon-italic-arctic"; icon.setAttribute("title", "Italic"); tool[0].appendChild(icon); break; } } return ( <JqxToolBar disabled={true} width={800} height={35} initTools={initTools} tools={tools} /> ) }} ReactDOM.render(<App />, document.getElementById('app'));