2.1. Add Entry in Components List Sidebar

Before creating the custom Button component itself, we need to provide details about our custom element to ezeXtend so that the custom component is displayed as an option in the component sidebar on the left side of the ezeXtend window. Doing this first will allow us to be able to test our Button in the UI and catch any errors in our Button development along the way.

First, open /EZEXTEND_ROOT/ui/src/AppConstants/WidjetsMapping.js. Inside of this file is a constant variable WidgetsMapping that contains a JSON object of the Labels to be displayed in the sidebar panel as available elemenents to use in the dashboard. Here we add a definition for our new element CUSTOM_BUTTON and the string label that will be shown for it.

Note

For the sake of brevity in the code examples, elipses are used to denote code that we are not concerned with for our example and thus does not need to be displayed in this tutorial.

 1export const WidgetsMapping = {
 2     SHAPES: {
 3         ...
 4     },
 5     CHARTS: {
 6         ...
 7     },
 8     INPUTS: {
 9         TEXTBOX: 'Text',
10         BUTTON: 'Button',
11         CUSTOM_BUTTON: 'Custom Button',
12         RADIO: 'Radio',
13         SELECT: 'Select',
14         MULTI_SELECT: 'Multi Select',
15         LABEL: 'Label',
16         IMAGE:'Img',
17     },
18     OTHERS: {
19         ...
20     },
21 };

Next, we need to add the data for the component entry in the sidebar, that is, we need to specify things like the icon to be displayed, etc. To do this, first open /EZEXTEND_ROOT/ui/src/Components/Sidebar/ComponentsData.js. This file contains a constant variable Groups that contains a JSON object with lists of JSON descriptions of each of the sidebar components belonging to each group in the panel. Because we add our custom button to the Inputs section of the WidgetsMapping so too do we have to add a new sidebar component to the Inputs list within the JSON object:

 1export const Groups = {
 2   Shapes: [
 3      ...
 4   ],
 5   Charts: [
 6      ...
 7   ],
 8   Inputs: [
 9      {
10            title: WidgetsMapping.INPUTS.TEXTBOX,
11            icon: <BsInputCursor size={size} color={activeColor} />,
12            active: true,
13      },
14      {
15            title: WidgetsMapping.INPUTS.BUTTON,
16            icon: <GiClick size={size} color={activeColor} />,
17            active: true,
18      },
19      {
20            title: WidgetsMapping.INPUTS.CUSTOM_BUTTON,
21            icon: <HiCursorClick size={size} color={activeColor} />,
22            active: true,
23      },
24      {
25            title: WidgetsMapping.INPUTS.RADIO,
26            icon: <IoMdRadioButtonOn size={size} color={activeColor} />,
27            active: true,
28      },
29      {
30            title: WidgetsMapping.INPUTS.SELECT,
31            icon: <BiSelectMultiple size={size} color={activeColor} />,
32            active: true,
33      },
34      {
35            title: WidgetsMapping.INPUTS.LABEL,
36            icon: <MdLabel size={size} color={activeColor} />,
37            active: true,
38      },
39      {
40            title: WidgetsMapping.INPUTS.IMAGE,
41            icon: <FaImages size={size} color={activeColor} />,
42            active: true,
43      },
44   ],
45   Others: [
46      ...
47   ],
48};

Notice that we are referencing the title via the key-value pair that we entered into the WidgetsMapping object. For the icon, we are using one of the available click-related React icons that are freely available to React developers. You can find more of these icons at react-icons. We are using the HiCursorClick icon for our Button, so we will need to import that icon as a dependency at the top of the file:

 1import {
 2   ...
 3} from 'react-icons/ai';
 4
 5...
 6import { GrGraphQl } from "react-icons/gr";
 7import { BiSelectMultiple } from 'react-icons/bi';
 8import { RiCheckboxMultipleBlankLine } from 'react-icons/ri';
 9import { HiCursorClick } from 'react-icons/hi';
10import { WidgetsMapping } from 'AppConstants';
11const size = 20;
12const color = 'rgb(203 203 203)';
13...

If we run ezeXtend in Development Mode, we can see our component that has yet to be created listed as an option in the component sidebar. This is shown in add-entry.

_static/images/add_entry_1.jpg

A new custom button entry listed in the widgets sidebar.